Blob-Detect

Blob 是什麼

一個Blob是在一張圖片中共享一些諸如灰度值等屬性的一組鏈接的像素點。在上圖中,黑色的鏈接區域就是blob,blob detection的目標就是識別並標記這些區域。html

 

Blob detection 工做原理

SimpleBlobDetector, 是很是簡單的模塊,算法使用以下參數控制,且執行以後的流程:python

  • Thresholding: 將源圖轉爲一些二值圖,使用從minThreshold開始的閾值. 閾值從minThreshold開始,使用thresholdStep爲梯度增長.
  • Grouping: 在每一個二值圖中,相鄰的白色像素點是被group在一塊兒的,稱之爲binary blobs。
  • Merging: 計算二值圖片中binary blobs的中心點,blobs之間的距離比minDistBetweenBlobs更小的會被合併。
  • Center & Radius Calculation: 計算並返回新合併的blobs的中心和半徑。
 

利用color, size, shape 過濾 Blobs

  • 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

 

Circularity

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 asimage.pngthis

This means that a circle has a circularity of 1, circularity of a square is 0.785, and so on.spa

 

Convexity

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)image.png.net

Inertia Ratio

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.image.pngcode

 
 

下例將展現各個參數對標準圖塊的選取影響:image.pnghtm

 
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)
本站公眾號
   歡迎關注本站公眾號,獲取更多信息