MultiChannelImage3DT.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #ifndef _NICE_CORE_MULTICHANNELIMAGE3DT_H
  2. #define _NICE_CORE_MULTICHANNELIMAGE3DT_H
  3. #include <core/image/MultiChannelImageAccess3D.h>
  4. #include <core/image/ImageT.h>
  5. #include <core/image/MultiChannelImageT.h>
  6. #include <core/image/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. P **data;
  26. /** image width */
  27. int xsize;
  28. /** image height */
  29. int ysize;
  30. /** image depth */
  31. int zsize;
  32. /** number of image channels */
  33. uint numChannels;
  34. public:
  35. virtual inline int width() const;
  36. virtual inline int height() const;
  37. virtual inline int depth() const;
  38. virtual inline int channels() const;
  39. virtual int getPixelInt( int x, int y, int z, int channel ) const;
  40. virtual double getPixelFloat( int x, int y, int z, int channel ) const;
  41. virtual void setPixelInt( int x, int y, int z, int channel, int pixel );
  42. virtual void setPixelFloat( int x, int y, int z, int channel, double pixel );
  43. /** simple constructor */
  44. MultiChannelImage3DT( int xsize, int ysize, int zsize, uint numChannels = 1);
  45. /** very simple constructor */
  46. MultiChannelImage3DT();
  47. /** copy constructor */
  48. MultiChannelImage3DT( const MultiChannelImage3DT<P>& p );
  49. /** simple destructor */
  50. virtual ~MultiChannelImage3DT();
  51. /** free all memory */
  52. void freeData();
  53. /** reinit */
  54. void reInit( int xsize, int ysize, int zsize, int numChannels = 1);
  55. /** reinit data structure using the same dimensions and
  56. number of channels as another image */
  57. template<class SrcP>
  58. void reInitFrom( const MultiChannelImage3DT<SrcP> & src);
  59. void addChannel( int newChans = 1 );
  60. /** add a channel to Multichannel Image */
  61. template<class SrcP>
  62. void addChannel( NICE::MultiChannelImageT<SrcP> &newImg );
  63. template<class SrcP>
  64. void addChannel(const NICE::MultiChannelImage3DT<SrcP> &newImg);
  65. /** get value */
  66. P get( int x, int y, int z, uint channel = 0 ) const;
  67. /** get data pointer */
  68. P** getDataPointer();
  69. /** set value */
  70. void set( int x, int y, int z, P val, uint channel = 0 );
  71. /** set value */
  72. void set( P val, uint channel = 0 );
  73. /** set value */
  74. void setAll( P val );
  75. /** calc integral image */
  76. void calcIntegral( uint channel = 0 );
  77. /**
  78. * @brief calculate the variance image map of a channel
  79. * @param srcchan source channel with raw data
  80. * @param tarchan target channel for the variance map
  81. */
  82. void calcVariance( uint srcchan = 0, uint tarchan = 1 );
  83. /**
  84. * @brief calculate the integral value in the volume given by upper left front corner and lower right back corner, including out of boundary check
  85. * @warning make sure that the given channel is an integral 3d image
  86. * @param ulfx upper left front x coordinate
  87. * @param ulfy upper left front y coordinate
  88. * @param ulfz upper left front z coordinate
  89. * @param lrbx lower right back x coordinate
  90. * @param lrby lower right back y coordinate
  91. * @param lrbz lower right back z coordinate
  92. * @param channel channel
  93. * @return P mean value of given volume
  94. **/
  95. P getIntegralValue(int ulfx, int ulfy, int ulfz, int lrbx, int lrby, int lrbz, int channel) const;
  96. /** convert to ice image */
  97. void convertToGrey( NICE::Image & img, int z, uint channel = 0, bool normalize = true ) const;
  98. /** convert to ice colorimage */
  99. void convertToColor( NICE::ColorImage & img, int z, const int chan1 = 0, const int chan2 = 1, const int chan3 = 2 ) const;
  100. /** return image for visualization */
  101. Image getChannel( int z, uint channel = 0 ) const;
  102. /** return image for visualization */
  103. ImageT<P> getChannelT( int z, uint channel = 0 ) const;
  104. /** return rgb image for visualization */
  105. ColorImage getColor(int z) const;
  106. /** calculate image statistics */
  107. void statistics( P & min, P & max, uint channel = 0 ) const;
  108. /** correct inhomogeneous illuminations between the image slices
  109. * ! Deprecated, use 'equalizeHistogram' instead !
  110. */
  111. void correctShading( uint channel = 0 ) const;
  112. /** do a histogram equalization */
  113. void equalizeHistogram( uint channel = 0 ) const;
  114. /** dump all data to RAW format: xsize, ysize, numChannels, <data> */
  115. void store( std::string filename ) const;
  116. /** read all data from RAW format: xsize, ysize, numChannels, <data> */
  117. void restore( std::string filename );
  118. /** copy alls data to new object */
  119. MultiChannelImage3DT<P>& operator=( const MultiChannelImage3DT<P>& orig );
  120. /** element operator */
  121. P & operator() (int x, int y, int z, uint channel = 0);
  122. /** element operator */
  123. MultiChannelImageT<P> operator[] (uint c);
  124. };
  125. } // namespace
  126. #include <core/image/MultiChannelImage3DT.tcc>
  127. #endif