1 //*******************************************************************
2 //
3 // LICENSE: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts
6 //
7 //*******************************************************************
8 // $Id: ossimDiscrete3x3HatFilter.cpp 11419 2007-07-27 16:24:57Z dburken $
9 #include <ossim/imaging/ossimDiscrete3x3HatFilter.h>
10 #include <ossim/base/ossimCommon.h>
11
ossimDiscrete3x3HatFilter()12 ossimDiscrete3x3HatFilter::ossimDiscrete3x3HatFilter()
13 :ossimDiscreteConvolutionKernel(3,3)
14 {
15 // make the default be the nearest neighbor
16 (*theKernel)[0][0] = 0;
17 (*theKernel)[0][1] = 0;
18 (*theKernel)[0][2] = 0;
19
20 (*theKernel)[1][0] = 0;
21 (*theKernel)[1][1] = 1;
22 (*theKernel)[1][2] = 0;
23
24 (*theKernel)[2][0] = 0;
25 (*theKernel)[2][1] = 0;
26 (*theKernel)[2][2] = 0;
27 }
28
convolve(const float * data,double & result,float nullPixel) const29 void ossimDiscrete3x3HatFilter::convolve(const float* data,
30 double& result,
31 float nullPixel)const
32 {
33 double divisor = 0;
34 result = 0;
35
36 if(data[0] != nullPixel)
37 {
38 divisor += (*theKernel)[0][0];
39 result += (*theKernel)[0][0] * data[0];
40 }
41 if(data[1] != nullPixel)
42 {
43 divisor += (*theKernel)[0][1];
44 result += (*theKernel)[0][1] * data[1];
45 }
46 if(data[2] != nullPixel)
47 {
48 divisor += (*theKernel)[0][2];
49 result += (*theKernel)[0][2] * data[2];
50 }
51 if(data[3] != nullPixel)
52 {
53 divisor += (*theKernel)[1][0];
54 result += (*theKernel)[1][0] * data[3];
55 }
56 if(data[4] != nullPixel)
57 {
58 divisor += (*theKernel)[1][1];
59 result += (*theKernel)[1][1] * data[4];
60 }
61 if(data[5] != nullPixel)
62 {
63 divisor += (*theKernel)[1][2];
64 result += (*theKernel)[1][2] * data[5];
65 }
66 if(data[6] != nullPixel)
67 {
68 divisor += (*theKernel)[2][0];
69 result += (*theKernel)[2][0] * data[6];
70 }
71 if(data[7] != nullPixel)
72 {
73 divisor += (*theKernel)[2][1];
74 result += (*theKernel)[2][1] * data[7];
75 }
76 if(data[8] != nullPixel)
77 {
78 divisor += (*theKernel)[2][2];
79 result += (*theKernel)[2][2] * data[8];
80 }
81
82
83 if(divisor > 0)
84 result /= divisor;
85 }
86
convolveSubImage(const float * data,long dataWidth,double & result,float nullPixel) const87 void ossimDiscrete3x3HatFilter::convolveSubImage(const float* data,
88 long dataWidth,
89 double& result,
90 float nullPixel)const
91 {
92 double divisor = 0.0;
93 result = 0;
94
95 if(data[0] != nullPixel)
96 {
97 divisor += (*theKernel)[0][0];
98 result += (*theKernel)[0][0]*data[0];
99 }
100 if(data[1] != nullPixel)
101 {
102 divisor += (*theKernel)[0][1];
103 result += (*theKernel)[0][1]*data[1];
104 }
105 if(data[2] != nullPixel)
106 {
107 divisor += (*theKernel)[0][2];
108 result += (*theKernel)[0][2]*data[2];
109 }
110
111 data +=dataWidth;
112 if(data[0] != nullPixel)
113 {
114 divisor += (*theKernel)[1][0];
115 result += (*theKernel)[1][0]*data[0];
116 }
117 if(data[1] != nullPixel)
118 {
119 divisor += (*theKernel)[1][1];
120 result += (*theKernel)[1][1]*data[1];
121 }
122 if(data[2] != nullPixel)
123 {
124 divisor += (*theKernel)[1][2];
125 result += (*theKernel)[1][2]*data[2];
126 }
127
128 data +=dataWidth;
129 if(data[0] != nullPixel)
130 {
131 divisor += (*theKernel)[2][0];
132 result += (*theKernel)[2][0]*data[0];
133 }
134 if(data[1] != nullPixel)
135 {
136 divisor += (*theKernel)[2][1];
137 result += (*theKernel)[2][1]*data[1];
138 }
139 if(data[2] != nullPixel)
140 {
141 divisor += (*theKernel)[2][2];
142 result += (*theKernel)[2][2]*data[2];
143 }
144
145 if(divisor > 0)
146 {
147 result /= divisor;
148 }
149 }
150
convolve(const unsigned char * data,double & result,ossim_uint8 nullPixel) const151 void ossimDiscrete3x3HatFilter::convolve(const unsigned char* data,
152 double& result,
153 ossim_uint8 nullPixel)const
154 {
155 double divisor = 0;
156 result = 0;
157
158 if(data[0] != nullPixel)
159 {
160 divisor += (*theKernel)[0][0];
161 result += (*theKernel)[0][0] * data[0];
162 }
163 if(data[1] != nullPixel)
164 {
165 divisor += (*theKernel)[0][1];
166 result += (*theKernel)[0][1] * data[1];
167 }
168 if(data[2] != nullPixel)
169 {
170 divisor += (*theKernel)[0][2];
171 result += (*theKernel)[0][2] * data[2];
172 }
173 if(data[3] != nullPixel)
174 {
175 divisor += (*theKernel)[1][0];
176 result += (*theKernel)[1][0] * data[3];
177 }
178 if(data[4] != nullPixel)
179 {
180 divisor += (*theKernel)[1][1];
181 result += (*theKernel)[1][1] * data[4];
182 }
183 if(data[5] != nullPixel)
184 {
185 divisor += (*theKernel)[1][2];
186 result += (*theKernel)[1][2] * data[5];
187 }
188 if(data[6] != nullPixel)
189 {
190 divisor += (*theKernel)[2][0];
191 result += (*theKernel)[2][0] * data[6];
192 }
193 if(data[7] != nullPixel)
194 {
195 divisor += (*theKernel)[2][1];
196 result += (*theKernel)[2][1] * data[7];
197 }
198 if(data[8] != nullPixel)
199 {
200 divisor += (*theKernel)[2][2];
201 result += (*theKernel)[2][2] * data[8];
202 }
203
204
205 if(divisor > 0)
206 result /= divisor;
207 }
208
209
convolveSubImage(const unsigned char * data,long dataWidth,double & result,ossim_uint8 nullPixel) const210 void ossimDiscrete3x3HatFilter::convolveSubImage(const unsigned char* data,
211 long dataWidth,
212 double& result,
213 ossim_uint8 nullPixel)const
214 {
215 double divisor = 0.0;
216 result = 0;
217
218 if(data[0] != nullPixel)
219 {
220 divisor += (*theKernel)[0][0];
221 result += (*theKernel)[0][0]*data[0];
222 }
223 if(data[1] != nullPixel)
224 {
225 divisor += (*theKernel)[0][1];
226 result += (*theKernel)[0][1]*data[1];
227 }
228 if(data[2] != nullPixel)
229 {
230 divisor += (*theKernel)[0][2];
231 result += (*theKernel)[0][2]*data[2];
232 }
233
234 data +=dataWidth;
235 if(data[0] != nullPixel)
236 {
237 divisor += (*theKernel)[1][0];
238 result += (*theKernel)[1][0]*data[0];
239 }
240 if(data[1] != nullPixel)
241 {
242 divisor += (*theKernel)[1][1];
243 result += (*theKernel)[1][1]*data[1];
244 }
245 if(data[2] != nullPixel)
246 {
247 divisor += (*theKernel)[1][2];
248 result += (*theKernel)[1][2]*data[2];
249 }
250
251 data +=dataWidth;
252 if(data[0] != nullPixel)
253 {
254 divisor += (*theKernel)[2][0];
255 result += (*theKernel)[2][0]*data[0];
256 }
257 if(data[1] != nullPixel)
258 {
259 divisor += (*theKernel)[2][1];
260 result += (*theKernel)[2][1]*data[1];
261 }
262 if(data[2] != nullPixel)
263 {
264 divisor += (*theKernel)[2][2];
265 result += (*theKernel)[2][2]*data[2];
266 }
267
268 if(divisor > 0)
269 {
270 result /= divisor;
271 }
272 }
273
buildConvolution(double xLocation,double yLocation)274 void ossimDiscrete3x3HatFilter::buildConvolution(double xLocation,
275 double yLocation)
276 {
277 NEWMAT::RowVector row(3);
278 NEWMAT::ColumnVector col(3);
279
280 row[0] = std::abs(xLocation);
281 row[1] = 1;
282 row[2] = std::abs(xLocation);
283 col[0] = std::abs(yLocation);
284 col[1] = 1;
285 col[2] = std::abs(yLocation);
286
287 (*theKernel) = col*row;
288 }
289