Routines (alphabetical) > Routines: I > IMAGE_STATISTICS

# IMAGE_STATISTICS

The IMAGE_STATISTICS procedure computes sample statistics for a given array of values. An optional mask may be specified to restrict computations to a spatial subset of the input data.

## Example

Copy and paste the following code at the IDL command line to see an example of using IMAGE_STATISTICS.

; Locate the glowing_gas.jpg file, then read it in.

place = FILEPATH('glowing_gas.jpg', SUBDIR=['examples', 'data'])

READ_JPEG, place, picture

; Generate stats on the image...

IMAGE_STATISTICS, picture, MAXIMUM=ma, MINIMUM=mi, MEAN=me, $

STDDEV=s, SUM_OF_SQUARES=sos, VARIANCE=v

; Display the image with the stats over the top, using TEXT.

im = IMAGE(picture)

t1 = TEXT(160, 355, 'Max: '+string(ma), COLOR='white', /DATA)

t2 = TEXT(160, 330, 'Min: '+string(mi), COLOR='white', /DATA)

t3 = TEXT(160, 305, 'Mean: '+string(me), COLOR='white', /DATA)

t4 = TEXT(160, 280, 'SD: '+string(s), COLOR='white', /DATA)

t5 = TEXT(160, 255, 'Sum_Sqs: '+string(sos), COLOR='white', /DATA)

t6 = TEXT(160, 230, 'Var: '+string(v), COLOR='white', /DATA)

## Syntax

IMAGE_STATISTICS, Data [, COUNT=variable] [, DATA_SUM=variable] [, /LABELED] [, LUT=array] [, MASK=array] [, MAXIMUM=variable] [, MEAN=variable] [, MINIMUM=variable] [, STDDEV=variable] [, SUM_OF_SQUARES=variable] [, VARIANCE=variable] [, /VECTOR] [, WEIGHT_SUM=variable] [, /WEIGHTED]

## Arguments

### Data

An N-dimensional input data array.

## Keywords

### COUNT

Set this keyword to a named variable to contain the number of samples that correspond to nonzero values within the mask.

### DATA_SUM

Set this keyword to a named variable to contain the sum of the samples that lie within the mask.

### LABELED

When set, this keyword indicates values in the mask representing region labels, where each pixel of the mask is set to the index of the region in which that pixel belongs (see the LABEL_REGION function. If the LABELED keyword is set, each statistic’s value is computed for each region index. Thus, a vector containing the results is provided for each statistic with one element per region. By default, this keyword is set to zero, indicating that all samples with a corresponding nonzero mask value are used to form a scalar result for each statistic.

Note: The LABELED keyword cannot be used with either the WEIGHT_SUM or the WEIGHTED keywords.

### LUT

Set this keyword to a one-dimensional array. For non-floating point input Data, the pixel values are looked up through this table before being used in any of the statistical computations. This allows an integer image array to be calibrated to any user specified intensity range for the sake of calculations. The length of this array must include the range of the input array. This keyword may not be set with floating point input data. When signed input data types are used, they are first cast to the corresponding IDL unsigned type before being used to access this array. For example, the integer value –1 looks up the value 65535 in the LUT array.

### MASK

An array of N, or N–1 (when the VECTOR keyword is used) dimensions representing the mask array. If the LABELED keyword is set, MASK contains the region indices of each pixel; otherwise statistics are only computed for data values where the MASK array is non-zero.

### MAXIMUM

Set this keyword to a named variable to contain the maximum value of the samples that lie within the mask.

### MEAN

Set this keyword to a named variable to contain the mean of the samples that lie within the mask.

### MINIMUM

Set this keyword to a named variable to contain the minimum value of the samples that lie within the mask.

### STDDEV

Set this keyword to a named variable to contain the standard deviation of the samples that lie within the mask.

### SUM_OF_SQUARES

Set this keyword to a named variable to contain the sum of the squares of the samples that lie within the mask.

### VARIANCE

Set this keyword to a named variable to contain the variance of the samples that lie within the mask.

### VECTOR

Set this keyword to specify that the leading dimension of the input array is not to be considered spatial but consists of multiple data values at each pixel location. In this case, the leading dimension is treated as a vector of samples at the spatial location determined by the remainder of the array dimensions.

### WEIGHT_SUM

Set the WEIGHT_SUM keyword to a named variable to contain the sum of the weights in the mask.

Note: The WEIGHT_SUM keyword cannot be used if the LABELED keyword is specified.

### WEIGHTED

If the WEIGHTED keyword is set, the values in the MASK array are used to weight individual pixels with respect to their count value. If a MASK array is not provided, all pixels are assigned a weight of 1.0.

Note: The WEIGHTED keyword cannot be used if the LABELED keyword is specified.

## Version History

5.3 | Introduced