Search code examples
image-processingcomputer-visionlighting

Adaptive threshold Binarization's bad effects


I implemented some adaptive binarization methods, they use a small window and at each pixel the threshold value is calculated. There are problems with these methods: If we select the window size too small we will get this effect (I think the reason is because of window size is small) alt text
(source: piccy.info)

At the left upper corner there is an original image, right upper corner - global threshold result. Bottom left - example of dividing image to some parts (but I am talking about analyzing image's pixel small surrounding, for example window of size 10X10). So you can see the result of such algorithms at the bottom right picture, we got a black area, but it must be white. Does anybody know how to improve an algorithm to solve this problem?


Solution

  • There shpuld be quite a lot of research going on in this area, but unfortunately I have no good links to give.

    An idea, which might work but I have not tested, is to try to estimate the lighting variations and then remove that before thresholding (which is a better term than "binarization"). The problem is then moved from adaptive thresholding to finding a good lighting model.

    If you know anything about the light sources then you could of course build a model from that.

    Otherwise a quick hack that might work is to apply a really heavy low pass filter to your image (blur it) and then use that as your lighting model. Then create a difference image between the original and the blurred version, and threshold that.

    EDIT: After quick testing, it appears that my "quick hack" is not really going to work at all. After thinking about it I am not very surprised either :)

    I = someImage
    Ib = blur(I, 'a lot!')
    Idiff = I - Idiff
    It = threshold(Idiff, 'some global threshold')
    

    EDIT 2 Got one other idea which could work depending on how your images are generated. Try estimating the lighting model from the first few rows in the image:

    1. Take the first N rows in the image
    2. Create a mean row from the N collected rows. You know have one row as your background model.
    3. For each row in the image subtract the background model row (the mean row).
    4. Threshold the resulting image.

    Unfortunately I am at home without any good tools to test this.