一个Blob是在一张图片中共享一些诸如灰度值等属性的一组链接的像素点。在上图中,黑色的链接区域就是blob,blob detection的目标就是识别并标记这些区域。html
SimpleBlobDetector, 是很是简单的模块,算法使用以下参数控制,且执行以后的流程:python
By Color : [ Note : This feature appears to be broken. I checked the code, and it appears to have a logical error ] First you need to set filterByColor = 1. Set blobColor = 0 to select darker blobs, and blobColor = 255 for lighter blobs.算法
By Size : You can filter the blobs based on size by setting the parameters filterByArea = 1, and appropriate values for minArea and maxArea. E.g. setting minArea = 100 will filter out all the blobs that have less then 100 pixels.app
By Shape : Now shape has three different parameters.less
This just measures how close to a circle the blob is. E.g. a regular hexagon has higher circularity than say a square. To filter by circularity, set filterByCircularity = 1. Then set appropriate values for minCircularity and maxCircularity. Circularity is defined asthis
This means that a circle has a circularity of 1, circularity of a square is 0.785, and so on.spa
A picture is worth a thousand words. Convexity is defined as the (Area of the Blob / Area of it’s convex hull). Now, Convex Hull of a shape is the tightest convex shape that completely encloses the shape. To filter by convexity, set filterByConvexity = 1, followed by setting 0 ≤ minConvexity ≤ 1 and maxConvexity ( ≤ 1).net
Don’t let this scare you. Mathematicians often use confusing words to describe something very simple. All you have to know is that this measures how elongated a shape is. E.g. for a circle, this value is 1, for an ellipse it is between 0 and 1, and for a line it is 0. To filter by inertia ratio, set filterByInertia = 1, and set 0 ≤ minInertiaRatio ≤ 1 and maxInertiaRatio (≤ 1 ) appropriately.code
下例将展现各个参数对标准图块的选取影响:htm
import env from mvlib import * from mvlib.application import *
# Read image im = read_image("blob.jpg") im_gray = gray(im) dev_imshow(im_gray)
blob_detect_params = create_blob_detector_params(10, 200, minArea=1500, minCircularity=0.1, minConvexity=0.87, minInertiaRatio=0.01) detector = create_blob_detector(blob_detect_params) # Detect blobs. keypoints = detector.detect(im_gray) # Draw detected blobs as red circles. # cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures # the size of the circle corresponds to the size of blob im_with_keypoints = dev_draw_keypoints(im, keypoints) dev_imshow(im_with_keypoints)