MultiChannelImageT.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #ifndef _NICE_CORE_MULTICHANNELIMAGET_H
  2. #define _NICE_CORE_MULTICHANNELIMAGET_H
  3. #include "MultiChannelImageAccess.h"
  4. #include "ImageT.h"
  5. namespace NICE {
  6. /**
  7. * @class MultiChannelImageT
  8. * An image consisting of an arbitrary number of channels.
  9. *
  10. * formaly known as Generic Image
  11. *
  12. * @author Erik Rodner and Björn Fröhlich
  13. * @example notyet
  14. */
  15. template <class P>
  16. class MultiChannelImageT : public MultiChannelImageAccess {
  17. protected:
  18. typedef P Value;
  19. typedef unsigned int uint;
  20. /** image data, use carefully !!! data[channel][pixel_offset] */
  21. P **data;
  22. /** image width */
  23. int xsize;
  24. /** image height */
  25. int ysize;
  26. /** number of image channels */
  27. uint numChannels;
  28. public:
  29. virtual inline int width() const;
  30. virtual inline int height() const;
  31. virtual inline int channels() const;
  32. virtual int getPixelInt( int x, int y, int channel ) const;
  33. virtual double getPixelFloat( int x, int y, int channel ) const;
  34. virtual void setPixelInt( int x, int y, int channel, int pixel );
  35. virtual void setPixelFloat( int x, int y, int channel, double pixel );
  36. /** simple constructor */
  37. MultiChannelImageT( int xsize, int ysize, uint numChannels = 1);
  38. /** very simple constructor */
  39. MultiChannelImageT();
  40. /** copy constructor */
  41. MultiChannelImageT( const MultiChannelImageT<P>& p );
  42. /** simple destructor */
  43. virtual ~MultiChannelImageT();
  44. /** free all memory */
  45. void freeData();
  46. /** reinit */
  47. void reInit( int xsize, int ysize, int numChannels = 1);
  48. /** reinit data structure using the same dimensions and
  49. number of channels as another image */
  50. template<class SrcP>
  51. void reInitFrom( const MultiChannelImageT<SrcP> & src);
  52. void addChannel( int newChans = 1 );
  53. /** add a channel to Multichannel Image */
  54. template<class SrcP>
  55. void addChannel(const NICE::ImageT<SrcP> &newImg);
  56. template<class SrcP>
  57. void addChannel(const NICE::MultiChannelImageT<SrcP> &newImg);
  58. /** get value */
  59. P get( int x, int y, uint channel = 0 ) const;
  60. /** get data pointer */
  61. P** getDataPointer();
  62. /** set value */
  63. void set( int x, int y, P val, uint channel = 0 );
  64. /** set value */
  65. void set( P val, uint channel);
  66. /** set value */
  67. void setAll( P val );
  68. /** calc integral image */
  69. void calcIntegral( uint channel = 0 );
  70. /**
  71. * @brief calculate the integral value in the area given by upper left corner and lower right corner, including out of boundary check
  72. * @warning make sure that the given channel is an integral image
  73. * @param ulx upper left x coordinate
  74. * @param uly upper left y coordinate
  75. * @param lrx lower right x coordinate
  76. * @param lry lower right y coordinate
  77. * @param channel channel
  78. * @return P mean value of given area
  79. **/
  80. P getIntegralValue(int ulx, int uly, int lrx, int lry, int channel) const;
  81. /** convert to ice image */
  82. void convertToGrey( NICE::Image & img, uint channel = 0, bool normalize = true ) const;
  83. /** convert to ice colorimage */
  84. void convertToColor( NICE::ColorImage & img, const int chan1 = 0, const int chan2 = 1, const int chan3 = 2 ) const;
  85. /** return image for visualization */
  86. Image getChannel( uint channel = 0 ) const;
  87. /** return rgb image for visualization */
  88. ColorImage getColor() const;
  89. /** calculate image statistics */
  90. void statistics( P & min, P & max, uint channel = 0 ) const;
  91. /** dump all data to RAW format: xsize, ysize, numChannels, <data> */
  92. void store( std::string filename ) const;
  93. /** read all data from RAW format: xsize, ysize, numChannels, <data> */
  94. void restore( std::string filename );
  95. /** copy alls data to new object */
  96. MultiChannelImageT<P>& operator=( const MultiChannelImageT<P>& orig );
  97. /** element operator */
  98. P & operator() (int x, int y, uint channel = 0);
  99. /** element operator */
  100. ImageT<P> operator[] (uint c);
  101. };
  102. } // namespace
  103. #include "core/image/MultiChannelImageT.tcc"
  104. #endif