]> Creatis software - clitk.git/blob - filters/clitkMedianImageGenericFilter.txx
292997b9136119302c06a21678a3b6b1063c9523
[clitk.git] / filters / clitkMedianImageGenericFilter.txx
1  #ifndef clitkMedianImageGenericFilter_txx
2 #define clitkMedianImageGenericFilter_txx
3
4 /* =================================================
5  * @file   clitkMedianImageGenericFilter.txx
6  * @author Bharath Navalapakkam <Bharath.Navalpakkam@creatis.insa-lyon.fr>
7  * @date   20 March 2010
8  * 
9  * @brief 
10  * 
11  ===================================================*/
12
13 // itk include
14 #include "itkMedianImageFilter.h"
15 #include "itkImage.h"
16
17 namespace clitk
18 {
19   
20   //--------------------------------------------------------------------
21   template<class args_info_type>
22   MedianImageGenericFilter<args_info_type>::MedianImageGenericFilter():
23     ImageToImageGenericFilter<Self>("MedianImage") {
24     InitializeImageType<2>();
25     InitializeImageType<3>();
26     InitializeImageType<4>();
27   }
28   //--------------------------------------------------------------------
29
30
31   //--------------------------------------------------------------------
32   template<class args_info_type>
33   template<unsigned int Dim>
34   void MedianImageGenericFilter<args_info_type>::InitializeImageType() {      
35     ADD_DEFAULT_IMAGE_TYPES(Dim);
36   }
37   //--------------------------------------------------------------------
38   
39
40   //--------------------------------------------------------------------
41   template<class args_info_type>
42   void MedianImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a) {
43     mArgsInfo=a;
44     SetIOVerbose(mArgsInfo.verbose_flag);  
45
46     if (mArgsInfo.input_given) {
47       SetInputFilename(mArgsInfo.input_arg);
48     }
49     if (mArgsInfo.output_given) {
50       SetOutputFilename(mArgsInfo.output_arg);
51     }
52
53   }
54   //--------------------------------------------------------------------
55
56
57   //--------------------------------------------------------------------
58   // Update with the number of dimensions and the pixeltype
59   //--------------------------------------------------------------------
60   template<class args_info_type>
61   template<class InputImageType>
62   void 
63   MedianImageGenericFilter<args_info_type>::UpdateWithInputImageType()
64   {
65     // Reading input
66     typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
67     // Typedef
68     typedef typename InputImageType::PixelType PixelType;
69
70     // typedef itk::Image<PixelType,InputImageType::ImageDimension> OutputImageType;
71
72     // Main filter   
73     typedef itk::Image<PixelType, InputImageType::ImageDimension> OutputImageType;
74     typename InputImageType::SizeType indexRadius;
75
76     // Filter
77     typedef itk::MedianImageFilter<InputImageType, OutputImageType> MedianImageFilterType; 
78     typename MedianImageFilterType::Pointer thresholdFilter=MedianImageFilterType::New();
79     thresholdFilter->SetInput(input);
80
81     indexRadius[0]=mArgsInfo.radius_arg[0];
82     indexRadius[1]=mArgsInfo.radius_arg[1];
83     indexRadius[2]=mArgsInfo.radius_arg[2];
84   
85     // indexRadius[0] = 1; 
86     // indexRadius[1] = 1;
87
88     thresholdFilter->SetRadius( indexRadius );  
89
90     typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput();
91     thresholdFilter->Update();
92      
93     // Write/Save results
94     this->template SetNextOutput<OutputImageType>(outputImage);   
95   }
96   
97   //--------------------------------------------------------------------
98
99 }//end clitk
100
101  
102 #endif //#define clitkMedianImageGenericFilter_txx
103