Functions > Image Processing > Image Manipulation > Example: Thresholding and Inversion
Example: Thresholding and Inversion
Use the threshold and invertimage functions to discard all of an image's intensity levels below or above a threshold, or to invert them. Thresholding can be used to remove background features (or noise) in an image or to shift its intensity spectrum. Inversion can be used to enhance details.
For information on using this example, refer to About Image Processing Examples.
threshold
This function can be used in two ways. When thresh is positive, elements of M less than thresh are set to zero; otherwise they retain their original value. When thresh is negative, elements of M greater than the absolute value of thresh are set to zero; otherwise they retain their original value. When thresh is zero, all elements are set to zero.
1. Read in a test image.
Click to copy this expression
(earth.bmp)
2. Set the cutoff threshold and view the effect on the above image.
Click to copy this expression
Click to copy this expression
Click to copy this expression
(earth_t100.bmp)
Try different values of thresh, and then recalculate to see the effect on the image. Try some negative numbers too.
invertimage
The returned matrix contains the inverted elements of the original image. The value of the inverted element depends on the maximum value of the input matrix.
1. Invert the original image.
Click to copy this expression
Click to copy this expression
(earth_inv.bmp)
For grayscale images, this is equivalent to a "photographic" negative.
2. Read in a color image.
Click to copy this expression
(apecolor.gif)
3. Invert the color image.
Click to copy this expression
Click to copy this expression
(apecolor_inv.bmp)
For color images, the effect is simply to replace all colors with their color complements.
4. Change the range of intensities of the original image.
Click to copy this expression
Click to copy this expression
(apecolor_s.bmp)
5. Invert the scaled image.
Click to copy this expression
Click to copy this expression
(apecolor_sinv.bmp)
Was this helpful?