GenericImageTools.tcc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * @file GenericImageTools.cpp
  3. * @brief simple filter stuff
  4. * @author Erik Rodner
  5. * @date 07/30/2008
  6. */
  7. #include <iostream>
  8. #include "GenericImageTools.h"
  9. template <class PixelValueDst, class PixelValueSrc>
  10. void GenericImageTools::calcIntegralImage ( NICE::ImageT<PixelValueDst> &integralImage, const NICE::ImageT<PixelValueSrc> &image, int xsize, int ysize )
  11. {
  12. integralImage ( 0, 0 ) = ( PixelValueDst ) image ( 0, 0 );;
  13. for ( int y = 0 ; y < (ysize - 1); ++y )
  14. integralImage ( 0, y + 1) = integralImage ( 0, y) + image ( 0, y);
  15. for ( int x = 0 ; x < (xsize - 1); ++x )
  16. integralImage ( x + 1, 0 ) = integralImage ( x, 0 ) + image ( x, 0 );
  17. for ( int y = 1 ; y < ysize ; y++ )
  18. for ( int x = 1 ; x < xsize ; x++ )
  19. {
  20. integralImage ( x, y ) = ( PixelValueDst ) image ( x, y );
  21. integralImage ( x, y ) += integralImage ( x, y - 1 );
  22. integralImage ( x, y ) += integralImage ( x - 1, y );
  23. integralImage ( x, y ) -= integralImage ( x - 1, y - 1 );
  24. }
  25. }
  26. template <class PixelValueDst, class PixelValueSrc>
  27. void GenericImageTools::nonMaximumSuppression ( NICE::ImageT<PixelValueDst> &dst, const NICE::ImageT<PixelValueSrc> &src, int xsize, int ysize, bool useEightConnectivity )
  28. {
  29. for ( int y = 0 ; y < ysize ; y++ )
  30. for ( int x = 0 ; x < xsize ; x++ )
  31. {
  32. if ( x != 0 )
  33. {
  34. if ( src ( x - 1, y ) > src ( x, y ) ) {
  35. dst ( x, y ) = 0;
  36. continue;
  37. };
  38. if ( useEightConnectivity ) {
  39. if ( ( y != 0 ) && ( src ( x, y - 1 ) > src ( x, y ) ) ) {
  40. dst ( x, y ) = 0;
  41. continue;
  42. };
  43. if ( ( y != ysize - 1 ) && ( src ( x - 1, y + 1 ) > src ( x, y ) ) ) {
  44. dst ( x, y ) = 0;
  45. continue;
  46. };
  47. }
  48. }
  49. if ( x != xsize - 1 )
  50. {
  51. if ( src ( x + 1, y ) > src ( x, y ) ) {
  52. dst ( x, y ) = 0;
  53. continue;
  54. };
  55. if ( useEightConnectivity ) {
  56. if ( ( y != 0 ) && ( src ( x + 1, y - 1 ) > src ( x, y ) ) ) {
  57. dst ( x, y ) = 0;
  58. continue;
  59. };
  60. if ( ( y != ysize - 1 ) && ( src ( x + 1, y + 1 ) > src ( x, y ) ) ) {
  61. dst ( x, y ) = 0;
  62. continue;
  63. };
  64. }
  65. }
  66. // CHANGE THIS to dst <-> src !!
  67. if ( y != 0 )
  68. if ( src ( x, y - 1 ) > src ( x, y ) ) {
  69. dst ( x, y ) = 0;
  70. continue;
  71. };
  72. if ( y != ysize - 1 )
  73. if ( src ( x, y + 1 ) > src ( x, y ) ) {
  74. dst ( x, y ) = 0;
  75. continue;
  76. };
  77. dst ( x, y ) = src ( x, y );
  78. }
  79. }