MultiChannelImage3DT.h 4.6 KB

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