Adaptive threshold with blurry image

minhthuan picture minhthuan · Sep 5, 2013 · Viewed 12.2k times · Source

I'm in search for best Adaptive Threshold method for image binarization. But I have any problems with dark and blurry image.
Input image:
Let the Image load...

and when I use Adaptive threshold method I receive this
Output Image:
Let the Image load...

This is not good for me!
So, could someone help me fix this problem?


another image : enter image description here

and : enter image description here

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 !

Answer

Hammer picture Hammer · Sep 5, 2013

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)

enter image description here

and then (OTSU)

enter image description here

A little eroding and dilating and you should be good to go