一個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)