]> Creatis software - clitk.git/blob - common/clitkImageCommon.h
changes in license header
[clitk.git] / common / clitkImageCommon.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef CLITKIMAGECOMMON_H
19 #define CLITKIMAGECOMMON_H
20
21 // clitk
22 //#include "clitkCommon.h"
23
24 // itk
25 #include "itkImage.h"
26 #include "itkImageFileReader.h"
27 #include "itkImageSeriesReader.h"
28 #include "itkImageFileWriter.h"
29 #include "gdcmFile.h"
30 #if GDCM_MAJOR_VERSION == 2
31   #include "gdcmReader.h"
32 #else
33   #include "gdcmFileHelper.h"
34 #endif
35
36 namespace clitk {
37   
38   //--------------------------------------------------------------------
39   // New Image creation (no allocation)
40   template<class PixelType>
41   typename itk::Image<PixelType,1>::Pointer NewImage1D(int size, double spacing=1.0);
42   template<class PixelType>
43   typename itk::Image<PixelType,2>::Pointer NewImage2D(int sx, int sy, double dx=1.0, double dy=1.0);
44   template<class PixelType>
45   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);
46   template<class PixelType>
47   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);
48
49   template<class ImageType>
50   typename ImageType::Pointer NewImageLike(const typename ImageType::Pointer input, bool allocate=true);
51
52   template<class ImageType>
53   void CopyValues(const typename ImageType::Pointer input, typename ImageType::Pointer output);
54   //--------------------------------------------------------------------
55   // New Image creation (with allocation)
56
57   //--------------------------------------------------------------------
58   // Read an Write image
59   // template<class ImageType>
60   //   typename ImageType::Pointer ReadImage(const std::string & filename, const bool verbose=false);
61   template<typename ImageType>
62   typename ImageType::Pointer readImage(const std::string & filename, const bool verbose=false);  
63   template<typename ImageType>
64   typename ImageType::Pointer readImage(const std::vector<std::string> & filenames, const bool verbose=false);
65   template<class ImageType>
66   void writeImage(const typename ImageType::Pointer image, const std::string & filename, const bool verbose=false);
67 //   template<class ImageType>  
68 //   void writeConstImage(const typename ImageType::ConstPointer image, const std::string & filename, const bool verbose=false);
69   template<class ImageType>  
70   void writeImage(const ImageType* image, const std::string & filename, const bool verbose=false);
71
72   //--------------------------------------------------------------------
73   // Read/print image header
74   itk::ImageIOBase::Pointer readImageHeader(const std::string & filename,bool exit_on_error=true);
75   void printImageHeader(itk::ImageIOBase::Pointer header, std::ostream & os, const int level=0);
76
77   //--------------------------------------------------------------------
78   // Determine pixetype and dimension of an image file
79   void ReadImageDimensionAndPixelType(const std::string & filename, int & dimension, std::string & pixeType);
80
81   //--------------------------------------------------------------------
82   // Determine pixetype, dimension and number of pixel components  of an image file
83   void ReadImageDimensionAndPixelType(const std::string & filename, int & dimension, std::string & pixeType, int & components);
84
85   //--------------------------------------------------------------------
86   // Read a dicom header  
87   gdcm::File * readDicomHeader(const std::string & filename, const bool verbose=false);
88
89   //--------------------------------------------------------------------
90   template<class ImageType>
91   int ComputeHowManyDifferentIntensity(const typename ImageType::Pointer & image, 
92                                        std::vector<typename ImageType::PixelType> & listOfIntensities);
93   template<class InputImageType, class MaskImageType>
94   void ComputeWeightsOfEachClasses(const typename InputImageType::Pointer & input, 
95                                    const typename MaskImageType::Pointer & mask,
96                                    const std::vector<typename MaskImageType::PixelType> & listOfIntensities, 
97                                    std::map<typename MaskImageType::PixelType, 
98                                    std::map<typename InputImageType::PixelType, double> > & mapOfLabelsAndWeights);
99
100   //--------------------------------------------------------------------
101   template<class ImageType1, class ImageType2>
102   bool HaveSameSizeAndSpacing(typename ImageType1::ConstPointer A, 
103                              typename ImageType2::ConstPointer B);
104
105   template<class ImageType1, class ImageType2>
106   bool HaveSameSizeAndSpacing(typename ImageType1::Pointer A, 
107                              typename ImageType2::Pointer B);
108
109   //--------------------------------------------------------------------
110   template<class ImageType1, class ImageType2>
111   bool HaveSameSpacing(typename ImageType1::ConstPointer A, 
112                        typename ImageType2::ConstPointer B);
113
114   template<class ImageType1, class ImageType2>
115   bool HaveSameSpacing(typename ImageType1::Pointer A, 
116                        typename ImageType2::Pointer B);
117
118 #include "clitkImageCommon.txx"
119
120 } // end namespace
121
122 #endif /* end #define CLITKIMAGECOMMON_H */
123