MultiChannelImage3DT.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 Multichannel Image */
  72. template<class SrcP>
  73. void addChannel( NICE::MultiChannelImageT<SrcP> &newImg );
  74. template<class SrcP>
  75. void addChannel(const NICE::MultiChannelImage3DT<SrcP> &newImg);
  76. /** add channels only as references (no deep memory copy) */
  77. template<class SrcP>
  78. void addChannelReferences(const NICE::MultiChannelImage3DT<SrcP> &newImg);
  79. /** get value */
  80. P get( int x, int y, int z, uint channel = 0 ) const;
  81. /** get data pointer */
  82. std::vector<P*> getDataPointer() const;
  83. //P** getDataPointer();
  84. /** set value */
  85. void set( int x, int y, int z, P val, uint channel = 0 );
  86. /** set value */
  87. void set( P val, uint channel = 0 );
  88. /** set value */
  89. void setAll( P val );
  90. /** calc integral image */
  91. void calcIntegral( uint channel = 0 );
  92. /**
  93. * @brief calculate the variance image map of a channel
  94. * @param srcchan source channel with raw data
  95. * @param tarchan target channel for the variance map
  96. */
  97. void calcVariance( uint srcchan = 0, uint tarchan = 1 );
  98. /**
  99. * @brief calculate the integral value in the volume given by upper left front corner and lower right back corner, including out of boundary check
  100. * @warning make sure that the given channel is an integral 3d image
  101. * @param ulfx upper left front x coordinate
  102. * @param ulfy upper left front y coordinate
  103. * @param ulfz upper left front z coordinate
  104. * @param lrbx lower right back x coordinate
  105. * @param lrby lower right back y coordinate
  106. * @param lrbz lower right back z coordinate
  107. * @param channel channel
  108. * @return P mean value of given volume
  109. **/
  110. P getIntegralValue(int ulfx, int ulfy, int ulfz, int lrbx, int lrby, int lrbz, int channel) const;
  111. /** convert to ice image */
  112. void convertToGrey( NICE::Image & img, int z, uint channel = 0, bool normalize = true ) const;
  113. /** convert to ice colorimage */
  114. void convertToColor( NICE::ColorImage & img, int z, const int chan1 = 0, const int chan2 = 1, const int chan3 = 2 ) const;
  115. /** return image for visualization */
  116. Image getChannel( int z, uint channel = 0 ) const;
  117. /** return image for visualization */
  118. ImageT<P> getChannelT( int z, uint channel = 0 ) const;
  119. /** return x-slice as image */
  120. ImageT<P> getXSlice ( int x, uint channel = 0 ) const;
  121. /** return rgb image (reading channels 0, 1, 2) for visualization */
  122. ColorImage getColor(int z) const;
  123. /** return rgb image (reading arbitrary three channels) for visualization */
  124. ColorImage getColorImageFromChannels(int z, int channel0, int channel1, int channel2) const;
  125. /** calculate image statistics */
  126. void statistics( P & min, P & max, uint channel = 0 ) const;
  127. /** correct inhomogeneous illuminations between the image slices
  128. * ! Deprecated, use 'equalizeHistogram' instead !
  129. */
  130. void correctShading( uint channel = 0 ) const;
  131. /** do a histogram equalization */
  132. void equalizeHistogram( uint channel = 0 ) const;
  133. /** dump all data to RAW format: xsize, ysize, numChannels, <data> */
  134. void store( std::string filename ) const;
  135. /** read all data from RAW format: xsize, ysize, numChannels, <data> */
  136. void restore( std::string filename );
  137. /** copy alls data to new object */
  138. MultiChannelImage3DT<P>& operator=( const MultiChannelImage3DT<P>& orig );
  139. /** element operator */
  140. P & operator() (int x, int y, int z, uint channel = 0);
  141. /** element operator */
  142. MultiChannelImageT<P> operator[] (uint c);
  143. };
  144. } // namespace
  145. #include <core/image/MultiChannelImage3DT.tcc>
  146. #endif