]> Creatis software - clitk.git/blob - common/clitkImageCommon.h
9744fc962cc666a4c156f90e56be41628c7191ec
[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://oncora1.lyon.fnclcc.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 #include "gdcmFileHelper.h"
31
32 namespace clitk {
33   
34   //--------------------------------------------------------------------
35   // New Image creation (no allocation)
36   template<class PixelType>
37   typename itk::Image<PixelType,1>::Pointer NewImage1D(int size, double spacing=1.0);
38   template<class PixelType>
39   typename itk::Image<PixelType,2>::Pointer NewImage2D(int sx, int sy, double dx=1.0, double dy=1.0);
40   template<class PixelType>
41   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);
42   template<class PixelType>
43   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);
44
45   template<class ImageType>
46   typename ImageType::Pointer NewImageLike(const typename ImageType::Pointer input, bool allocate=true);
47
48   template<class ImageType>
49   void CopyValues(const typename ImageType::Pointer input, typename ImageType::Pointer output);
50   //--------------------------------------------------------------------
51   // New Image creation (with allocation)
52
53   //--------------------------------------------------------------------
54   // Read an Write image
55   // template<class ImageType>
56   //   typename ImageType::Pointer ReadImage(const std::string & filename, const bool verbose=false);
57   template<typename ImageType>
58   typename ImageType::Pointer readImage(const std::string & filename, const bool verbose=false);  
59   template<typename ImageType>
60   typename ImageType::Pointer readImage(const std::vector<std::string> & filenames, const bool verbose=false);
61   template<class ImageType>
62   void writeImage(const typename ImageType::Pointer image, const std::string & filename, const bool verbose=false);
63 //   template<class ImageType>  
64 //   void writeConstImage(const typename ImageType::ConstPointer image, const std::string & filename, const bool verbose=false);
65   template<class ImageType>  
66   void writeImage(const ImageType* image, const std::string & filename, const bool verbose=false);
67
68   //--------------------------------------------------------------------
69   // Read/print image header
70   itk::ImageIOBase::Pointer readImageHeader(const std::string & filename,bool exit_on_error=true);
71   void printImageHeader(itk::ImageIOBase::Pointer header, std::ostream & os, const int level=0);
72
73   //--------------------------------------------------------------------
74   // Determine pixetype and dimension of an image file
75   void ReadImageDimensionAndPixelType(const std::string & filename, int & dimension, std::string & pixeType);
76
77   //--------------------------------------------------------------------
78   // Determine pixetype, dimension and number of pixel components  of an image file
79   void ReadImageDimensionAndPixelType(const std::string & filename, int & dimension, std::string & pixeType, int & components);
80
81   //--------------------------------------------------------------------
82   // Read a dicom header  
83   gdcm::File * readDicomHeader(const std::string & filename, const bool verbose=false);
84
85   //--------------------------------------------------------------------
86   template<class ImageType>
87   int ComputeHowManyDifferentIntensity(const typename ImageType::Pointer & image, 
88                                        std::vector<typename ImageType::PixelType> & listOfIntensities);
89   template<class InputImageType, class MaskImageType>
90   void ComputeWeightsOfEachClasses(const typename InputImageType::Pointer & input, 
91                                    const typename MaskImageType::Pointer & mask,
92                                    const std::vector<typename MaskImageType::PixelType> & listOfIntensities, 
93                                    std::map<typename MaskImageType::PixelType, 
94                                    std::map<typename InputImageType::PixelType, double> > & mapOfLabelsAndWeights);
95
96   //--------------------------------------------------------------------
97   template<class ImageType1, class ImageType2>
98   bool HaveSameSizeAndSpacing(typename ImageType1::ConstPointer A, 
99                              typename ImageType2::ConstPointer B);
100
101   template<class ImageType1, class ImageType2>
102   bool HaveSameSizeAndSpacing(typename ImageType1::Pointer A, 
103                              typename ImageType2::Pointer B);
104
105   //--------------------------------------------------------------------
106   template<class ImageType1, class ImageType2>
107   bool HaveSameSpacing(typename ImageType1::ConstPointer A, 
108                        typename ImageType2::ConstPointer B);
109
110   template<class ImageType1, class ImageType2>
111   bool HaveSameSpacing(typename ImageType1::Pointer A, 
112                        typename ImageType2::Pointer B);
113
114 #include "clitkImageCommon.txx"
115
116 } // end namespace
117
118 #endif /* end #define CLITKIMAGECOMMON_H */
119