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