Reputation: 11
How can I highlight the black spots in the image below for detection?
I've tried a lot of things, gaussian filter, change of contrast, contour filters... but nothing really worked. Currently, I'm trying to find a solution using python libraries, cv2, PIL, scikit-image,etc.
My goal is to identify each black spot.
Upvotes: 0
Views: 66
Reputation: 207798
An attempt at fleshing out Fred's advice (@fmw42):
magick spots.png -colorspace gray -statistic median 19x19 -lat 49x49-1% result.jpg
Maybe work on the parameters a little to tune it.
Slightly different approach:
magick spots.png -colorspace gray -median 15x15 -normalize -threshold 15% result.jpg
Another slightly different approach:
magick spots.png -colorspace gray -median 15x15 -median 7x7 -normalize -threshold 25% result.jpg
With OpenCV, that will look something like this:
import cv2 as cv
# Load image as greyscale
im = cv2.imread('spots.png',cv.IMREAD_GRAYSCALE)
# Median blur 15 and save debug
filtered = cv.medianBlur(im,15)
cv.imwrite('DEBUG-median15.png', filtered)
# Median blur 7 and save debug
filtered = cv.medianBlur(filtered,7)
cv.imwrite('DEBUG-median7.png', filtered)
# Normalize to full range
norm = cv2.normalize(filtered, None, 0, 255, cv.NORM_MINMAX)
cv.imwrite('DEBUG-norm.png', norm)
# Threshold
res = norm > 127
cv.imwrite('result.png', (res * 255).astype(np.uint8))
Note:
There is a Python C-types binding of ImageMagick called wand so you can port my answer across to Python. Here is an example.
Upvotes: 2