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 clitkDecomposeAndReconstructGenericFilter_txx
19 #define clitkDecomposeAndReconstructGenericFilter_txx
21 /* =================================================
22 * @file clitkDecomposeAndReconstructGenericFilter.txx
28 ===================================================*/
34 //-------------------------------------------------------------------
35 // Update with the number of dimensions
36 //-------------------------------------------------------------------
37 template<unsigned int Dimension>
39 DecomposeAndReconstructGenericFilter::UpdateWithDim(std::string PixelType)
41 if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<"..."<<std::endl;
43 if(PixelType == "short"){
44 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
45 UpdateWithDimAndPixelType<Dimension, signed short>();
47 // else if(PixelType == "unsigned_short"){
48 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
49 // UpdateWithDimAndPixelType<Dimension, unsigned short>();
52 else if (PixelType == "unsigned_char"){
53 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
54 std::cout << "WARNING: Working in unsigned pixelType, remember to set the Erosion Padding Value to a suitable value!"<< std::endl;
55 UpdateWithDimAndPixelType<Dimension, unsigned char>();
59 // else if (PixelType == "char"){
60 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
61 // UpdateWithDimAndPixelType<Dimension, signed char>();
64 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
65 UpdateWithDimAndPixelType<Dimension, float>();
70 //-------------------------------------------------------------------
71 // Update with the number of dimensions and the pixeltype
72 //-------------------------------------------------------------------
73 template <unsigned int Dimension, class PixelType>
75 DecomposeAndReconstructGenericFilter::UpdateWithDimAndPixelType()
79 typedef itk::Image<PixelType, Dimension> InputImageType;
80 typedef itk::Image<int, Dimension> InternalImageType;
81 typedef itk::Image<PixelType, Dimension> OutputImageType;
84 typedef itk::ImageFileReader<InputImageType> InputReaderType;
85 typename InputReaderType::Pointer reader = InputReaderType::New();
86 reader->SetFileName( m_InputFileName);
88 typename InputImageType::Pointer input= reader->GetOutput();
90 // Structuring element radius
91 typename InputImageType::SizeType radius;
92 if (m_ArgsInfo.radius_given==Dimension)
93 for (unsigned int i=0;i<Dimension;i++)
94 {radius[i]=m_ArgsInfo.radius_arg[i];}
96 for (unsigned int i=0;i<Dimension;i++)
97 radius[i]=m_ArgsInfo.radius_arg[0];
100 typedef itk::CastImageFilter<InputImageType, InternalImageType> InputCastImageFilterType;
101 typename InputCastImageFilterType::Pointer inputCaster= InputCastImageFilterType::New();
102 inputCaster->SetInput(input);
103 inputCaster->Update();
106 typedef itk::ImageToImageFilter<InternalImageType, InternalImageType> ImageToImageFilterType;
107 typename ImageToImageFilterType::Pointer filter;
109 switch (m_ArgsInfo.type_arg)
113 typedef clitk::DecomposeThroughErosionImageFilter<InternalImageType,InternalImageType> FilterType;
114 typename FilterType::Pointer f=FilterType::New();
115 f->SetVerbose(m_Verbose);
116 f->SetFullyConnected(m_ArgsInfo.full_flag);
117 f->SetErosionPaddingValue(m_ArgsInfo.pad_arg);
118 f->SetMinimumNumberOfIterations(m_ArgsInfo.min_arg);
119 f->SetMinimumObjectSize(m_ArgsInfo.minSize_arg);
120 f->SetRadius(radius);
121 f->SetNumberOfNewLabels(m_ArgsInfo.new_arg);
122 if(m_Verbose) std::cout<<"Using the DecomposeThroughErosionImageFilter..."<<std::endl;
129 typedef clitk::ReconstructThroughDilationImageFilter<InternalImageType,InternalImageType> FilterType;
130 typename FilterType::Pointer f=FilterType::New();
131 f->SetVerbose(m_Verbose);
132 f->SetErosionPaddingValue(m_ArgsInfo.pad_arg);
133 f->SetRadius(radius);
134 f->SetMaximumNumberOfLabels(m_ArgsInfo.max_arg);
135 f->SetBackgroundValue(m_ArgsInfo.bg_arg);
136 f->SetForegroundValue(m_ArgsInfo.fg_arg);
137 if(m_Verbose) std::cout<<"Using the ReconstructThroughDilationImageFilter..."<<std::endl;
143 typedef clitk::DecomposeAndReconstructImageFilter<InternalImageType,InternalImageType> FilterType;
144 typename FilterType::Pointer f=FilterType::New();
145 f->SetVerbose(m_Verbose);
146 f->SetRadius(radius);
147 f->SetMaximumNumberOfLabels(m_ArgsInfo.max_arg);
148 f->SetMinimumNumberOfIterations(m_ArgsInfo.min_arg);
149 f->SetBackgroundValue(m_ArgsInfo.bg_arg);
150 f->SetForegroundValue(m_ArgsInfo.fg_arg);
151 f->SetFullyConnected(m_ArgsInfo.full_flag);
152 f->SetNumberOfNewLabels(m_ArgsInfo.new_arg);
153 f->SetMinimumObjectSize(m_ArgsInfo.minSize_arg);
154 if(m_Verbose) std::cout<<"Using the DecomposeAndReconstructImageFilter..."<<std::endl;
160 filter->SetInput(inputCaster->GetOutput());
162 typename InternalImageType::Pointer output= filter->GetOutput();
165 typedef itk::CastImageFilter<InternalImageType, OutputImageType> OutputCastImageFilterType;
166 typename OutputCastImageFilterType::Pointer outputCaster= OutputCastImageFilterType::New();
167 outputCaster->SetInput(output);
168 outputCaster->Update();
171 typedef itk::ImageFileWriter<OutputImageType> WriterType;
172 typename WriterType::Pointer writer = WriterType::New();
173 writer->SetFileName(m_ArgsInfo.output_arg);
174 writer->SetInput(outputCaster->GetOutput());
182 #endif //#define clitkDecomposeAndReconstructGenericFilter_txx