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
21 /* =================================================
22 * @file clitkSetBackgroundGenericFilter.txx
28 ===================================================*/
34 //-------------------------------------------------------------------
35 // Update with the number of dimensions
36 //-------------------------------------------------------------------
37 template<unsigned int Dimension>
39 SetBackgroundGenericFilter::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 PixelType>
73 SetBackgroundGenericFilter::UpdateWithDimAndPixelType()
77 typedef itk::Image<PixelType, Dimension> InputImageType;
78 typedef itk::Image<float, Dimension> MaskImageType;
81 typedef itk::ImageFileReader<InputImageType> InputReaderType;
82 typename InputReaderType::Pointer reader = InputReaderType::New();
83 reader->SetFileName( m_InputFileName);
84 typename InputImageType::Pointer input= reader->GetOutput();
87 typedef itk::ImageFileReader<MaskImageType> MaskReaderType;
88 typename MaskReaderType::Pointer maskReader = MaskReaderType::New();
89 maskReader->SetFileName( m_ArgsInfo.mask_arg);
90 typename MaskImageType::Pointer mask= maskReader->GetOutput();
92 // Filter setting background
93 typedef clitk::SetBackgroundImageFilter<InputImageType,MaskImageType, InputImageType> SetBackgroundFilterType;
94 typename SetBackgroundFilterType::Pointer setBackgroundFilter = SetBackgroundFilterType::New();
95 setBackgroundFilter->SetInput(input);
96 setBackgroundFilter->SetInput2(mask);
97 if(m_ArgsInfo.fg_flag) setBackgroundFilter->SetForeground(m_ArgsInfo.fg_flag);
98 if(m_ArgsInfo.maskValue_given) setBackgroundFilter->SetMaskValue(m_ArgsInfo.maskValue_arg);
99 if(m_ArgsInfo.outsideValue_given) setBackgroundFilter->SetOutsideValue(m_ArgsInfo.outsideValue_arg);
100 setBackgroundFilter->Update();
101 typename InputImageType::Pointer output =setBackgroundFilter->GetOutput();
104 typedef itk::ImageFileWriter<InputImageType> WriterType;
105 typename WriterType::Pointer writer = WriterType::New();
106 writer->SetFileName(m_ArgsInfo.output_arg);
107 writer->SetInput(output);
115 #endif //#define clitkSetBackgroundGenericFilter_txx