Ask Your Question
2

Does SimpleBlobDetector ignore blobs at the edges of an image?

asked 2019-04-26 16:45:03 -0600

I was thinking I'd have to write a filter to ignore blobs that touch the edge of an image, but I did some testing and it seems like they're ignored anyway. Is this a feature of the SimpleBlobDetector algorithm that I can rely on or an implementation detail that I shouldn't assume will always work this way?

Blobs:

blobs

Detected blobs:

detected blobs

edit retag flag offensive close merge delete

Comments

Firstly, I got 5 out 3. I was attempting to do SimpleBlobDetector. Secondly, I got all 8 of circles using inside circles , but no black image. I was using white image.

supra56 gravatar imagesupra56 ( 2019-04-27 07:44:06 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-04-29 13:19:27 -0600

supra56 gravatar image

If you want inner circles, but not outer circles. Code:

#!/usr/bin/env python3
#Raspberry pi 3B/+, OpenCV 4.1.0
#Date: 29th April, 2019

import numpy as np
import cv2

img = cv2.imread('SimpleBlobDetector.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blurred = cv2.medianBlur(gray, 5)
_filter = cv2.bilateralFilter(blurred, 9, 75, 75)
adap_thresh = cv2.adaptiveThreshold(_filter, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                    cv2.THRESH_BINARY_INV, 21, 0)
element = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3)) 
dilated = cv2.dilate(adap_thresh, element, iterations=1)

# blob detection
params = cv2.SimpleBlobDetector_Params()
params.filterByColor = False
params.blobColor = 0
params.filterByArea = False
params.minArea = 500
params.maxArea = 5000
params.filterByCircularity = False
params.minCircularity =.4
params.maxCircularity = 1

det = cv2.SimpleBlobDetector_create(params)
keypts = det.detect(dilated)
im_with_keypoints = cv2.drawKeypoints(dilated, keypts, np.array([]),
                                      (255, 0, 0), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.imwrite('blob.png', im_with_keypoints)
cv2.imshow("Keypoints", im_with_keypoints)
cv2.waitKey(0)

Output: image description

Secondly,w/out SimpleBlobDetector:

#!/usr/bin/env python3
#Raspberry pi 3B/+, OpenCV 4.1.0
#Date: 29th April, 2019

import cv2

# read original image
img = cv2.imread('SimpleBlobDetector.jpg')

# create binary image
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (5, 5), 0)
(t, binary) = cv2.threshold(blur, 100, 255, cv2.THRESH_BINARY)

# find contours
contours, _ = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

# draw contours over original image
cv2.drawContours(img, contours, -1, (0, 0, 255), 5)

# display original image with contours

cv2.imwrite('blop1.jpg', img)
cv2.imshow("output", img)
cv2.waitKey(0)

Output: image description

edit flag offensive delete link more

Comments

Thanks for your answer, but that wasn't really my question. SimpleBlobDetector is already doing exactly what I want. I don't want it to detect blobs that touch the edge of the image. My question is whether or not this is an intentional behavior of the algorithm or an implementation detail that could change in a future version.

SSteve gravatar imageSSteve ( 2019-05-01 12:32:41 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-04-26 16:45:03 -0600

Seen: 2,497 times

Last updated: Apr 29 '19