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://www.centreleonberard.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 clitkDecomposeAndReconstructGenericFilter_txx
19 #define clitkDecomposeAndReconstructGenericFilter_txx
24 //-------------------------------------------------------------------
25 // Update with the number of dimensions
26 //-------------------------------------------------------------------
27 template<unsigned int Dimension>
29 DecomposeAndReconstructGenericFilter::UpdateWithDim(std::string PixelType)
31 if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<"..."<<std::endl;
33 if(PixelType == "short"){
34 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
35 UpdateWithDimAndPixelType<Dimension, signed short>();
37 // else if(PixelType == "unsigned_short"){
38 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
39 // UpdateWithDimAndPixelType<Dimension, unsigned short>();
42 else if (PixelType == "unsigned_char"){
43 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
44 std::cout << "WARNING: Working in unsigned pixelType, remember to set the Erosion Padding Value to a suitable value!"<< std::endl;
45 UpdateWithDimAndPixelType<Dimension, unsigned char>();
49 // else if (PixelType == "char"){
50 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
51 // UpdateWithDimAndPixelType<Dimension, signed char>();
54 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
55 UpdateWithDimAndPixelType<Dimension, float>();
60 //-------------------------------------------------------------------
61 // Update with the number of dimensions and the pixeltype
62 //-------------------------------------------------------------------
63 template <unsigned int Dimension, class PixelType>
65 DecomposeAndReconstructGenericFilter::UpdateWithDimAndPixelType()
69 typedef itk::Image<PixelType, Dimension> InputImageType;
70 typedef itk::Image<int, Dimension> InternalImageType;
71 typedef itk::Image<PixelType, Dimension> OutputImageType;
74 typedef itk::ImageFileReader<InputImageType> InputReaderType;
75 typename InputReaderType::Pointer reader = InputReaderType::New();
76 reader->SetFileName( m_InputFileName);
78 typename InputImageType::Pointer input= reader->GetOutput();
80 // Structuring element radius
81 typename InputImageType::SizeType radius;
82 if (m_ArgsInfo.radius_given==Dimension)
83 for (unsigned int i=0;i<Dimension;i++)
84 {radius[i]=m_ArgsInfo.radius_arg[i];}
86 for (unsigned int i=0;i<Dimension;i++)
87 radius[i]=m_ArgsInfo.radius_arg[0];
90 typedef itk::CastImageFilter<InputImageType, InternalImageType> InputCastImageFilterType;
91 typename InputCastImageFilterType::Pointer inputCaster= InputCastImageFilterType::New();
92 inputCaster->SetInput(input);
93 inputCaster->Update();
96 typedef itk::ImageToImageFilter<InternalImageType, InternalImageType> ImageToImageFilterType;
97 typename ImageToImageFilterType::Pointer filter;
99 switch (m_ArgsInfo.type_arg)
103 typedef clitk::DecomposeThroughErosionImageFilter<InternalImageType,InternalImageType> FilterType;
104 typename FilterType::Pointer f=FilterType::New();
105 f->SetVerbose(m_Verbose);
106 f->SetFullyConnected(m_ArgsInfo.full_flag);
107 f->SetErosionPaddingValue(m_ArgsInfo.pad_arg);
108 f->SetMinimumNumberOfIterations(m_ArgsInfo.min_arg);
109 f->SetMinimumObjectSize(m_ArgsInfo.minSize_arg);
110 f->SetRadius(radius);
111 f->SetNumberOfNewLabels(m_ArgsInfo.new_arg);
112 if(m_Verbose) std::cout<<"Using the DecomposeThroughErosionImageFilter..."<<std::endl;
119 typedef clitk::ReconstructThroughDilationImageFilter<InternalImageType,InternalImageType> FilterType;
120 typename FilterType::Pointer f=FilterType::New();
121 f->SetVerbose(m_Verbose);
122 f->SetErosionPaddingValue(m_ArgsInfo.pad_arg);
123 f->SetRadius(radius);
124 f->SetMaximumNumberOfLabels(m_ArgsInfo.max_arg);
125 f->SetBackgroundValue(m_ArgsInfo.bg_arg);
126 f->SetForegroundValue(m_ArgsInfo.fg_arg);
127 if(m_Verbose) std::cout<<"Using the ReconstructThroughDilationImageFilter..."<<std::endl;
133 typedef clitk::DecomposeAndReconstructImageFilter<InternalImageType,InternalImageType> FilterType;
134 typename FilterType::Pointer f=FilterType::New();
135 f->SetVerbose(m_Verbose);
136 f->SetRadius(radius);
137 f->SetMaximumNumberOfLabels(m_ArgsInfo.max_arg);
138 f->SetMinimumNumberOfIterations(m_ArgsInfo.min_arg);
139 f->SetBackgroundValue(m_ArgsInfo.bg_arg);
140 f->SetForegroundValue(m_ArgsInfo.fg_arg);
141 f->SetFullyConnected(m_ArgsInfo.full_flag);
142 f->SetNumberOfNewLabels(m_ArgsInfo.new_arg);
143 f->SetMinimumObjectSize(m_ArgsInfo.minSize_arg);
144 if(m_Verbose) std::cout<<"Using the DecomposeAndReconstructImageFilter..."<<std::endl;
150 filter->SetInput(inputCaster->GetOutput());
152 typename InternalImageType::Pointer output= filter->GetOutput();
155 typedef itk::CastImageFilter<InternalImageType, OutputImageType> OutputCastImageFilterType;
156 typename OutputCastImageFilterType::Pointer outputCaster= OutputCastImageFilterType::New();
157 outputCaster->SetInput(output);
158 outputCaster->Update();
161 typedef itk::ImageFileWriter<OutputImageType> WriterType;
162 typename WriterType::Pointer writer = WriterType::New();
163 writer->SetFileName(m_ArgsInfo.output_arg);
164 writer->SetInput(outputCaster->GetOutput());
172 #endif //#define clitkDecomposeAndReconstructGenericFilter_txx