]> Creatis software - clitk.git/blob - tools/clitkImageGradientMagnitudeGenericFilter.txx
gradient magnitude tool
[clitk.git] / tools / clitkImageGradientMagnitudeGenericFilter.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 clitkImageGradientMagnitudeGenericFilter_txx
19 #define clitkImageGradientMagnitudeGenericFilter_txx
20
21 /* =================================================
22  * @file   clitkImageGradientMagnitudeGenericFilter.txx
23  * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
24  * @date   29 june 2009
25  *
26  * @brief
27  *
28  ===================================================*/
29
30 // itk include
31 #include "itkGradientMagnitudeImageFilter.h"
32 #include "itkMaskImageFilter.h"
33 #include "itkMaskNegatedImageFilter.h"
34 #include <clitkCommon.h>
35
36 namespace clitk
37 {
38
39 //--------------------------------------------------------------------
40 template<class args_info_type>
41 ImageGradientMagnitudeGenericFilter<args_info_type>::ImageGradientMagnitudeGenericFilter():
42   ImageToImageGenericFilter<Self>("ImageGradientMagnitude")
43 {
44   InitializeImageType<2>();
45   InitializeImageType<3>();
46 }
47 //--------------------------------------------------------------------
48
49
50 //--------------------------------------------------------------------
51 template<class args_info_type>
52 template<unsigned int Dim>
53 void ImageGradientMagnitudeGenericFilter<args_info_type>::InitializeImageType()
54 {
55   ADD_DEFAULT_IMAGE_TYPES(Dim);
56 }
57 //--------------------------------------------------------------------
58
59
60 //--------------------------------------------------------------------
61 template<class args_info_type>
62 void ImageGradientMagnitudeGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
63 {
64   mArgsInfo=a;
65   this->SetIOVerbose(mArgsInfo.verbose_flag);
66   if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
67
68   if (mArgsInfo.input_given) {
69     this->SetInputFilename(mArgsInfo.input_arg);
70   }
71   if (mArgsInfo.output_given) {
72     this->SetOutputFilename(mArgsInfo.output_arg);
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 ImageGradientMagnitudeGenericFilter<args_info_type>::UpdateWithInputImageType()
84 {
85
86   // Reading input
87   typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
88
89   // Main filter
90   typedef typename InputImageType::PixelType PixelType;
91   typedef itk::Image<float, InputImageType::ImageDimension> OutputImageType;
92
93   // Filter
94   typedef itk::GradientMagnitudeImageFilter<InputImageType, OutputImageType> GradientMagnitudeImageFilterType;
95   typename GradientMagnitudeImageFilterType::Pointer gradientFilter=GradientMagnitudeImageFilterType::New();
96   gradientFilter->SetInput(input);
97   gradientFilter->Update();
98
99   typename OutputImageType::Pointer outputImage = gradientFilter->GetOutput();
100   this->template SetNextOutput<OutputImageType>(outputImage);
101 }
102 //--------------------------------------------------------------------
103
104
105 }//end clitk
106
107 #endif //#define clitkImageGradientMagnitudeGenericFilter_txx