2
; NAME: IMAGE_STATISTICS
51
; LICENCE: this code is under GNU GPL v2 or later. (C) 2011
53
; MODIFICATION HISTORY:
54
; -- first draft created by Alain Coulais, 10-Nov-2011
55
; -- 15-Nov-2011 : AC : better managmenet of output types
56
; -- 02-Jul-2012 : Josh Sixsmith : Added the labeled keyword
59
pro ImSt_MESS, keyword_name
60
MESSAGE, /continue, 'This keyword '+STRUPCASE(keyword_name)+' is not available'
61
MESSAGE, /continue, 'Please consider to contribute (by submitting Patches on SF.net)'
64
pro IMAGE_STATISTICS, input_data, mask=mask, count=count, $
65
data_sum=data_sum, maximum=maximum, $
66
mean=mean_, minimum=minimum, $
67
stddev=stddev_, sum_of_squares=sum_of_squares, $
69
lut=lut, vector=vector, $
70
weight_sum=weight_sum, weighted=weighted, $
72
help=help, test=test, verbose=verbose
74
if N_PARAMS() NE 1 then MESSAGE, 'Incorrect number of arguments.'
76
if ((SIZE(input_data))[0] LT 1) then MESSAGE, 'Expression must be an array in this context'
78
if KEYWORD_SET(help) then begin
79
print, 'pro IMAGE_STATISTICS, data, mask=mask, count=count, $'
80
print, ' data_sum=data_sum, maximum=maximum, $'
81
print, ' mean=mean_, minimum=minimum, $'
82
print, ' stddev=stddev_, sum_of_squares=sum_of_squares, $'
83
print, ' variance=variance_, $'
84
print, ' lut=lut, vector=vector, $'
85
print, ' weight_sum=weight_sum, weighted=weighted, $'
86
print, ' labeled=labeled, $'
87
print, ' help=help, test=test, verbose=verbose'
91
if KEYWORD_SET(lut) then ImSt_MESS, 'lut'
92
if KEYWORD_SET(vector) then ImSt_MESS, 'vector'
93
if KEYWORD_SET(weight_sum) then ImSt_MESS, 'weight_sum'
94
if KEYWORD_SET(weighted) then ImSt_MESS, 'weighted'
97
if KEYWORD_SET(mask) then begin
98
if KEYWORD_SET(labeled) then begin
99
hist=HISTOGRAM(mask, reverse_indices=ri)
101
mean_=FLTARR(n, /nozero)
102
maximum=FLTARR(n, /nozero)
103
minimum=FLTARR(n, /nozero)
104
count=ULONARR(n, /nozero)
105
data_sum=FLTARR(n, /nozero)
106
sum_of_squares=FLTARR(n, /nozero)
107
for i=0L, n-1 do begin
108
if ri[i] NE ri[i+1] then begin
109
data=image[ri[ri[i]:ri[i+1]-1]]
110
mean_[i] = MEAN(data,/double)
111
maximum[i] = MAX(data, min=min_i)
113
count[i] = N_ELEMENTS(data)
114
data_sum[i] = TOTAL(data, /double)
115
sum_of_squares[i] = FLOAT(TOTAL(data^2D, /double))
119
OK=WHERE(mask NE 0, nbp_ok)
120
if (nbp_ok GT 0) then image=input_data[OK]
124
if KEYWORD_SET(labeled) then begin
125
; basically do nothing, just allows us to create a block for the non-labeled
128
count=ULONG(N_ELEMENTS(image))
129
data_sum=FLOAT(TOTAL(image,/double))
130
mean_=FLOAT(MEAN(image,/double))
131
maximum=MAX(image, min=minimum)
132
maximum=FLOAT(maximum)
133
minimum=FLOAT(minimum)
134
sum_of_squares=FLOAT(TOTAL(image^2.D,/double))
137
if N_ELEMENTS(image) GT 1 then begin
138
if KEYWORD_SET(labeled) then begin
139
stddev_=FLTARR(n, /nozero)
140
variance_=FLTARR(n, /nozero)
141
for i=0L, n-1 do begin
142
if ri[i] NE ri[i+1] then begin
143
data=image[ri[ri[i]:ri[i+1]-1]]
144
stddev_[i] = STDDEV(data, /double)
145
variance_[i] = VARIANCE(data, /double)
149
stddev_=FLOAT(STDDEV(image,/double))
150
variance_=FLOAT(VARIANCE(image,/double))
157
if KEYWORD_SET(verbose) then begin
158
if KEYWORD_SET(mask) then begin
159
print, 'Statistics on MASKED Image:'
161
print, 'Statistics on Image:'
163
print, 'Total Number of Pixels = ', count
164
print, 'Total of Pixel Values = ', data_sum
165
print, 'Maximum Pixel Value = ', maximum
166
print, 'Mean of Pixel Values = ', mean_
167
print, 'Minimum Pixel Value = ', minimum
168
print, 'Standard Deviation of Pixel Values = ', stddev_
169
print, 'Total of Squared Pixel Values = ', sum_of_squares
170
print, 'Variance of Pixel Values = ', variance_
173
if KEYWORD_SET(test) then STOP