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