]> Creatis software - clitk.git/blob - common/clitkImageCommon.h
11ddaba67441645957ac8f1aa2aa4e13917626fc
[clitk.git] / common / clitkImageCommon.h
1 #ifndef CLITKIMAGECOMMON_H
2 #define CLITKIMAGECOMMON_H
3 /**
4  -------------------------------------------------------------------
5  * @file   clitkImageCommon.h
6  * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
7  * @date   07 Sep 2007 11:30:10
8
9  * @brief  
10
11  -------------------------------------------------------------------*/
12
13 // clitk
14 #include "clitkCommon.h"
15
16 // itk
17 #include "itkImage.h"
18 #include "itkImageFileReader.h"
19 #include "itkImageSeriesReader.h"
20 #include "itkImageFileWriter.h"
21 #include "gdcmFile.h"
22 #include "gdcmFileHelper.h"
23
24
25 namespace clitk {
26   
27   //--------------------------------------------------------------------
28   // New Image creation (no allocation)
29   template<class PixelType>
30   typename itk::Image<PixelType,1>::Pointer NewImage1D(int size, double spacing=1.0);
31   template<class PixelType>
32   typename itk::Image<PixelType,2>::Pointer NewImage2D(int sx, int sy, double dx=1.0, double dy=1.0);
33   template<class PixelType>
34   typename itk::Image<PixelType,3>::Pointer NewImage3D(int sx, int sy, int sz, double dx=1.0, double dy=1.0, double dz=1.0);
35   template<class PixelType>
36   typename itk::Image<PixelType,4>::Pointer NewImage4D(int sx, int sy, int sz, int st, double dx=1.0, double dy=1.0, double dz=1.0, double dt=1.0);
37
38   //--------------------------------------------------------------------
39   // New Image creation (with allocation)
40
41   //--------------------------------------------------------------------
42   // Read an Write image
43   // template<class ImageType>
44   //   typename ImageType::Pointer ReadImage(const std::string & filename, const bool verbose=false);
45   template<typename ImageType>
46   typename ImageType::Pointer readImage(const std::string & filename, const bool verbose=false);  
47   template<typename ImageType>
48   typename ImageType::Pointer readImage(const std::vector<std::string> & filenames, const bool verbose=false);
49   template<class ImageType>
50   void writeImage(const typename ImageType::Pointer image, const std::string & filename, const bool verbose=false);
51 //   template<class ImageType>  
52 //   void writeConstImage(const typename ImageType::ConstPointer image, const std::string & filename, const bool verbose=false);
53   template<class ImageType>  
54   void writeImage(const ImageType* image, const std::string & filename, const bool verbose=false);
55
56   //--------------------------------------------------------------------
57   // Read/print image header
58   itk::ImageIOBase::Pointer readImageHeader(const std::string & filename,bool exit_on_error=true);
59   void printImageHeader(itk::ImageIOBase::Pointer header, std::ostream & os, const int level=0);
60
61   //--------------------------------------------------------------------
62   // Determine pixetype and dimension of an image file
63   void ReadImageDimensionAndPixelType(const std::string & filename, int & dimension, std::string & pixeType);
64
65   //--------------------------------------------------------------------
66   // Determine pixetype, dimension and number of pixel components  of an image file
67   void ReadImageDimensionAndPixelType(const std::string & filename, int & dimension, std::string & pixeType, int & components);
68
69   //--------------------------------------------------------------------
70   // Read a dicom header  
71   gdcm::File * readDicomHeader(const std::string & filename, const bool verbose=false);
72
73   //--------------------------------------------------------------------
74   template<class ImageType>
75   int ComputeHowManyDifferentIntensity(const typename ImageType::Pointer & image, 
76                                        std::vector<typename ImageType::PixelType> & listOfIntensities);
77   template<class InputImageType, class MaskImageType>
78   void ComputeWeightsOfEachClasses(const typename InputImageType::Pointer & input, 
79                                    const typename MaskImageType::Pointer & mask,
80                                    const std::vector<typename MaskImageType::PixelType> & listOfIntensities, 
81                                    std::map<typename MaskImageType::PixelType, 
82                                    std::map<typename InputImageType::PixelType, double> > & mapOfLabelsAndWeights);
83
84 #include "clitkImageCommon.txx"
85
86 } // end namespace
87
88 #endif /* end #define CLITKIMAGECOMMON_H */
89