I tried to apply opencv OTSU binarization on the following image, but it generate a black image.

enter image description here

Here is the following python code:

import cv2

image = cv2.imread('test_otsu.png', 0)
ret, thresh = cv2.threshold(image, 0,250,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
cv2.imwrite('temp.png', thresh)

Did I miss anything in my code? Please help me how to get correct binarization of the given image.

  • $\begingroup$ it seems a wrong threshold is determined, can you try manual binerization? $\endgroup$ – MimSaad Jun 25 '18 at 9:19

the problems seems to be with the white border of the image you are using. remove it manually and test again.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.