|
Image Processing : Contrasting and Filtering |
|
The histogram of an image shows the number of pixels for each pixel value within the range of the image. If the minimum value of the image is 0 and the maximum value of the image is 255, the histogram of the image shows the number of pixels for each value ranging between and including 0 and 255. Peaks in the histogram represent more common values within the image that usually consist of nearly uniform regions. Valleys in the histogram represent less common values. Empty regions within the histogram indicate that no pixels within the image contain those values.
The following figure shows an example of a histogram and its related image. The most common value in this image is 180, composing the background of the image. Although the background appears nearly uniform, it contains many small variations.
![]() |
The contrast of these variations can be increased by equalizing the image's histogram. Either the image's color table or the image itself can be equalized based on the information within the image's histogram. This section shows how to enhance the contrast within an image by modifying the image itself. See H_EQ_CT for more information on enhancing contrast by modifying the color table of an image using the image's histogram information.
During histogram equalization, the values occurring in the empty regions of the histogram are redistributed equally among the peaks and valleys. This process creates intensity gradients within these regions (replacing nearly uniform values), thus highlighting minor variations.
IDL contains the ability to perform histogram equalization and adaptive histogram equalization. The following sections show how to use these forms of histogram equalization to modify images within IDL:
You can use the HIST_EQUAL function to perform basic histogram equalization within IDL. Unlike histogram equalization methods performed on color tables, the HIST_EQUAL function results in a modified image, which has a different histogram than the original image. The resulting image shows more variations (increased contrast) within uniform areas than the original image.
The following example applies histogram equalization to an image of mineral deposits to reveal previously indistinguishable features. This example uses the mineral.png file in the examples/data directory. Complete the following steps for a detailed description of the process.
| Example Code See equalizing.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
mineral.png file:
file = FILEPATH('mineral.png', $
SUBDIRECTORY = ['examples', 'data'])
image = READ_PNG(file, red, green, blue)
imageSize = SIZE(image, /DIMENSIONS)
DEVICE, DECOMPOSED = 0 TVLCT, red, green, blue
WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Original Image' TV, image
The following figure shows the original image.
![]() |
WINDOW, 1, TITLE = 'Histogram of Image' PLOT, HISTOGRAM(image), /XSTYLE, /YSTYLE, $ TITLE = 'Mineral Image Histogram', $ XTITLE = 'Intensity Value', $ YTITLE = 'Number of Pixels of That Value'
The following figure shows the original image's histogram.
equalizedImage = HIST_EQUAL(image)
WINDOW, 2, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Equalized Image' TV, equalizedImage
The following figure shows the results of the histogram equalization. Small variations within the uniform regions are now much more noticeable.
WINDOW, 3, TITLE = 'Histogram of Equalized Image' PLOT, HISTOGRAM(equalizedImage), /XSTYLE, /YSTYLE, $ TITLE = 'Equalized Image Histogram', $ XTITLE = 'Intensity Value', $ YTITLE = 'Number of Pixels of That Value'
The following figure shows the modified image's histogram. The resulting histogram is now more uniform than the original histogram.
Adaptive histogram equalization involves applying equalization based on the local region surrounding each pixel. Each pixel is mapped to an intensity proportional to its rank within the surrounding neighborhood. This type of equalization also tends to reduce the disparity between peaks and valleys within the image's histogram.
You can use the ADAPT_HIST_EQUAL function to perform the adaptive histogram equalization process within IDL. Like the HIST_EQUAL function, the ADAPT_HIST_EQUAL function results in a modified image, which has a different histogram than the original image.
The following example applies adaptive histogram equalization to an image of mineral deposits to reveal previously indistinguishable features. This example uses a the mineral.png file in the examples/data directory. Complete the following steps for a detailed description of the process.
| Example Code See adaptiveequalizing.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
mineral.png file:
file = FILEPATH('mineral.png', $
SUBDIRECTORY = ['examples', 'data'])
image = READ_PNG(file, red, green, blue)
imageSize = SIZE(image, /DIMENSIONS)
DEVICE, DECOMPOSED = 0 TVLCT, red, green, blue
WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Original Image' TV, image
The following figure shows the original image.
![]() |
WINDOW, 1, TITLE = 'Histogram of Image' PLOT, HISTOGRAM(image), /XSTYLE, /YSTYLE, $ TITLE = 'Mineral Image Histogram', $ XTITLE = 'Intensity Value', $ YTITLE = 'Number of Pixels of That Value'
The following figure shows the resulting display.
equalizedImage = ADAPT_HIST_EQUAL(image)
WINDOW, 2, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Adaptive Equalized Image' TV, equalizedImage
The following figure shows the results of adaptive histogram equalization. All the variations within the image are now noticeable.
WINDOW, 3, TITLE = 'Histogram of Adaptive Equalized Image' PLOT, HISTOGRAM(equalizedImage), /XSTYLE, /YSTYLE, $ TITLE = 'Adaptive Equalized Image Histogram', $ XTITLE = 'Intensity Value', $ YTITLE = 'Number of Pixels of That Value'
The following figure shows the modified image's histogram. The resulting histogram contains no empty regions and fewer extreme peaks and valleys than the original image.
IDL Online Help (March 06, 2007)