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