]> Creatis software - clitk.git/blob - tools/clitkSetBackgroundGenericFilter.txx
Allow to display in all directions for images with size 2 and 3 in 3rd direction
[clitk.git] / tools / clitkSetBackgroundGenericFilter.txx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
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
8
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.
12
13   It is distributed under dual licence
14
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
20
21 namespace clitk
22 {
23
24 //-------------------------------------------------------------------
25 // Update with the number of dimensions
26 //-------------------------------------------------------------------
27 template<unsigned int Dimension>
28 void
29 SetBackgroundGenericFilter::UpdateWithDim(std::string PixelType)
30 {
31   if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<"..."<<std::endl;
32
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>();
36   }
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>();
40   //     }
41
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>();
45   }
46
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>();
50   //     }
51   else {
52     if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
53     UpdateWithDimAndPixelType<Dimension, float>();
54   }
55 }
56
57 //-------------------------------------------------------------------
58 // Update with the number of dimensions and the pixeltype
59 //-------------------------------------------------------------------
60 template <unsigned int Dimension, class  PixelType>
61 void
62 SetBackgroundGenericFilter::UpdateWithDimAndPixelType()
63 {
64
65   // ImageTypes
66   typedef itk::Image<PixelType, Dimension> InputImageType;
67   typedef itk::Image<unsigned char, Dimension> MaskImageType;
68
69   // Read the input
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();
74
75   // Read the mask
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();
80
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();
91
92   // Output
93   typedef itk::ImageFileWriter<InputImageType> WriterType;
94   typename WriterType::Pointer writer = WriterType::New();
95   writer->SetFileName(m_ArgsInfo.output_arg);
96   writer->SetInput(output);
97   writer->Update();
98
99 }
100
101
102 }//end clitk
103
104 #endif //#define clitkSetBackgroundGenericFilter_txx