MultiChannelImage3DT.h 5.3 KB

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