I am trying to port one of my image analysis scripts from Mathematica to Python OpenCV, but I am having trouble with one of the functions involved.
I managed to binarise and watershed the image, much like one does in Mathematica. However, the steps to filter the properties of the connected components seem to be not working correctly.
The input image is below:
However, I attempted to run the following code:
import cv2
import numpy as np
img = cv2.imread('test2.4.png', 1)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Set up the detector and configure its params.
params = cv2.SimpleBlobDetector_Params()
params.minDistBetweenBlobs = 0
params.filterByColor = True
params.blobColor = 255
params.filterByArea = True
params.minArea = 10
params.maxArea = 300000
params.filterByCircularity = False
params.filterByConvexity = False
params.filterByInertia = True
params.minInertiaRatio = 0.01
params.maxInertiaRatio = 1
detector = cv2.SimpleBlobDetector_create(params)
# Detect blobs.
keypointsb = detector.detect(img)
# Draw detected blobs as red circles.
im_with_keypoints = cv2.drawKeypoints(img, keypointsb, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
# Show keypoints
cv2.imwrite('test3.png',im_with_keypoints)
As seen in the code, I have set the parameters for the blob detection to be as permissive as possible. However, a large proportion of the blobs are not detected, and none of the watershed-split blobs were detected either.
I have checked the documentation for the function and tweaked most of them with the exception of thresholds and repeatability (as the image is already binarised). Is there any other configuration that I should perform in order for the function to detect all of the blobs present?
Alternatively, are there any other recent/well updated libraries that are capable of filtering by component measurements?

