]> Creatis software - clitk.git/blob - tools/clitkMedianImageGenericFilter.txx
Precision on clitkBlurImage help
[clitk.git] / tools / clitkMedianImageGenericFilter.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 clitkMedianImageGenericFilter_txx
19 #define clitkMedianImageGenericFilter_txx
20
21 /* =================================================
22  * @file   clitkMedianImageGenericFilter.txx
23  * @author Bharath Navalapakkam <Bharath.Navalpakkam@creatis.insa-lyon.fr>
24  * @date   20 March 2010
25  *
26  * @brief
27  *
28  ===================================================*/
29
30 // itk include
31 #include "itkMedianImageFilter.h"
32 #include "itkImage.h"
33
34 namespace clitk
35 {
36
37 //--------------------------------------------------------------------
38 template<class args_info_type>
39 MedianImageGenericFilter<args_info_type>::MedianImageGenericFilter():
40   ImageToImageGenericFilter<Self>("MedianImage")
41 {
42   InitializeImageType<2>();
43   InitializeImageType<3>();
44   InitializeImageType<4>();
45 }
46 //--------------------------------------------------------------------
47
48
49 //--------------------------------------------------------------------
50 template<class args_info_type>
51 template<unsigned int Dim>
52 void MedianImageGenericFilter<args_info_type>::InitializeImageType()
53 {
54   ADD_DEFAULT_IMAGE_TYPES(Dim);
55 }
56 //--------------------------------------------------------------------
57
58
59 //--------------------------------------------------------------------
60 template<class args_info_type>
61 void MedianImageGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
62 {
63   mArgsInfo=a;
64   this->SetIOVerbose(mArgsInfo.verbose_flag);
65
66   if (mArgsInfo.input_given) {
67     this->SetInputFilename(mArgsInfo.input_arg);
68   }
69   if (mArgsInfo.output_given) {
70     this->SetOutputFilename(mArgsInfo.output_arg);
71   }
72
73 }
74 //--------------------------------------------------------------------
75
76
77 //--------------------------------------------------------------------
78 // Update with the number of dimensions and the pixeltype
79 //--------------------------------------------------------------------
80 template<class args_info_type>
81 template<class InputImageType>
82 void
83 MedianImageGenericFilter<args_info_type>::UpdateWithInputImageType()
84 {
85   // Reading input
86   typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
87   // Typedef
88   typedef typename InputImageType::PixelType PixelType;
89
90   // typedef itk::Image<PixelType,InputImageType::ImageDimension> OutputImageType;
91
92   // Filter
93   typedef itk::MedianImageFilter<InputImageType, InputImageType> MedianImageFilterType;
94   typename MedianImageFilterType::Pointer medianFilter=MedianImageFilterType::New();
95   typename MedianImageFilterType::InputSizeType radius;
96   radius.Fill(1);
97   medianFilter->SetInput(input);
98
99   if(mArgsInfo.radius_given) {
100       for (unsigned i = 0; i < InputImageType::ImageDimension; ++i)
101           radius[i]=mArgsInfo.radius_arg[i];
102   }
103   //
104   std::cout<<"radius median filter= "<<radius<<std::endl;
105   //
106   medianFilter->SetRadius( radius );
107
108   medianFilter->Update();
109   // Write/Save results
110   typename InputImageType::Pointer outputImage = medianFilter->GetOutput();
111   this->template SetNextOutput<InputImageType>(outputImage);
112 }
113
114 //--------------------------------------------------------------------
115
116 }//end clitk
117
118
119 #endif //#define clitkMedianImageGenericFilter_txx
120