MultiChannelImage3DT.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 gray level co-occurence matrix of a channel
  79. * @param max Co-occurence Matrix
  80. * @param dis displacement vector
  81. * @param channel channel
  82. */
  83. void calcGLCM( std::vector<std::vector<double> > & mat, const std::vector<int> dis, uint channel = 0 );
  84. /**
  85. * @brief calculate the variance image map of a channel
  86. * @param srcchan source channel with raw data
  87. * @param tarchan target channel for the variance map
  88. */
  89. void calcVariance( uint srcchan = 0, uint tarchan = 1 );
  90. /**
  91. * @brief calculate the integral value in the volume given by upper left front corner and lower right back corner, including out of boundary check
  92. * @warning make sure that the given channel is an integral 3d image
  93. * @param ulfx upper left front x coordinate
  94. * @param ulfy upper left front y coordinate
  95. * @param ulfz upper left front z coordinate
  96. * @param lrbx lower right back x coordinate
  97. * @param lrby lower right back y coordinate
  98. * @param lrbz lower right back z coordinate
  99. * @param channel channel
  100. * @return P mean value of given volume
  101. **/
  102. P getIntegralValue(int ulfx, int ulfy, int ulfz, int lrbx, int lrby, int lrbz, int channel);
  103. /** convert to ice image */
  104. void convertToGrey( NICE::Image & img, int z, uint channel = 0, bool normalize = true ) const;
  105. /** convert to ice colorimage */
  106. void convertToColor( NICE::ColorImage & img, int z, const int chan1 = 0, const int chan2 = 1, const int chan3 = 2 ) const;
  107. /** return image for visualization */
  108. Image getChannel( int z, uint channel = 0 ) const;
  109. /** return image for visualization */
  110. ImageT<P> getChannelT( int z, uint channel = 0 ) const;
  111. /** return rgb image for visualization */
  112. ColorImage getColor(int z) const;
  113. /** calculate image statistics */
  114. void statistics( P & min, P & max, uint channel = 0 ) const;
  115. /** correct inhomogeneous illuminations between the image slices
  116. * ! Deprecated, use 'equalizeHistogram' instead !
  117. */
  118. void correctShading( uint channel = 0 ) const;
  119. /** do a histogram equalization */
  120. void equalizeHistogram( uint channel = 0 ) const;
  121. /** dump all data to RAW format: xsize, ysize, numChannels, <data> */
  122. void store( std::string filename ) const;
  123. /** read all data from RAW format: xsize, ysize, numChannels, <data> */
  124. void restore( std::string filename );
  125. /** copy alls data to new object */
  126. MultiChannelImage3DT<P>& operator=( const MultiChannelImage3DT<P>& orig );
  127. /** element operator */
  128. P & operator() (int x, int y, int z, uint channel = 0);
  129. /** element operator */
  130. MultiChannelImageT<P> operator[] (uint c);
  131. };
  132. } // namespace
  133. #include <core/image/MultiChannelImage3DT.tcc>
  134. #endif