1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- /**
- * @file GenericImageTools.cpp
- * @brief simple filter stuff
- * @author Erik Rodner
- * @date 07/30/2008
- */
- #include <iostream>
- #include "GenericImageTools.h"
- template <class PixelValueDst, class PixelValueSrc>
- void GenericImageTools::calcIntegralImage ( PixelValueDst *integralImage, const PixelValueSrc *image, int xsize, int ysize )
- {
- integralImage[0] = image[0];
- int k = xsize;
- for ( int y = 1 ; y < ysize; y++, k+=xsize )
- integralImage[k] = (PixelValueDst)(integralImage[k-xsize] + image[k]);
- k = 1;
- for ( int x = 1 ; x < xsize; x++, k++ )
- integralImage[k] = (PixelValueDst)(integralImage[k-1] + image[k]);
- k = xsize + 1;
- for ( int y = 1 ; y < ysize ; y++,k++ )
- for ( int x = 1 ; x < xsize ; x++,k++ )
- {
- integralImage[k] = (PixelValueDst)image[k];
- integralImage[k] += integralImage[k-1];
- integralImage[k] += integralImage[k - xsize];
- integralImage[k] -= integralImage[k - xsize - 1];
- }
- }
- template <class PixelValueDst, class PixelValueSrc>
- void GenericImageTools::nonMaximumSuppression ( PixelValueDst *dst, const PixelValueSrc *src,
- int xsize, int ysize, bool useEightConnectivity )
- {
- long k = 0;
- for ( int y = 0 ; y < ysize ; y++ )
- for ( int x = 0 ; x < xsize ; x++,k++ )
- {
- if ( x != 0 )
- {
- if ( src[k-1] > src[k] ) { dst[k] = 0; continue; };
- if ( useEightConnectivity ) {
- if ( ( y != 0 ) && ( src[k-xsize-1] > src[k] ) ) { dst[k] = 0; continue; };
- if ( ( y != ysize-1 ) && ( src[k+xsize-1] > src[k] ) ) { dst[k] = 0; continue; };
- }
- }
- if ( x != xsize-1 )
- {
- if ( src[k+1] > src[k] ) { dst[k] = 0; continue; };
- if ( useEightConnectivity ) {
- if ( ( y != 0 ) && ( src[k-xsize+1] > src[k] ) ) { dst[k] = 0; continue; };
- if ( ( y != ysize-1 ) && ( src[k+xsize+1] > src[k] ) ) { dst[k] = 0; continue; };
- }
- }
- // CHANGE THIS to dst <-> src !!
- if ( y != 0 )
- if ( src[k-xsize] > src[k] ) { dst[k] = 0; continue; };
-
- if ( y != ysize-1 )
- if ( src[k+xsize] > src[k] ) { dst[k] = 0; continue; };
- dst[k] = src[k];
- }
- }
|