1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
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
22 #include "clitkCommon.h"
26 #include "itkImageFileReader.h"
27 #include "itkImageSeriesReader.h"
28 #include "itkImageFileWriter.h"
30 #include "gdcmFileHelper.h"
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);
45 template<class ImageType>
46 typename ImageType::Pointer NewImageLike(const typename ImageType::Pointer input, bool allocate=true);
48 template<class ImageType>
49 void CopyValues(const typename ImageType::Pointer input, typename ImageType::Pointer output);
50 //--------------------------------------------------------------------
51 // New Image creation (with allocation)
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);
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);
73 //--------------------------------------------------------------------
74 // Determine pixetype and dimension of an image file
75 void ReadImageDimensionAndPixelType(const std::string & filename, int & dimension, std::string & pixeType);
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);
81 //--------------------------------------------------------------------
82 // Read a dicom header
83 gdcm::File * readDicomHeader(const std::string & filename, const bool verbose=false);
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);
96 //--------------------------------------------------------------------
97 template<class ImageType1, class ImageType2>
98 bool HaveSameSizeAndSpacing(typename ImageType1::ConstPointer A,
99 typename ImageType2::ConstPointer B);
101 template<class ImageType1, class ImageType2>
102 bool HaveSameSizeAndSpacing(typename ImageType1::Pointer A,
103 typename ImageType2::Pointer B);
105 //--------------------------------------------------------------------
106 template<class ImageType1, class ImageType2>
107 bool HaveSameSpacing(typename ImageType1::ConstPointer A,
108 typename ImageType2::ConstPointer B);
110 template<class ImageType1, class ImageType2>
111 bool HaveSameSpacing(typename ImageType1::Pointer A,
112 typename ImageType2::Pointer B);
114 #include "clitkImageCommon.txx"
118 #endif /* end #define CLITKIMAGECOMMON_H */