]> Creatis software - clitk.git/blob - tools/clitkMedianImageGenericFilter.txx
*** empty log message ***
[clitk.git] / tools / 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 {
25   InitializeImageType<2>();
26   InitializeImageType<3>();
27   InitializeImageType<4>();
28 }
29 //--------------------------------------------------------------------
30
31
32 //--------------------------------------------------------------------
33 template<class args_info_type>
34 template<unsigned int Dim>
35 void MedianImageGenericFilter<args_info_type>::InitializeImageType()
36 {
37   ADD_DEFAULT_IMAGE_TYPES(Dim);
38 }
39 //--------------------------------------------------------------------
40
41
42 //--------------------------------------------------------------------
43 template<class args_info_type>
44 void MedianImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
45 {
46   mArgsInfo=a;
47   SetIOVerbose(mArgsInfo.verbose_flag);
48
49   if (mArgsInfo.input_given) {
50     SetInputFilename(mArgsInfo.input_arg);
51   }
52   if (mArgsInfo.output_given) {
53     SetOutputFilename(mArgsInfo.output_arg);
54   }
55
56 }
57 //--------------------------------------------------------------------
58
59
60 //--------------------------------------------------------------------
61 // Update with the number of dimensions and the pixeltype
62 //--------------------------------------------------------------------
63 template<class args_info_type>
64 template<class InputImageType>
65 void
66 MedianImageGenericFilter<args_info_type>::UpdateWithInputImageType()
67 {
68   // Reading input
69   typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
70   // Typedef
71   typedef typename InputImageType::PixelType PixelType;
72
73   // typedef itk::Image<PixelType,InputImageType::ImageDimension> OutputImageType;
74
75   // Main filter
76   typedef itk::Image<PixelType, InputImageType::ImageDimension> OutputImageType;
77   typename InputImageType::SizeType indexRadius;
78
79   // Filter
80   typedef itk::MedianImageFilter<InputImageType, OutputImageType> MedianImageFilterType;
81   typename MedianImageFilterType::Pointer thresholdFilter=MedianImageFilterType::New();
82   thresholdFilter->SetInput(input);
83
84   indexRadius[0]=mArgsInfo.radius_arg[0];
85   indexRadius[1]=mArgsInfo.radius_arg[1];
86   indexRadius[2]=mArgsInfo.radius_arg[2];
87
88   // indexRadius[0] = 1;
89   // indexRadius[1] = 1;
90
91   thresholdFilter->SetRadius( indexRadius );
92
93   typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput();
94   thresholdFilter->Update();
95
96   // Write/Save results
97   this->template SetNextOutput<OutputImageType>(outputImage);
98 }
99
100 //--------------------------------------------------------------------
101
102 }//end clitk
103
104
105 #endif //#define clitkMedianImageGenericFilter_txx
106