]> Creatis software - clitk.git/blob - tools/clitkMedianImageGenericFilter.txx
Remove warnings
[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   SetIOVerbose(mArgsInfo.verbose_flag);
65
66   if (mArgsInfo.input_given) {
67     SetInputFilename(mArgsInfo.input_arg);
68   }
69   if (mArgsInfo.output_given) {
70     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   // Main filter
93   typedef itk::Image<PixelType, InputImageType::ImageDimension> OutputImageType;
94   typename InputImageType::SizeType indexRadius;
95
96   // Filter
97   typedef itk::MedianImageFilter<InputImageType, OutputImageType> MedianImageFilterType;
98   typename MedianImageFilterType::Pointer thresholdFilter=MedianImageFilterType::New();
99   thresholdFilter->SetInput(input);
100
101   for (unsigned i = 0; i < InputImageType::ImageDimension; ++i)
102     indexRadius[i]=mArgsInfo.radius_arg[i];
103
104   // indexRadius[0] = 1;
105   // indexRadius[1] = 1;
106
107   thresholdFilter->SetRadius( indexRadius );
108
109   typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput();
110   thresholdFilter->Update();
111
112   // Write/Save results
113   this->template SetNextOutput<OutputImageType>(outputImage);
114 }
115
116 //--------------------------------------------------------------------
117
118 }//end clitk
119
120
121 #endif //#define clitkMedianImageGenericFilter_txx
122