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>();
57 //-------------------------------------------------------------------
58 // Update with the number of dimensions and the pixeltype
59 //-------------------------------------------------------------------
60 template <unsigned int Dimension, class PixelType>
62 SetBackgroundGenericFilter::UpdateWithDimAndPixelType()
66 typedef itk::Image<PixelType, Dimension> InputImageType;
67 typedef itk::Image<unsigned char, Dimension> MaskImageType;
70 typedef itk::ImageFileReader<InputImageType> InputReaderType;
71 typename InputReaderType::Pointer reader = InputReaderType::New();
72 reader->SetFileName( m_InputFileName);
73 typename InputImageType::Pointer input= reader->GetOutput();
76 typedef itk::ImageFileReader<MaskImageType> MaskReaderType;
77 typename MaskReaderType::Pointer maskReader = MaskReaderType::New();
78 maskReader->SetFileName( m_ArgsInfo.mask_arg);
79 typename MaskImageType::Pointer mask= maskReader->GetOutput();
81 // Filter setting background
82 typedef clitk::SetBackgroundImageFilter<InputImageType,MaskImageType, InputImageType> SetBackgroundFilterType;
83 typename SetBackgroundFilterType::Pointer setBackgroundFilter = SetBackgroundFilterType::New();
84 setBackgroundFilter->SetInput(input);
85 setBackgroundFilter->SetInput2(mask);
86 if(m_ArgsInfo.fg_flag) setBackgroundFilter->SetForeground(m_ArgsInfo.fg_flag);
87 if(m_ArgsInfo.maskValue_given) setBackgroundFilter->SetMaskValue(m_ArgsInfo.maskValue_arg);
88 if(m_ArgsInfo.outsideValue_given) setBackgroundFilter->SetOutsideValue(m_ArgsInfo.outsideValue_arg);
89 setBackgroundFilter->Update();
90 typename InputImageType::Pointer output =setBackgroundFilter->GetOutput();
93 typedef itk::ImageFileWriter<InputImageType> WriterType;
94 typename WriterType::Pointer writer = WriterType::New();
95 writer->SetFileName(m_ArgsInfo.output_arg);
96 writer->SetInput(output);
104 #endif //#define clitkSetBackgroundGenericFilter_txx