Thresholding for fun and profit!
Thresholding is one of the vital steps in many preprocessing scenarios. The idea is to distinguish between foreground and background pixels to extract information. The big problem is to decide a threshold for each pixel without losing information or introducing noise. We have tested a couple of thresholding methods for our project within the spatial domain. We tested thresholding algorithms that were proposed within the domain of character recognition.
Local Threshdolding is a class of thresholding algorithms that calculate a single threshold for every pixel within an image. The advantage is that uneven illumination can be handled better than within a global thresholding algorithm. The idea is that a certain pixel threshold is calculated in respect of the pixel statistics surrounding the pixel of interest. The boundary is usually called a local window.
One problem when using local thresholding is to find a good size for this local window. It should span 1-2 characters within OCR applications to be efficient. This is not so easy with barcode recognition. As we do not know (and do not want) the scaling of the image, and hence the barcode size, we can not guarantee that the local window spans foreground and background pixels. Because the pixel thresholds are calculated in respect of the statistics of surrounding pixels, light barcode pixels might be classified as background pixels if the local windows is too small (covering only foreground (barcode) pixels). This results in a hole within the barcode line, which certainly is not wanted.
Global thresholding algorithms calculate a common thresholding value for every pixel within the image. Uneven illumination can introduce noise and false pixel classifications. Images of bad quality (through glare or blur) introduce some unwanted effects as well. So global binarization algorithms do not seem to be a very good idea on the first impression (related to barcode localization). But what if we use the binarization to classify between edge and none edge pixels? This of course involves some way of edge detection (like using the sobel operator). Or course the edge detection operator might be fooled by glare. But it will only detect the edges of the glarred spot and introduce a much smaller error. The thresholding then does not classify between foreground or background pixels, but between edge and non edge pixels.
Local thresholding can handle bad quality images better than Global thresholding but it’s tough to decide a good local window size. If the window is too small barcode pixels might get lost, if the window is too big the algorithm speed decreases as well as the threshold qualities. A good tradeoff is to use global thresholding on a preprocessed images to classify between edge and non-edge pixels.
Local Binarization on grayalue Image
Local Binarization on grayvalue Image
Global Binarization on Edge Image