Description
Issues like #709 and #575 show a deficiency of the LocalAverage
binarizer to make a sound decision if the local area does not contain both fore- and background. It then simply assumes it is looking at background (white). This leads to issues like the above mentioned where a greyscale inversion before the binarization leads to a different result. This is also the basic problem with images that are too high in resolution, where the 'local area' could end up being completely inside a black module and the binarizer ends up introducing white pixels inside black QRCode finder patterns, thereby destroying the pattern for later recognition. The tryDownscale
feature was a means to cope with that.
Now I have another idea that might be able to fix both issues (writing it down here so I don't forget about it): Have the binarizer work in 2 stages where the first outputs one of 3 states for each pixel: black, white and void. Void meaning basically "no idea". Then in a second stage the void pixels are replaced by a hopefully performant version of "copy from the nearest non-void neighbor".
Thinking about it, this second stage would not be required to be repeated after the inversion, which makes it even more attractive. The biggest issue potentially killing it completely is the "performant" part.
In case someone happens to know the best algorithm for doing this, please let me know. To rephrase the problem: given an image which is all 'void' except one pixel white in the center of the left half and one pixel black in the center of the right half, what is the fastest way to fill the whole image such that the left half of it is white and the right half is black?