1 #ifndef clitkSetBackgroundGenericFilter_txx
2 #define clitkSetBackgroundGenericFilter_txx
4 /* =================================================
5 * @file clitkSetBackgroundGenericFilter.txx
11 ===================================================*/
17 //-------------------------------------------------------------------
18 // Update with the number of dimensions
19 //-------------------------------------------------------------------
20 template<unsigned int Dimension>
22 SetBackgroundGenericFilter::UpdateWithDim(std::string PixelType)
24 if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<"..."<<std::endl;
26 if(PixelType == "short"){
27 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
28 UpdateWithDimAndPixelType<Dimension, signed short>();
30 // else if(PixelType == "unsigned_short"){
31 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
32 // UpdateWithDimAndPixelType<Dimension, unsigned short>();
35 else if (PixelType == "unsigned_char"){
36 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
37 UpdateWithDimAndPixelType<Dimension, unsigned char>();
40 // else if (PixelType == "char"){
41 // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
42 // UpdateWithDimAndPixelType<Dimension, signed char>();
45 if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
46 UpdateWithDimAndPixelType<Dimension, float>();
51 //-------------------------------------------------------------------
52 // Update with the number of dimensions and the pixeltype
53 //-------------------------------------------------------------------
54 template <unsigned int Dimension, class PixelType>
56 SetBackgroundGenericFilter::UpdateWithDimAndPixelType()
60 typedef itk::Image<PixelType, Dimension> InputImageType;
61 typedef itk::Image<float, Dimension> MaskImageType;
64 typedef itk::ImageFileReader<InputImageType> InputReaderType;
65 typename InputReaderType::Pointer reader = InputReaderType::New();
66 reader->SetFileName( m_InputFileName);
67 typename InputImageType::Pointer input= reader->GetOutput();
70 typedef itk::ImageFileReader<MaskImageType> MaskReaderType;
71 typename MaskReaderType::Pointer maskReader = MaskReaderType::New();
72 maskReader->SetFileName( m_ArgsInfo.mask_arg);
73 typename MaskImageType::Pointer mask= maskReader->GetOutput();
75 // Filter setting background
76 typedef clitk::SetBackgroundImageFilter<InputImageType,MaskImageType, InputImageType> SetBackgroundFilterType;
77 typename SetBackgroundFilterType::Pointer setBackgroundFilter = SetBackgroundFilterType::New();
78 setBackgroundFilter->SetInput(input);
79 setBackgroundFilter->SetInput2(mask);
80 if(m_ArgsInfo.fg_flag) setBackgroundFilter->SetForeground(m_ArgsInfo.fg_flag);
81 if(m_ArgsInfo.maskValue_given) setBackgroundFilter->SetMaskValue(m_ArgsInfo.maskValue_arg);
82 if(m_ArgsInfo.outsideValue_given) setBackgroundFilter->SetOutsideValue(m_ArgsInfo.outsideValue_arg);
83 setBackgroundFilter->Update();
84 typename InputImageType::Pointer output =setBackgroundFilter->GetOutput();
87 typedef itk::ImageFileWriter<InputImageType> WriterType;
88 typename WriterType::Pointer writer = WriterType::New();
89 writer->SetFileName(m_ArgsInfo.output_arg);
90 writer->SetInput(output);
98 #endif //#define clitkSetBackgroundGenericFilter_txx