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 clitkSetBackgroundGenericFilter_txx
19 #define clitkSetBackgroundGenericFilter_txx
24 //-------------------------------------------------------------------
25 // Update with the number of dimensions
26 //-------------------------------------------------------------------
27 template<unsigned int Dimension>
29 SetBackgroundGenericFilter::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 UpdateWithDimAndPixelType<Dimension, unsigned char>();
47 // else if (PixelType == "char"){
48 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
49 // UpdateWithDimAndPixelType<Dimension, signed char>();
52 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
53 UpdateWithDimAndPixelType<Dimension, float>();
58 //-------------------------------------------------------------------
59 // Update with the number of dimensions and the pixeltype
60 //-------------------------------------------------------------------
61 template <unsigned int Dimension, class PixelType>
63 SetBackgroundGenericFilter::UpdateWithDimAndPixelType()
67 typedef itk::Image<PixelType, Dimension> InputImageType;
68 typedef itk::Image<float, Dimension> MaskImageType;
71 typedef itk::ImageFileReader<InputImageType> InputReaderType;
72 typename InputReaderType::Pointer reader = InputReaderType::New();
73 reader->SetFileName( m_InputFileName);
74 typename InputImageType::Pointer input= reader->GetOutput();
77 typedef itk::ImageFileReader<MaskImageType> MaskReaderType;
78 typename MaskReaderType::Pointer maskReader = MaskReaderType::New();
79 maskReader->SetFileName( m_ArgsInfo.mask_arg);
80 typename MaskImageType::Pointer mask= maskReader->GetOutput();
82 // Filter setting background
83 typedef clitk::SetBackgroundImageFilter<InputImageType,MaskImageType, InputImageType> SetBackgroundFilterType;
84 typename SetBackgroundFilterType::Pointer setBackgroundFilter = SetBackgroundFilterType::New();
85 setBackgroundFilter->SetInput(input);
86 setBackgroundFilter->SetInput2(mask);
87 if(m_ArgsInfo.fg_flag) setBackgroundFilter->SetForeground(m_ArgsInfo.fg_flag);
88 if(m_ArgsInfo.maskValue_given) setBackgroundFilter->SetMaskValue(m_ArgsInfo.maskValue_arg);
89 if(m_ArgsInfo.outsideValue_given) setBackgroundFilter->SetOutsideValue(m_ArgsInfo.outsideValue_arg);
90 setBackgroundFilter->Update();
91 typename InputImageType::Pointer output =setBackgroundFilter->GetOutput();
94 typedef itk::ImageFileWriter<InputImageType> WriterType;
95 typename WriterType::Pointer writer = WriterType::New();
96 writer->SetFileName(m_ArgsInfo.output_arg);
97 writer->SetInput(output);
105 #endif //#define clitkSetBackgroundGenericFilter_txx