Binarize (IP Command)

From Grooper Wiki
(Redirected from Binarize)

This article was migrated from an older version and has not been updated for the current version of Grooper.

This tag will be removed upon article review and update.

This article is about the current version of Grooper.

Note that some content may still need to be updated.

2025 20232.80
The Binarize step as it appears unconfigured on the IP Step tab.

Binarize is an IP Command that converts a color or grayscale image to a bi-tonal (black and white) image using various thresholding methods.

Binarize is an IP Command that converts a color or grayscale document image into black and white. This can be used as a basic method of cleaning up a document, rendering it black and white to produce better OCR results. This is accomplished by "thresholding" the image, setting a value that determines which pixels should be "white" and which should be "black". There are four image thresholding methods available to Grooper: Simple, Auto, Adaptive, and Dynamic.

Binarization is also considered an "IP Primitive" in that it is foundational to other image processing operations. Binarization is helpful (and sometimes required) to perform other IP Commands, such as Line Removal and Box Removal. These commands will have an ability to pre-process the image with its own binarization settings before final document binarization.

What Is Binarization?

Binarization is the process of transforming a multi-tonal, gray-scale or pixel image into a two-tone, black – white, or binary image. Converting an image from multi-tonal to bi-tonal (or binarized image) is accomplished through thresholding. This means setting the pixel values from the 0-255 spectrum to a 0-1 spectrum. In a binarized image, 0 represents white and 1 represents black.

If a gray value is equal to greater than the threshold, then those parts of the image are transformed into white. So if a gray value parts of an image are less than the threshold, then those parts are transformed into black.

About Binarization (and the Binarize IP Command)

Many of Grooper's Image Processing capabilities work better if an image is in black and white instead of color (or simply won't work when using a color image).  Take Line Detection for example.  At its most basic level, a line on an image is a string of pixels one after the other.  Grooper would have to pick out one string of colored pixels in a row and decide if it was a line or just a string of pixels that happened to be the same color.  The result would be catastrophic. However, if you convert the color image into a black and white one, you only have two choices to make, is the pixel black or white?  Is it a string of black pixels in a row?  That's a line.  Easy.

Binarization converts color images to black and white by "thresholding" the image. Thresholding is the process of setting a threshold value on the pixel intensity of the original image.  Pixel intensity is a pixel's "lightness" or "brightness".  Essentially, once a midpoint between the most intense ("whitest") and least intense ("blackest") pixel on a page is established, lighter pixels are converted to white and darker are converted to black.  Or put another way, pixels with an intensity value above the image threshold are converted to white, and those below the threshold are converted to black.  This midpoint (or "threshold") can be set manually or found automatically by a software application. The Thresholding Method can be set to one of four ways:

  • Simple - Thresholds an image to black and white using a fixed threshold value between 1 and 255.
  • Auto - Selects a threshold value automatically using Otsu's Method.
  • Adaptive - Thesholds pixels based on the intensity of pixels in the local neighborhood.
  • Dynamic - Performs adaptive thresholding, while preserving dark areas on the page.

Each method has its own set of configurable properties.  See below for details on each method.

FYI

Thresholding is sometimes described as separating an image into foreground values (black) and background values (white).

Image Thresholding Methods

Simple

This is by far the simplest to configure.  All you do is manually set the pixel threshold for the documents.  However, simplest doesn't necessarily mean easiest.  This can be a value from 1 to 255.  On a thresholding scale, 0 is pure black and 255 is pure white.  If you set the threshold to 255, that would mean any pixel with an intensity value less than pure white would be converted to black.  For many documents, this ends up turning the entire page black.  Even if a page "looks" white, if it is not totally 100% pure white, those pixels are turning black.  Be careful, for many images scanned on color or grayscale (and even some digital documents as well) what you think is white may actually be just extremely close to white (same for black).

However, as a general rule, the closer the number is to 255 will make the image blacker, and the closer it is to 1 will make the image whiter.  The image will have more black pixels the closer to 255 and more white pixels the closer to 1.

It should be noted, this is a fixed value for all pages.  Documents are uniformly transformed according to the single value. If you have a set of documents whose black/white pixel intensity changes from one to the next, this method may not prove reliable.


The input image.

Threshold 50
Threshold 100
Threshold 150

Threshold 200

Property Details

Property Default Value Information
Threshold 127 Defines the fixed threshold value from 1 to 255. The default value is 127 because it is halfway between pure white (255) and pure black (0).

Auto

This is Grooper's default image threshold method. This method selects a threshold value from 1 to 255 automatically using "Otsu's Method". This has the benefit of analyzing an image an choosing a threshold value for you. Furthermore, the threshold is not fixed for each image. A threshold value is computed for each one.

Property Details

Property Default Value Information
Maximum Range 25% Halfway between pure white (255) and pure black (0) is a threshold value of 127. The "Maximum Range" value sets how far from the midpoint threshold of 127 is allowable for an image. For example, 25% of 127 is roughly 32, meaning the threshold can be from 95 to 159. If Otsu's Method determined a threshold value below 95, it would still be set to 95. If found to be above 159, the threshold value would be set to 159.
Adjustment 0 You may add an adjustment to the calculated threshold. A positive number will increase the threshold value. A negative one will decrease it.

Adaptive

An example of an image suited for Adaptive thresholding.

Both Simple and Auto use a conventional form of thresholding by setting a global threshold for the entire image. If the threshold value is determined to be 127 for the image, a pixel with a lower intensity than 127 will be converted to white and a pixel with a higher intensity will be converted to black. Adaptive and Dynamic thresholding changes dynamically over the image. This can accommodate changing lighting conditions in the image, resulting in strong illumination or shadows on only portions of the image.

The Adaptive method examines the intensity values of an area around each individual pixels rather than the average intensity of the entire image. This area is called the "local neighborhood". 


Property Details

Property Default Value Information
Window Size 5pt This property determines the size of the local neighborhood around each pixel (in points, pixels, inches, millimeters or centimeters).
Kernal Type Box This value can be either "Box" or "Gaussian"  Box thresholding draws a box (whose size is determined by the window size) around a pixel location and finds the average intensity of the pixels within the box.  The threshold for that pixel is set using the average intensity of the box's pixels.  Gaussian thresholding works similarly, but pixels closer to the center of the box are given a higher weight, meaning the intensity of pixels around the edge will factor less when calculating the average intensity.
Delta 16 This specifies the change in intensity, from 1 to 255, required for a pixel to be considered an edge pixel
Sigma 0 When using a Gaussian kernal, this specifies the sigma value, which corresponds to the standard deviation between the statistical midpoint of pixel intensity. Changing this value will alter what is considered the normal distribution of white and black pixels.

Dynamic

The Dynamic image thresholding method uses the Adaptive method but works to preserve darker pixels on the page.

Property Details

Property Default Value Information
Window Size 5pt This property determines the size of the local neighborhood around each pixel (in points, pixels, inches, millimeters or centimeters).
Kernal Type Box This value can be either "Box" or "Gaussian"  Box thresholding draws a box (whose size is determined by the window size) around a pixel location and finds the average intensity of the pixels within the box.  The threshold for that pixel is set using the average intensity of the box's pixels.  Gaussian thresholding works similarly, but pixels closer to the center of the box are given a higher weight, meaning the intensity of pixels around the edge will factor less when calculating the average intensity.
Delta 16 This specifies the change in intensity, from 1 to 255, required for a pixel to be considered an edge pixel
Sigma 0 When using a Gaussian kernal, this specifies the sigma value, which corresponds to the standard deviation between the statistical midpoint of pixel intensity. Changing this value will alter what is considered the normal distribution of white and black pixels.
Black Grouping 25% Specifies how aggressively dark areas of the image will be preserved. In a nutshell, the higher this number, the less black pixels will be dropped out during thresholding.