~ubuntu-branches/ubuntu/saucy/gnudatalanguage/saucy-proposed

« back to all changes in this revision

Viewing changes to src/pro/image_statistics.pro

  • Committer: Package Import Robot
  • Author(s): Axel Beckert
  • Date: 2013-05-15 02:23:58 UTC
  • mfrom: (15.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130515022358-rziznpf225zn9lv9
Tags: 0.9.3-2
* Upload to unstable.
* Revamp debian/rules
  - Allow parallel builds
  - Use debian/manpages instead of dh_installman parameter
  - Switch to dh7 style debian/rules file
* Bump debhelper compatibility to 9
  - Update versioned debhelper build-dependency
* Bump Standards-Version to 3.9.4 (no changes)
* Apply wrap-and-sort

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;+
 
2
; NAME:    IMAGE_STATISTICS
 
3
;
 
4
; PURPOSE:
 
5
;
 
6
; CATEGORY:
 
7
;
 
8
;
 
9
;
 
10
; CALLING SEQUENCE:
 
11
;
 
12
;
 
13
;
 
14
; INPUTS:
 
15
;
 
16
;
 
17
;
 
18
; OPTIONAL INPUTS:
 
19
;
 
20
;
 
21
;
 
22
; KEYWORD PARAMETERS:
 
23
;
 
24
;
 
25
;
 
26
; OUTPUTS:
 
27
;
 
28
;
 
29
;
 
30
; OPTIONAL OUTPUTS:
 
31
;
 
32
;
 
33
;
 
34
; COMMON BLOCKS: none
 
35
;
 
36
; SIDE EFFECTS:
 
37
;
 
38
;
 
39
;
 
40
; RESTRICTIONS:
 
41
;
 
42
;
 
43
;
 
44
; PROCEDURE:
 
45
;
 
46
;
 
47
;
 
48
; EXAMPLE:
 
49
;
 
50
;
 
51
; LICENCE: this code is under GNU GPL v2 or later. (C) 2011
 
52
 
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
 
57
;-
 
58
;
 
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)'
 
62
end
 
63
;
 
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, $
 
68
                      variance=variance_, $
 
69
                      lut=lut, vector=vector, $
 
70
                      weight_sum=weight_sum, weighted=weighted, $
 
71
                      labeled=labeled, $
 
72
                      help=help, test=test, verbose=verbose
 
73
;
 
74
if N_PARAMS() NE 1 then MESSAGE, 'Incorrect number of arguments.'
 
75
;
 
76
if ((SIZE(input_data))[0] LT 1) then MESSAGE, 'Expression must be an array in this context'
 
77
;
 
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'
 
88
   return
 
89
endif
 
90
;
 
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'
 
95
;
 
96
image=input_data
 
97
if KEYWORD_SET(mask) then begin
 
98
   if KEYWORD_SET(labeled) then begin
 
99
   hist=HISTOGRAM(mask, reverse_indices=ri)
 
100
   n=N_ELEMENTS(hist)
 
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)
 
112
         minimum[i] = 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))
 
116
      endif
 
117
   endfor
 
118
   endif else begin
 
119
      OK=WHERE(mask NE 0, nbp_ok)
 
120
      if (nbp_ok GT 0) then image=input_data[OK]
 
121
   endelse
 
122
endif
 
123
;
 
124
if KEYWORD_SET(labeled) then begin
 
125
   ; basically do nothing, just allows us to create a block for the non-labeled
 
126
   ; calculations
 
127
endif else begin
 
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))
 
135
endelse
 
136
;
 
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)
 
146
         endif
 
147
      endfor
 
148
   endif else begin
 
149
      stddev_=FLOAT(STDDEV(image,/double))
 
150
      variance_=FLOAT(VARIANCE(image,/double))
 
151
   endelse
 
152
endif else begin
 
153
   stddev_=0.0
 
154
   variance_=0.0
 
155
endelse
 
156
;
 
157
if KEYWORD_SET(verbose) then begin
 
158
   if KEYWORD_SET(mask) then begin
 
159
      print, 'Statistics on MASKED Image:'
 
160
   endif else begin
 
161
      print, 'Statistics on Image:'
 
162
   endelse
 
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_
 
171
endif
 
172
;
 
173
if KEYWORD_SET(test) then STOP
 
174
;
 
175
end