0

I have an image that contains an illuminate. First I crop the area which I want to process then convert it into the binary image. I use Otsu's thresholding, but it gives a bad result for this problem. I have to try to use adaptive threshold, but this method dependent on block size and C parameter (opencv method). What should I do to get a good result in this problem?

Original image, but I crop the certain area Original image, but I crop the certain area:

Otsu Thresholding result

Otsu Thresholding result

Hendra
  • 21
  • 1
  • 9
  • 1
    You can try to filter image with low-pass filter and subtract result from original image to suppress long-range "brightness waves" Example: https://stackoverflow.com/questions/44047819/ – MBo Jul 22 '17 at 06:39
  • why would you use Otsu if you only have one image? that makes no sense at all. use a manual threshold... – Piglet Jul 22 '17 at 10:20
  • @MBo Thanks for your responses. I have tried through that link, but I got no significant difference between using that method or not. I used dilate with 21x21 and medianBlur with 21 for ksize parameter. Am I missing something? – Hendra Jul 23 '17 at 13:30
  • @Piglet thanks for your responses. I have many images with different luminance. In a normal image, no luminance problem, I used this Otsu method and give a good result. I need threshold which is not needed to define first because the same threshold will not match with another image. – Hendra Jul 23 '17 at 13:35

1 Answers1

0

adaptive threshold in not suitable for your case. if you like to simply create a binary image with black background and white text (or vise-versa), and you have tight cropped area, you can simply do below steps:
1-convert image to gray scale
2-normalize your image (ignore 1% of darkest and lightest pixels)
3-use a fixed threshold (something between 0.3 to 0.7)
4-do some morphological enhancement like eroding, dilating, opening and closing for eliminating noise.
adaptive thresholding used in case of uneven luminance when you have a gradient light on board which is not present in you example.

Mokhabadi
  • 302
  • 2
  • 14
  • you don't need to normalize or remove noise if you use a proper threshold. skipping 1% of the brightest pixels will most likely remove the white text. also I'd pick saturation over intensity for this as the contrast is better. your comments on adaptive thresholding are not quite correct. the main problem with his image is the anisotropy in the background which cannot be compensated with a square blocksize. but I guess you could find some working parameters anyway. considering this single image (he didn't mention others) the easiest way would be using a magic wand in gimp... – Piglet Jul 22 '17 at 14:51
  • So, what case I should look for that image? and how to normalise image by ignoring 1% of darkest and lightest pixels? Thanks for your answer. – Hendra Jul 23 '17 at 13:39
  • you can create histogram and take a rang that 1% of pixels are ignored from each side and then expand the chosen range (e.g. 11-238) to full range (0-255). in this example 1% of pixel values are 11 or less and after normalization all of them become 0. you can find many tutorials about histogram and normalization on the web. – Mokhabadi Jul 24 '17 at 04:49