0

When I do an OTSU threshold on this image it always takes erodes away the same text every time no matter the lighting conditions.

Here is how I am calling the method:

threshold(outImg_gray(boxRoi), outImg_binarized(boxRoi), 0, 255, CV_THRESH_BINARY_INV|CV_THRESH_OTSU);

When given this image:

enter image description here

I get this image:

enter image description here

As you can see the bottom text removes part of the text at the bottom and it always removes part of this text.

How can I avoid this from happening?

  • You haven't posted enough of your code to reproduce your problem. However, it appears that you need to adjust `boxRoi` to not cut off those parts of the image. – Aurelius Apr 24 '14 at 18:00
  • Yeah, Otsu's thresholding works by minimising intra class variance from histogram calculated in the image. So, when there's some lighting changes that's not extreme, the result will be very similar. In this case, you might wanna think about other thresholding method. Wiki Otsu's method for more info. – sub_o Apr 24 '14 at 19:08

1 Answers1

0

Add a border to the image before processing (use copyMakeBorder), and remove it after processing.

Andrey Smorodov
  • 10,649
  • 2
  • 35
  • 42