MultiChannelImage3DT.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #ifndef _NICE_CORE_MULTICHANNELIMAGE3DT_H
  2. #define _NICE_CORE_MULTICHANNELIMAGE3DT_H
  3. #include "MultiChannelImageAccess3D.h"
  4. #include "ImageT.h"
  5. #include "MultiChannelImageT.h"
  6. #include "Histogram.h"
  7. #include <vector>
  8. #include <fstream>
  9. namespace NICE {
  10. /**
  11. * @class MultiChannelImage3DT
  12. * A 3d image (arbitrary number of cross section images) consisting of an arbitrary number of channels.
  13. *
  14. * formaly known as Generic Image
  15. *
  16. * @author Björn Fröhlich and Sven Sickert
  17. * @example notyet
  18. */
  19. template <class P>
  20. class MultiChannelImage3DT : public MultiChannelImageAccess3D {
  21. protected:
  22. typedef P Value;
  23. typedef unsigned int uint;
  24. /** image data, use carefully !!! data[channel][pixel_offset] */
  25. std::vector<P*> data;
  26. // P **data;
  27. /** image width */
  28. int xsize;
  29. /** image height */
  30. int ysize;
  31. /** image depth */
  32. int zsize;
  33. /** number of image channels */
  34. uint numChannels;
  35. public:
  36. virtual inline int width() const;
  37. virtual inline int height() const;
  38. virtual inline int depth() const;
  39. virtual inline int channels() const;
  40. virtual int getPixelInt( int x, int y, int z, int channel ) const;
  41. virtual double getPixelFloat( int x, int y, int z, int channel ) const;
  42. virtual void setPixelInt( int x, int y, int z, int channel, int pixel );
  43. virtual void setPixelFloat( int x, int y, int z, int channel, double pixel );
  44. /** simple constructor */
  45. MultiChannelImage3DT( int xsize, int ysize, int zsize, uint numChannels = 1);
  46. /** very simple constructor */
  47. MultiChannelImage3DT();
  48. /** copy constructor */
  49. MultiChannelImage3DT( const MultiChannelImage3DT<P>& p );
  50. /** simple destructor */
  51. virtual ~MultiChannelImage3DT();
  52. /** free all memory */
  53. void freeData();
  54. /**
  55. * @brief free only the pointer to the actual data, but leaves the actual data in the memory.
  56. *
  57. * Usefull for when the underlying data (e.g data[0] ptrs are passed to an other multi channel
  58. * image for further use and memcopy should be avoided.
  59. * Detail: Only frees variable 'data', not the memory data[0:numChannels] is pointing to
  60. * @author Johannes Ruehle
  61. * @date 2014-07-18
  62. */
  63. void freeShallowData();
  64. /** reinit */
  65. void reInit( int xsize, int ysize, int zsize, int numChannels = 1);
  66. /** reinit data structure using the same dimensions and
  67. number of channels as another image */
  68. template<class SrcP>
  69. void reInitFrom( const MultiChannelImage3DT<SrcP> & src);
  70. void addChannel( int newChans = 1 );
  71. /** add a channel to Image */
  72. template<class SrcP>
  73. void addChannel(const NICE::ImageT<SrcP> &newImg );
  74. /** add a channel to Multichannel Image */
  75. template<class SrcP>
  76. void addChannel(const NICE::MultiChannelImageT<SrcP> &newImg );
  77. template<class SrcP>
  78. void addChannel(const NICE::MultiChannelImage3DT<SrcP> &newImg);
  79. /** add channels only as references (no deep memory copy) */
  80. template<class SrcP>
  81. void addChannelReferences(const NICE::MultiChannelImage3DT<SrcP> &newImg);
  82. /** get value */
  83. P get( int x, int y, int z, uint channel = 0 ) const;
  84. /** get data pointer */
  85. std::vector<P*> getDataPointer() const;
  86. //P** getDataPointer();
  87. /** set value */
  88. void set( int x, int y, int z, P val, uint channel = 0 );
  89. /** set value */
  90. void set( P val, uint channel = 0 );
  91. /** set value */
  92. void setAll( P val );
  93. /** calc integral image */
  94. void calcIntegral( uint channel = 0 );
  95. /**
  96. * @brief calculate the variance image map of a channel
  97. * @param srcchan source channel with raw data
  98. * @param tarchan target channel for the variance map
  99. */
  100. void calcVariance( uint srcchan = 0, uint tarchan = 1 );
  101. /**
  102. * @brief calculate the integral value in the volume given by upper left front corner and lower right back corner, including out of boundary check
  103. * @warning make sure that the given channel is an integral 3d image
  104. * @param ulfx upper left front x coordinate
  105. * @param ulfy upper left front y coordinate
  106. * @param ulfz upper left front z coordinate
  107. * @param lrbx lower right back x coordinate
  108. * @param lrby lower right back y coordinate
  109. * @param lrbz lower right back z coordinate
  110. * @param channel channel
  111. * @return P mean value of given volume
  112. **/
  113. P getIntegralValue(int ulfx, int ulfy, int ulfz, int lrbx, int lrby, int lrbz, int channel) const;
  114. /** convert to ice image */
  115. void convertToGrey( NICE::Image & img, int z, uint channel = 0, bool normalize = true ) const;
  116. /** convert to ice colorimage */
  117. void convertToColor( NICE::ColorImage & img, int z, const int chan1 = 0, const int chan2 = 1, const int chan3 = 2 ) const;
  118. /** return image for visualization */
  119. Image getChannel( int z, uint channel = 0 ) const;
  120. /** return image for visualization */
  121. ImageT<P> getChannelT( int z, uint channel = 0 ) const;
  122. /** return x-slice as image */
  123. ImageT<P> getXSlice ( int x, uint channel = 0 ) const;
  124. /** return rgb image (reading channels 0, 1, 2) as MultiChannelImageT */
  125. MultiChannelImageT<P> getColorMCI(int z) const;
  126. /** return rgb image (reading channels 0, 1, 2) for visualization */
  127. ColorImage getColor(int z) const;
  128. /** return rgb image (reading arbitrary three channels) for visualization */
  129. ColorImage getColorImageFromChannels(int z, int channel0, int channel1, int channel2) const;
  130. /** calculate image statistics */
  131. void statistics( P & min, P & max, uint channel = 0 ) const;
  132. /** correct inhomogeneous illuminations between the image slices
  133. * ! Deprecated, use 'equalizeHistogram' instead !
  134. */
  135. void correctShading( uint channel = 0 ) const;
  136. /** do a histogram equalization */
  137. void equalizeHistogram( uint channel = 0 ) const;
  138. /** dump all data to RAW format: xsize, ysize, numChannels, <data> */
  139. void store( std::string filename ) const;
  140. /** read all data from RAW format: xsize, ysize, numChannels, <data> */
  141. void restore( std::string filename );
  142. /** copy alls data to new object */
  143. MultiChannelImage3DT<P>& operator=( const MultiChannelImage3DT<P>& orig );
  144. /** element operator */
  145. P & operator() (int x, int y, int z, uint channel = 0);
  146. /** element operator */
  147. MultiChannelImageT<P> operator[] (uint c);
  148. };
  149. } // namespace
  150. #include "MultiChannelImage3DT.tcc"
  151. #endif