Use the binarize function to produce an image with 2 levels of grey. Use quantize to produce an image with n levels of grey.
For each element in the image, the functions return 0 if the element is ≤ to a specified threshold and they return 1 if the element is greater than the threshold.
Binarization and quantization can be used for enhancing features of an image by choosing the appropriate threshold or number of levels. They can also be a first step in an image analysis.
1. Use the READ_IMAGE function to read in an image.
(bridge.bmp)
2. Set the threshold.
3. Use the binarize function to produce a binarized image.
4. Use the WRITEBMP function to write the binarized image to a file.
(bridge_bin.bmp)
You can change the value of thresh to view the effect on the image.
Setting Binarization Automatically
Use automatic binarization to highlight items of interest in machine vision applications.
If a threshold value is not specified, then the binarize function automatically calculates one.
1. Read a grayscale digitized image of an industrial part.
2. Binarize the image.
3. Write the binarized image to a file.
(part.gif)
(part_bin.bmp)
Using the Optional Arguments
To emphasize or de-emphasize particular ranges of levels, you can provide the optional arguments lowThresh, highThresh, inValue, and outValue. All levels between lowThresh and highThresh are binarized to inValue, and the remaining levels are binarized to outValue. The values for the input parameters are arbitrary and do not have to be from 0 to 255. inValue and outValue may be the same, in which case the entire image is set to one level only.
1. Set the image levels from 50 to 150 to 25, and set the rest of the levels to 200.
2. Binarize the bridgegray image matrix using the optional arguments.
3. Write the binarized image to a file.
(bridge_bin2.bmp)
quantize
1. Apply the quantize function to the grayscale image used above.
2. Write the quantized image to a file.
(bridge_q3.bmp)
3. Specify the levels in a vector and quantize the same image. Compare this 3-level quantization with the previous one:
The values in v must be strictly ascending, but they may be any real number. This specification is useful if you want to use quantization levels which are not uniformly spaced within the range of the given image.