|
Image Processing : Working with Masks and Image Statistics |
|
The statistical properties of an image provide useful information, such as the total, mean, standard deviation, and variance of the pixel values. IDL's IMAGE_STATISTICS procedure can be used to calculate these statistical properties. The MOMENT, N_ELEMENTS, TOTAL, MAX, MEAN, MIN, STDDEV, and VARIANCE routines can also be used to calculate individual statistics, but most of these values are already provided by the IMAGE_STATISTICS procedure.
The following example shows how to use the IMAGE_STATISTICS procedure to calculate the statistical properties of an image. First, a mask is used to subtract the convection of the earth's core from the convection image contained in the convec.dat file, which is in the examples/data directory. The resulting difference represents the convection of just the earth's mantle. The IMAGE_STATISTICS procedure is applied to this difference image, and the resulting values are displayed in the Output Log. Then, a mask is derived for the non-zero values of the difference image, and the IMAGE_STATISTICS procedure is used again, this time with the mask applied through the MASK keyword. The resulting statistics can than be compared. The color table associated with this example is white for zero values and dark red for 255 values. Complete the following steps for a detailed description of the process.
| Example Code See calculatingstatistics.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
file = FILEPATH('convec.dat', $
SUBDIRECTORY = ['examples', 'data'])
imageSize = [248, 248]
image = READ_BINARY(file, DATA_DIMS = imageSize)
DEVICE, DECOMPOSED = 0 LOADCT, 27
WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Earth Mantle Convection' TV, image
The following figure shows the original convection image.
core = BYTSCL(image EQ 255)
difference = image - core
WINDOW, 2, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Difference of Original & Core' TV, difference
The following figure shows the convection of just the earth's mantle.
![]() |
IMAGE_STATISTICS, difference, COUNT = pixelNumber, $ DATA_SUM = pixelTotal, MAXIMUM = pixelMax, $ MEAN = pixelMean, MINIMUM = pixelMin, $ STDDEV = pixelDeviation, $ SUM_OF_SQUARES = pixelSquareSum, $ VARIANCE = pixelVariance
PRINT, '' PRINT, 'IMAGE STATISTICS:' PRINT, 'Total Number of Pixels = ', pixelNumber PRINT, 'Total of Pixel Values = ', pixelTotal PRINT, 'Maximum Pixel Value = ', pixelMax PRINT, 'Mean of Pixel Values = ', pixelMean PRINT, 'Minimum Pixel Value = ', pixelMin PRINT, 'Standard Deviation of Pixel Values = ', $ pixelDeviation PRINT, 'Total of Squared Pixel Values = ', $ pixelSquareSum PRINT, 'Variance of Pixel Values = ', pixelVariance
IDL prints:
IMAGE STATISTICS: Total Number of Pixels = 61504 Total of Pixel Values = 2.61691e+006 Maximum Pixel Value = 253.000 Mean of Pixel Values = 42.5486 Minimum Pixel Value = 0.000000 Standard Deviation of Pixel Values = 48.7946 Total of Squared Pixel Values = 2.57779e+008 Variance of Pixel Values = 2380.91
nonzeroMask = difference NE 0
IMAGE_STATISTICS, difference, COUNT = pixelNumber, $ DATA_SUM = pixelTotal, MASK = nonzeroMask, $ MAXIMUM = pixelMax, MEAN = pixelMean, $ MINIMUM = pixelMin, STDDEV = pixelDeviation, $ SUM_OF_SQUARES = pixelSquareSum, $ VARIANCE = pixelVariance
PRINT, '' PRINT, 'MASKED IMAGE STATISTICS:' PRINT, 'Total Number of Pixels = ', pixelNumber PRINT, 'Total of Pixel Values = ', pixelTotal PRINT, 'Maximum Pixel Value = ', pixelMax PRINT, 'Mean of Pixel Values = ', pixelMean PRINT, 'Minimum Pixel Value = ', pixelMin PRINT, 'Standard Deviation of Pixel Values = ', $ pixelDeviation PRINT, 'Total of Squared Pixel Values = ', $ pixelSquareSum PRINT, 'Variance of Pixel Values = ', pixelVariance
IDL prints:
MASKED IMAGE STATISTICS: Total Number of Pixels = 36325 Total of Pixel Values = 2.61691e+006 Maximum Pixel Value = 253.000 Mean of Pixel Values = 72.0416 Minimum Pixel Value = 1.00000 Standard Deviation of Pixel Values = 43.6638 Total of Squared Pixel Values = 2.57779e+008 Variance of Pixel Values = 1906.53
The difference in the resulting statistics are because of the zero values, which are a part of the calculations for the image before the mask is applied.
IDL Online Help (March 06, 2007)