OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
ossimDiscreteConvolutionKernel Class Reference

#include <ossimDiscreteConvolutionKernel.h>

Inheritance diagram for ossimDiscreteConvolutionKernel:
ossimDiscrete3x3HatFilter ossimDiscreteNearestNeighbor

Public Member Functions

 ossimDiscreteConvolutionKernel (long width, long height, bool doWeightedAverage=true)
 
 ossimDiscreteConvolutionKernel (const NEWMAT::Matrix &kernel, bool doWeightedAverage=true)
 
virtual ~ossimDiscreteConvolutionKernel ()
 
virtual void setKernel (const NEWMAT::Matrix &kernel)
 
virtual void convolve (const float *data, double &result, float nullPixel=OSSIM_DEFAULT_NULL_PIX_FLOAT) const
 
virtual void convolveSubImage (const float *data, long dataWidth, double &result, float nullPixel=OSSIM_DEFAULT_NULL_PIX_FLOAT) const
 
virtual void convolve (const double *data, double &result, double nullPixel=OSSIM_DEFAULT_NULL_PIX_DOUBLE) const
 
virtual void convolveSubImage (const double *data, long dataWidth, double &result, double nullPixel=OSSIM_DEFAULT_NULL_PIX_DOUBLE) const
 
virtual void convolve (const short *data, double &result, ossim_sint16 nullPixel=OSSIM_DEFAULT_NULL_PIX_SINT16) const
 
virtual void convolveSubImage (const short *data, long dataWidth, double &result, ossim_sint16 nullPixel=OSSIM_DEFAULT_NULL_PIX_SINT16) const
 
virtual void convolve (const unsigned short *data, double &result, ossim_uint16 nullPixel=OSSIM_DEFAULT_NULL_PIX_UINT16) const
 
virtual void convolveSubImage (const unsigned short *data, long dataWidth, double &result, ossim_uint16 nullPixel=OSSIM_DEFAULT_NULL_PIX_UINT16) const
 
virtual void convolve (const unsigned char *data, double &result, ossim_uint8 nullPixel=OSSIM_DEFAULT_NULL_PIX_UINT8) const
 
virtual void convolveSubImage (const unsigned char *data, long dataWidth, double &result, ossim_uint8 nullPixel=OSSIM_DEFAULT_NULL_PIX_UINT8) const
 
virtual void buildConvolution (double, double)
 
virtual long getWidth () const
 
virtual long getHeight () const
 
const NEWMAT::Matrix & getKernel () const
 

Static Public Member Functions

static void buildSymmetric (const std::vector< float > &coefficients, NEWMAT::Matrix &result)
 
static void buildSymmetric (float *coefficients, long size, NEWMAT::Matrix &result)
 

Protected Attributes

NEWMAT::Matrix * theKernel
 
long theWidth
 
long theHeight
 
bool theComputeWeightedAverageFlag
 

Detailed Description

Definition at line 19 of file ossimDiscreteConvolutionKernel.h.

Constructor & Destructor Documentation

◆ ossimDiscreteConvolutionKernel() [1/2]

ossimDiscreteConvolutionKernel::ossimDiscreteConvolutionKernel ( long  width,
long  height,
bool  doWeightedAverage = true 
)

◆ ossimDiscreteConvolutionKernel() [2/2]

ossimDiscreteConvolutionKernel::ossimDiscreteConvolutionKernel ( const NEWMAT::Matrix &  kernel,
bool  doWeightedAverage = true 
)

◆ ~ossimDiscreteConvolutionKernel()

ossimDiscreteConvolutionKernel::~ossimDiscreteConvolutionKernel ( )
virtual

Definition at line 36 of file ossimDiscreteConvolutionKernel.cpp.

References theKernel.

37 {
38  if(theKernel)
39  {
40  delete theKernel;
41  theKernel = 0;
42  }
43 }

Member Function Documentation

◆ buildConvolution()

virtual void ossimDiscreteConvolutionKernel::buildConvolution ( double  ,
double   
)
inlinevirtual

This is used to allow me to continually adjust a convolution kernel based on where it center lies on a pixel. The xLocation and yLocation are all from the center of pixel. If I am convolving at full resolution then xLocation and yLocation should both be 0. Let's pretend that we contract an image by .5 scale factor or zooming out by a factor of 2. Then we actually of it .5 off from cneter of pixel in both the x and y direction. This information can be used to allow a kernel to adjust it's waits accordingly.

Typically if the xLocation and yLocation is directly on the center indicated by 0 vor both then the kernel defaults to 1 in the middle and all other weights are zero.

Reimplemented in ossimDiscreteNearestNeighbor, and ossimDiscrete3x3HatFilter.

Definition at line 113 of file ossimDiscreteConvolutionKernel.h.

115  {}

◆ buildSymmetric() [1/2]

void ossimDiscreteConvolutionKernel::buildSymmetric ( const std::vector< float > &  coefficients,
NEWMAT::Matrix &  result 
)
static

Definition at line 45 of file ossimDiscreteConvolutionKernel.cpp.

References size.

47 {
48  ossim_uint32 size = (ossim_uint32)coefficients.size();
49  if(size > 0)
50  {
51 
52  NEWMAT::RowVector row(size);
53  NEWMAT::ColumnVector col(size);
54  for(ossim_uint32 index = 0; index < size; ++index)
55  {
56  row[index] = coefficients[index];
57  col[index] = coefficients[index];
58  }
59  result = col*row;
60  }
61 }
yy_size_t size
unsigned int ossim_uint32

◆ buildSymmetric() [2/2]

void ossimDiscreteConvolutionKernel::buildSymmetric ( float *  coefficients,
long  size,
NEWMAT::Matrix &  result 
)
static

Definition at line 63 of file ossimDiscreteConvolutionKernel.cpp.

References size.

66 {
67  if(size > 0)
68  {
69  NEWMAT::RowVector row(size);
70  NEWMAT::ColumnVector col(size);
71  for(long index = 0; index < size; ++index)
72  {
73  row[index] = coefficients[index];
74  col[index] = coefficients[index];
75  }
76  result = col*row;
77  }
78 }
yy_size_t size

◆ convolve() [1/5]

void ossimDiscreteConvolutionKernel::convolve ( const float *  data,
double &  result,
float  nullPixel = OSSIM_DEFAULT_NULL_PIX_FLOAT 
) const
virtual

Will expect a data buffer of size width*height and is row ordered.

Reimplemented in ossimDiscrete3x3HatFilter.

Definition at line 91 of file ossimDiscreteConvolutionKernel.cpp.

References theComputeWeightedAverageFlag, theHeight, and theWidth.

94 {
95  result = 0;
96 
98  {
99  double divisor = 0.0;
100  for(long row=0; row < theHeight; ++row)
101  {
102  for(long col=0; col < theWidth; ++col)
103  {
104  if(*data != nullPixel)
105  {
106  divisor += (*theKernel)[row][col];
107  result += ((*theKernel)[row][col] * (*data));
108  }
109  ++data;
110  }
111  }
112  if(divisor > 0)
113  {
114  result /= divisor;
115  }
116  }
117  else
118  {
119  for(long row=0; row < theHeight; ++row)
120  {
121  for(long col=0; col < theWidth; ++col)
122  {
123  if(*data != nullPixel)
124  {
125  result += ((*theKernel)[row][col] * (*data));
126  }
127  ++data;
128  }
129  }
130  }
131 }

◆ convolve() [2/5]

void ossimDiscreteConvolutionKernel::convolve ( const double *  data,
double &  result,
double  nullPixel = OSSIM_DEFAULT_NULL_PIX_DOUBLE 
) const
virtual

Will expect a data buffer of size width*height and is row ordered.

Definition at line 453 of file ossimDiscreteConvolutionKernel.cpp.

References theComputeWeightedAverageFlag, theHeight, and theWidth.

456 {
457  result = 0;
458 
460  {
461  double divisor = 0.0;
462  for(long row=0; row < theHeight; ++row)
463  {
464  for(long col=0; col < theWidth; ++col)
465  {
466  if(*data != nullPixel)
467  {
468  divisor += (*theKernel)[row][col];
469  result += ((*theKernel)[row][col] * (*data));
470  }
471  ++data;
472  }
473  }
474  if(divisor > 0)
475  {
476  result /= divisor;
477  }
478  }
479  else
480  {
481  for(long row=0; row < theHeight; ++row)
482  {
483  for(long col=0; col < theWidth; ++col)
484  {
485  if(*data != nullPixel)
486  {
487  result += ((*theKernel)[row][col] * (*data));
488  }
489  ++data;
490  }
491  }
492  }
493 }

◆ convolve() [3/5]

void ossimDiscreteConvolutionKernel::convolve ( const short *  data,
double &  result,
ossim_sint16  nullPixel = OSSIM_DEFAULT_NULL_PIX_SINT16 
) const
virtual

Will expect a data buffer of size width*height and is row ordered.

Definition at line 362 of file ossimDiscreteConvolutionKernel.cpp.

References theComputeWeightedAverageFlag, theHeight, and theWidth.

365 {
366  result = 0;
367 
369  {
370  double divisor = 0.0;
371  for(long row=0; row < theHeight; ++row)
372  {
373  for(long col=0; col < theWidth; ++col)
374  {
375  if(*data != nullPixel)
376  {
377  divisor += (*theKernel)[row][col];
378  result += ((*theKernel)[row][col] * (*data));
379  }
380  ++data;
381  }
382  }
383  if(divisor > 0)
384  {
385  result /= divisor;
386  }
387  }
388  else
389  {
390  for(long row=0; row < theHeight; ++row)
391  {
392  for(long col=0; col < theWidth; ++col)
393  {
394  if(*data != nullPixel)
395  {
396  result += ((*theKernel)[row][col] * (*data));
397  }
398  ++data;
399  }
400  }
401  }
402 }

◆ convolve() [4/5]

void ossimDiscreteConvolutionKernel::convolve ( const unsigned short *  data,
double &  result,
ossim_uint16  nullPixel = OSSIM_DEFAULT_NULL_PIX_UINT16 
) const
virtual

Will expect a data buffer of size width*height and is row ordered.

Definition at line 272 of file ossimDiscreteConvolutionKernel.cpp.

References theComputeWeightedAverageFlag, theHeight, and theWidth.

275 {
276  result = 0;
277 
279  {
280  double divisor = 0.0;
281  for(long row=0; row < theHeight; ++row)
282  {
283  for(long col=0; col < theWidth; ++col)
284  {
285  if(*data != nullPixel)
286  {
287  divisor += (*theKernel)[row][col];
288  result += ((*theKernel)[row][col] * (*data));
289  }
290  ++data;
291  }
292  }
293  if(divisor > 0)
294  {
295  result /= divisor;
296  }
297  }
298  else
299  {
300  for(long row=0; row < theHeight; ++row)
301  {
302  for(long col=0; col < theWidth; ++col)
303  {
304  if(*data != nullPixel)
305  {
306  result += ((*theKernel)[row][col] * (*data));
307  }
308  ++data;
309  }
310  }
311  }
312 }

◆ convolve() [5/5]

void ossimDiscreteConvolutionKernel::convolve ( const unsigned char *  data,
double &  result,
ossim_uint8  nullPixel = OSSIM_DEFAULT_NULL_PIX_UINT8 
) const
virtual

Reimplemented in ossimDiscrete3x3HatFilter.

Definition at line 181 of file ossimDiscreteConvolutionKernel.cpp.

References theComputeWeightedAverageFlag, theHeight, and theWidth.

184 {
185  result = 0;
186 
188  {
189  double divisor = 0.0;
190  for(long row=0; row < theHeight; ++row)
191  {
192  for(long col=0; col < theWidth; ++col)
193  {
194  if(*data != nullPixel)
195  {
196  divisor += (*theKernel)[row][col];
197  result += ((*theKernel)[row][col] * (*data));
198  }
199  ++data;
200  }
201  }
202  if(divisor > 0)
203  {
204  result /= divisor;
205  }
206  }
207  else
208  {
209  for(long row=0; row < theHeight; ++row)
210  {
211  for(long col=0; col < theWidth; ++col)
212  {
213  if(*data != nullPixel)
214  {
215  result += ((*theKernel)[row][col] * (*data));
216  }
217  ++data;
218  }
219  }
220  }
221 }

◆ convolveSubImage() [1/5]

void ossimDiscreteConvolutionKernel::convolveSubImage ( const float *  data,
long  dataWidth,
double &  result,
float  nullPixel = OSSIM_DEFAULT_NULL_PIX_FLOAT 
) const
virtual

Reimplemented in ossimDiscrete3x3HatFilter.

Definition at line 133 of file ossimDiscreteConvolutionKernel.cpp.

References theComputeWeightedAverageFlag, theHeight, and theWidth.

Referenced by ossimConvolutionSource::convolve(), and ossimTilePatch::fillTileTemplate().

137 {
138  const float* dataStart = 0;
139  result = 0;
140 
142  {
143  double divisor = 0.0;
144  for(long row=0; row < theHeight; ++row)
145  {
146  dataStart=data;
147  for(long col=0; col < theWidth; ++col)
148  {
149  if(*dataStart != nullPixel)
150  {
151  divisor += (*theKernel)[row][col];
152  result += ((*theKernel)[row][col] * (*dataStart));
153  }
154  ++dataStart;
155  }
156  data+=dataWidth;
157  }
158  if(divisor > 0)
159  {
160  result /= divisor;
161  }
162  }
163  else
164  {
165  for(long row=0; row < theHeight; ++row)
166  {
167  dataStart=data;
168  for(long col=0; col < theWidth; ++col)
169  {
170  if(*dataStart != nullPixel)
171  {
172  result += ((*theKernel)[row][col] * (*dataStart));
173  }
174  ++dataStart;
175  }
176  data+=dataWidth;
177  }
178  }
179 }

◆ convolveSubImage() [2/5]

void ossimDiscreteConvolutionKernel::convolveSubImage ( const double *  data,
long  dataWidth,
double &  result,
double  nullPixel = OSSIM_DEFAULT_NULL_PIX_DOUBLE 
) const
virtual

Definition at line 495 of file ossimDiscreteConvolutionKernel.cpp.

References theComputeWeightedAverageFlag, theHeight, and theWidth.

499 {
500  const double* dataStart = 0;
501  result = 0;
502 
504  {
505  double divisor = 0.0;
506  for(long row=0; row < theHeight; ++row)
507  {
508  dataStart=data;
509  for(long col=0; col < theWidth; ++col)
510  {
511  if(*dataStart != nullPixel)
512  {
513  divisor += (*theKernel)[row][col];
514  result += ((*theKernel)[row][col] * (*dataStart));
515  }
516  ++dataStart;
517  }
518  data+=dataWidth;
519  }
520  if(divisor > 0)
521  {
522  result /= divisor;
523  }
524  }
525  else
526  {
527  for(long row=0; row < theHeight; ++row)
528  {
529  dataStart=data;
530  for(long col=0; col < theWidth; ++col)
531  {
532  if(*dataStart != nullPixel)
533  {
534  result += ((*theKernel)[row][col] * (*dataStart));
535  }
536  ++dataStart;
537  }
538  data+=dataWidth;
539  }
540  }
541 }

◆ convolveSubImage() [3/5]

void ossimDiscreteConvolutionKernel::convolveSubImage ( const short *  data,
long  dataWidth,
double &  result,
ossim_sint16  nullPixel = OSSIM_DEFAULT_NULL_PIX_SINT16 
) const
virtual

Definition at line 404 of file ossimDiscreteConvolutionKernel.cpp.

References theComputeWeightedAverageFlag, theHeight, and theWidth.

408 {
409  const ossim_sint16* dataStart = 0;
410  result = 0;
411 
413  {
414  double divisor = 0.0;
415  for(long row=0; row < theHeight; ++row)
416  {
417  dataStart=data;
418  for(long col=0; col < theWidth; ++col)
419  {
420  if(*dataStart != nullPixel)
421  {
422  divisor += (*theKernel)[row][col];
423  result += ((*theKernel)[row][col] * (*dataStart));
424  }
425  ++dataStart;
426  }
427  data+=dataWidth;
428  }
429  if(divisor > 0)
430  {
431  result /= divisor;
432  }
433  }
434  else
435  {
436  for(long row=0; row < theHeight; ++row)
437  {
438  dataStart=data;
439  for(long col=0; col < theWidth; ++col)
440  {
441  if(*dataStart != nullPixel)
442  {
443  result += ((*theKernel)[row][col] * (*dataStart));
444  }
445  ++dataStart;
446  }
447  data+=dataWidth;
448  }
449  }
450 }
signed short ossim_sint16

◆ convolveSubImage() [4/5]

void ossimDiscreteConvolutionKernel::convolveSubImage ( const unsigned short *  data,
long  dataWidth,
double &  result,
ossim_uint16  nullPixel = OSSIM_DEFAULT_NULL_PIX_UINT16 
) const
virtual

Definition at line 314 of file ossimDiscreteConvolutionKernel.cpp.

References theComputeWeightedAverageFlag, theHeight, and theWidth.

318 {
319  const ossim_uint16* dataStart = 0;
320  result = 0;
321 
323  {
324  double divisor = 0.0;
325  for(long row=0; row < theHeight; ++row)
326  {
327  dataStart=data;
328  for(long col=0; col < theWidth; ++col)
329  {
330  if(*dataStart != nullPixel)
331  {
332  divisor += (*theKernel)[row][col];
333  result += ((*theKernel)[row][col] * (*dataStart));
334  }
335  ++dataStart;
336  }
337  data+=dataWidth;
338  }
339  if(divisor > 0)
340  {
341  result /= divisor;
342  }
343  }
344  else
345  {
346  for(long row=0; row < theHeight; ++row)
347  {
348  dataStart=data;
349  for(long col=0; col < theWidth; ++col)
350  {
351  if(*dataStart != nullPixel)
352  {
353  result += ((*theKernel)[row][col] * (*dataStart));
354  }
355  ++dataStart;
356  }
357  data+=dataWidth;
358  }
359  }
360 }
unsigned short ossim_uint16

◆ convolveSubImage() [5/5]

void ossimDiscreteConvolutionKernel::convolveSubImage ( const unsigned char *  data,
long  dataWidth,
double &  result,
ossim_uint8  nullPixel = OSSIM_DEFAULT_NULL_PIX_UINT8 
) const
virtual

this allows you to pass a subImage to the convolution engine. It needs to know the width of the buffer so it can increment to the next element.

Reimplemented in ossimDiscrete3x3HatFilter.

Definition at line 223 of file ossimDiscreteConvolutionKernel.cpp.

References theComputeWeightedAverageFlag, theHeight, and theWidth.

227 {
228  const ossim_uint8* dataStart = 0;
229  result = 0;
230 
232  {
233  double divisor = 0.0;
234  for(long row=0; row < theHeight; ++row)
235  {
236  dataStart=data;
237  for(long col=0; col < theWidth; ++col)
238  {
239  if(*dataStart != nullPixel)
240  {
241  divisor += (*theKernel)[row][col];
242  result += ((*theKernel)[row][col] * (*dataStart));
243  }
244  ++dataStart;
245  }
246  data+=dataWidth;
247  }
248  if(divisor > 0)
249  {
250  result /= divisor;
251  }
252  }
253  else
254  {
255  for(long row=0; row < theHeight; ++row)
256  {
257  dataStart=data;
258  for(long col=0; col < theWidth; ++col)
259  {
260  if(*dataStart != nullPixel)
261  {
262  result += ((*theKernel)[row][col] * (*dataStart));
263  }
264  ++dataStart;
265  }
266  data+=dataWidth;
267  }
268  }
269 }
unsigned char ossim_uint8

◆ getHeight()

virtual long ossimDiscreteConvolutionKernel::getHeight ( ) const
inlinevirtual

◆ getKernel()

const NEWMAT::Matrix& ossimDiscreteConvolutionKernel::getKernel ( ) const
inline

Definition at line 124 of file ossimDiscreteConvolutionKernel.h.

References theKernel.

125  {
126  return *theKernel;
127  }

◆ getWidth()

virtual long ossimDiscreteConvolutionKernel::getWidth ( ) const
inlinevirtual

◆ setKernel()

void ossimDiscreteConvolutionKernel::setKernel ( const NEWMAT::Matrix &  kernel)
virtual

Definition at line 80 of file ossimDiscreteConvolutionKernel.cpp.

References theHeight, theKernel, and theWidth.

81 {
82  if(theKernel)
83  {
84  theKernel = new NEWMAT::Matrix;
85  }
86  *theKernel = kernel;
87  theWidth = theKernel->Ncols();
88  theHeight = theKernel->Nrows();
89 }

Member Data Documentation

◆ theComputeWeightedAverageFlag

bool ossimDiscreteConvolutionKernel::theComputeWeightedAverageFlag
protected

Definition at line 132 of file ossimDiscreteConvolutionKernel.h.

Referenced by convolve(), and convolveSubImage().

◆ theHeight

long ossimDiscreteConvolutionKernel::theHeight
protected

◆ theKernel

NEWMAT::Matrix* ossimDiscreteConvolutionKernel::theKernel
protected

◆ theWidth

long ossimDiscreteConvolutionKernel::theWidth
protected

The documentation for this class was generated from the following files: