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 clitkFilterGenericFilter_txx
19 #define clitkFilterGenericFilter_txx
21 /* =================================================
22 * @file clitkFilterGenericFilter.txx
28 ===================================================*/
34 //-------------------------------------------------------------------
35 // Update with the number of dimensions
36 //-------------------------------------------------------------------
37 template<unsigned int Dimension>
39 FilterGenericFilter::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 // UpdateWithDimAndPixelType<Dimension, unsigned char>();
57 // else if (PixelType == "char"){
58 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
59 // UpdateWithDimAndPixelType<Dimension, signed char>();
62 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
63 UpdateWithDimAndPixelType<Dimension, float>();
68 //-------------------------------------------------------------------
69 // Update with the number of dimensions and the pixeltype
70 //-------------------------------------------------------------------
71 template <unsigned int Dimension, class InternalPixelType>
73 FilterGenericFilter::UpdateWithDimAndPixelType()
77 typedef itk::Image<InternalPixelType, Dimension> InputImageType;
78 typedef itk::Image<InternalPixelType, Dimension> InternalImageType;
79 typedef itk::Image<InternalPixelType, Dimension> OutputImageType;
82 typedef itk::ImageFileReader<InputImageType> InputReaderType;
83 typename InputReaderType::Pointer reader = InputReaderType::New();
84 reader->SetFileName( m_InputFileName);
86 typename InputImageType::Pointer input= reader->GetOutput();
90 typedef itk::ImageToImageFilter< InternalImageType, InternalImageType > ImageToImageFilterType;
91 typename ImageToImageFilterType::Pointer filter;
93 switch ( m_ArgsInfo.type_arg ){
96 typename itk::DerivativeImageFilter< InternalImageType,InternalImageType >::Pointer df = itk::DerivativeImageFilter<InternalImageType,InternalImageType >::New();
99 df->SetDirection(m_ArgsInfo.direction_arg);
100 df->SetOrder(m_ArgsInfo.order_arg);
102 if (m_Verbose) std::cout<<"Using the derivative image filter with order "<<m_ArgsInfo.order_arg <<" on direction "<< m_ArgsInfo.direction_arg << "..." << std::endl;
106 typename itk::GradientMagnitudeImageFilter< InternalImageType,InternalImageType >::Pointer gf = itk::GradientMagnitudeImageFilter<InternalImageType,InternalImageType >::New();
109 gf->SetUseImageSpacingOn();
112 if (m_Verbose) std::cout<<"Using the gradient magnitude image filter... "<< std::endl;
117 switch ( m_ArgsInfo.projection_arg ){
121 typename itk::SumProjectionImageFilter< InternalImageType,InternalImageType >::Pointer pf = itk::SumProjectionImageFilter<InternalImageType,InternalImageType>::New();
123 pf->SetProjectionDimension(m_ArgsInfo.direction_arg);
126 if (m_Verbose) std::cout<<"Using the Sum projection image filter on the dimension "<< m_ArgsInfo.direction_arg << "..."<<std::endl;
131 typename itk::MaximumProjectionImageFilter< InternalImageType,InternalImageType >::Pointer pf = itk::MaximumProjectionImageFilter<InternalImageType,InternalImageType>::New();
133 pf->SetProjectionDimension(m_ArgsInfo.direction_arg);
136 if (m_Verbose) std::cout<<"Using the maximum intensity projection image filter on the dimension "<< m_ArgsInfo.direction_arg << "..."<<std::endl;
141 typename itk::MinimumProjectionImageFilter< InternalImageType,InternalImageType >::Pointer pf = itk::MinimumProjectionImageFilter<InternalImageType,InternalImageType>::New();
143 pf->SetProjectionDimension(m_ArgsInfo.direction_arg);
146 if (m_Verbose) std::cout<<"Using the minimum intensity projection image filter on the dimension "<< m_ArgsInfo.direction_arg << "..."<<std::endl;
151 }//end case projection filter
154 typename itk::IntensityWindowingImageFilter< InternalImageType,InternalImageType >::Pointer pf
155 = itk::IntensityWindowingImageFilter<InternalImageType,InternalImageType>::New();
157 pf->SetWindowMinimum((InternalPixelType) m_ArgsInfo.inputMin_arg);
158 pf->SetWindowMaximum((InternalPixelType) m_ArgsInfo.inputMax_arg);
159 pf->SetOutputMinimum((InternalPixelType) m_ArgsInfo.outputMin_arg);
160 pf->SetOutputMaximum((InternalPixelType) m_ArgsInfo.outputMax_arg);
163 if (m_Verbose) std::cout<<"Using the window intensity image filter with the window min and max being "
164 << m_ArgsInfo.inputMin_arg << " and "<< m_ArgsInfo.inputMax_arg
165 <<" and the output min and max being "<<m_ArgsInfo.outputMin_arg<<" and "
166 << m_ArgsInfo.outputMax_arg << std::endl;
171 //Downsample using bsplines: four types of resamplers
172 typedef itk::BSplineResampleImageFilterBase<InternalImageType, InternalImageType> ResamplerType;
173 typedef itk::BSplineCenteredResampleImageFilterBase<InternalImageType, InternalImageType> CenteredResamplerType;
174 typedef itk::BSplineL2ResampleImageFilterBase<InternalImageType, InternalImageType> L2ResamplerType;
175 typedef itk::BSplineCenteredL2ResampleImageFilterBase<InternalImageType, InternalImageType> CenteredL2ResamplerType;
178 if(m_ArgsInfo.resamplerType_arg==0)
180 typename itk::BSplineDownsampleImageFilter< InternalImageType,InternalImageType, ResamplerType >::Pointer df
181 = itk::BSplineDownsampleImageFilter< InternalImageType,InternalImageType, ResamplerType >::New();
182 df->SetSplineOrder(m_ArgsInfo.splineOrder_arg);
184 if (m_Verbose) std::cout<<"Using the BSpline downsample image filter with Standard Resampler"<<std::endl;
186 //CenteredResamplerType
187 else if(m_ArgsInfo.resamplerType_arg==1)
189 typename itk::BSplineDownsampleImageFilter< InternalImageType,InternalImageType, CenteredResamplerType >::Pointer df
190 = itk::BSplineDownsampleImageFilter< InternalImageType,InternalImageType, CenteredResamplerType >::New();
191 df->SetSplineOrder(m_ArgsInfo.splineOrder_arg);
193 if (m_Verbose) std::cout<<"Using the BSpline downsample image filter with Centered Resampler"<<std::endl;
196 else if(m_ArgsInfo.resamplerType_arg==2)
198 typename itk::BSplineDownsampleImageFilter< InternalImageType,InternalImageType, L2ResamplerType >::Pointer df
199 = itk::BSplineDownsampleImageFilter< InternalImageType,InternalImageType,L2ResamplerType >::New();
200 df->SetSplineOrder(m_ArgsInfo.splineOrder_arg);
202 if (m_Verbose) std::cout<<"Using the BSpline downsample image filter with L2 Resampler"<<std::endl;
204 else if(m_ArgsInfo.resamplerType_arg==3)
206 typename itk::BSplineDownsampleImageFilter< InternalImageType,InternalImageType, CenteredL2ResamplerType >::Pointer df
207 = itk::BSplineDownsampleImageFilter< InternalImageType,InternalImageType,CenteredL2ResamplerType >::New();
208 df->SetSplineOrder(m_ArgsInfo.splineOrder_arg);
210 if (m_Verbose) std::cout<<"Using the BSpline downsample image filter with L2 Centered Resampler"<<std::endl;
215 typedef itk::NormalizeImageFilter<InternalImageType, InternalImageType> NormalizeFilterType;
216 typename NormalizeFilterType::Pointer df = NormalizeFilterType::New();
218 if (m_Verbose) std::cout << "Normalizing image intensities to a zero mean and 1 SD (float!)..." << std::endl;
222 // typedef itk::AnisotropicDiffusionImageFilter<InternalImageType, InternalImageType> FilterType;
223 // typename FilterType::Pointer df = FilterType::New();
224 // df->SetConductanceParameter(m_ArgsInfo.cond_arg);
225 // df->SetNumberOfIterations(m_ArgsInfo.iter_arg);
226 // df->SetTimeStep(m_ArgsInfo.time_arg);
227 // df->SetUseImageSpacing(true);
230 // if (m_Verbose) std::cout << "Using the anisotropic diffusion image filter..." << std::endl;
235 typedef itk::GradientAnisotropicDiffusionImageFilter<InternalImageType, InternalImageType> FilterType;
236 typename FilterType::Pointer df = FilterType::New();
237 df->SetConductanceParameter(m_ArgsInfo.cond_arg);
238 df->SetNumberOfIterations(m_ArgsInfo.iter_arg);
239 df->SetTimeStep(m_ArgsInfo.time_arg);
240 df->SetUseImageSpacing(true);
243 if (m_Verbose) std::cout << "Using the gradient anisotropic diffusion image filter..." << std::endl;
248 typedef itk::CurvatureAnisotropicDiffusionImageFilter<InternalImageType, InternalImageType> FilterType;
249 typename FilterType::Pointer df = FilterType::New();
250 df->SetConductanceParameter(m_ArgsInfo.cond_arg);
251 df->SetNumberOfIterations(m_ArgsInfo.iter_arg);
252 df->SetTimeStep(m_ArgsInfo.time_arg);
253 df->SetUseImageSpacing(true);
256 if (m_Verbose) std::cout << "Using the Curvature anisotropic diffusion image filter..." << std::endl;
261 typedef itk::CurvatureFlowImageFilter<InternalImageType, InternalImageType> FilterType;
262 typename FilterType::Pointer df = FilterType::New();
263 df->SetTimeStep(m_ArgsInfo.time_arg);
264 df->SetUseImageSpacing(true);
265 df->SetNumberOfIterations(m_ArgsInfo.iter_arg);
267 if (m_Verbose) std::cout << "Using the curvature flow image filter......" << std::endl;
272 }//end switch filterType
275 //==================================================================
277 filter->SetInput(input);
280 if (m_Verbose)std::cout<<"Starting filter..."<<std::endl;
285 catch( itk::ExceptionObject & err )
287 std::cerr << "ExceptionObject caught! Filter failed!" << std::endl;
288 std::cerr << err << std::endl;
293 typedef itk::ImageFileWriter<OutputImageType> WriterType;
294 typename WriterType::Pointer writer = WriterType::New();
295 writer->SetFileName(m_ArgsInfo.output_arg);
296 writer->SetInput(filter->GetOutput());
304 #endif //#define clitkFilterGenericFilter_txx