I'm in search for best Adaptive Threshold method for image binarization. But I have any problems with dark and blurry image.
Input image:
and when I use Adaptive threshold method I receive this
Output Image:
This is not good for me!
So, could someone help me fix this problem?
another image :
and :
the first seem very bad with @Hammer'solution (i must chose c channel) , the second i can use adaptive threshold normal .
so i want to find the best solution for all cases .
thank Again !
It seems like color is a much better indicator for segmentation in your image than intensity. Try converting it to HSV and then running OTSU on the H channel.
in python
hsv = cv2.cvtColor(image, cv2.cv.CV_BGR2HSV)
cv2.imshow('hsv', hsv[:,:,0])
(thresh, im_bw) = cv2.threshold(hsv[:,:,0], 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
cv2.imshow('OTSU', im_bw)
gives (hsv)
and then (OTSU)
A little eroding and dilating and you should be good to go
You might be interested in these adaptive thresholds used by openCV.
I used the adaptive mean threshold. You may have to play with the parameters a bit, but if your images are similar (same size etc), hopefully there won't be too much tweaking required.
# Smooth image
filtered = cv2.adaptiveThreshold(input_image.astype(np.uint8), 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 41, 3)
# Some morphology to clean up image
kernel = np.ones((5,5), np.uint8)
opening = cv2.morphologyEx(filtered, cv2.MORPH_OPEN, kernel)
closing = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel)
Results:
The following code ...
im=cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,111,3)
cv2.imshow('mkm',im)`
... gives a good result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With