2

is there a way to threshold only if the blob size is more than (height,width)?

Example

import cv2

img_1 = cv2.imread('my_image_1.jpg')
thresh = cv2.threshold(img_1, 200, 255, cv2.THRESH_BINARY)[1]

For the purposes of thresholding, I want to ignore all pixels that are not inside a blob of say, 6 x 6 pixels that also meet the thresholding condition.

What is the best way to do this?

Alejandro Simkievich
  • 3,512
  • 4
  • 33
  • 49

1 Answers1

3

Please check this tutorial. You can implement this by adding the following lines to your code,

params = cv2.SimpleBlobDetector_Params()

params.filterByArea = True
params.minArea = 20 #define minimum area

ver = (cv2.__version__).split('.')

if int(ver[0]) < 3 :
    detector = cv2.SimpleBlobDetector(params)
else : 
    detector = cv2.SimpleBlobDetector_create(params)

keypoints = detector.detect(thresh)

im_with_keypoints = cv2.drawKeypoints(thresh, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
Rayees
  • 111
  • 1
  • 7
  • While this link may answer the question, link only answers are discouraged on Stack Overflow, you can improve this answer by taking vital parts of the link and putting it into your answer, this makes sure your answer is still an answer if the link gets changed or removed :) – WhatsThePoint Sep 18 '17 at 07:52
  • 3
    Sorry. I didn't know. I am new here.I will try to improve the answer with parts of the code. Thank you very much! – Rayees Sep 18 '17 at 08:50