]> Creatis software - clitk.git/blob - filters/clitkUnsharpMaskGenericFilter.txx
unsharp mask (needs a symbolic link of the ggo in tools to compile, due to a gengetop...
[clitk.git] / filters / clitkUnsharpMaskGenericFilter.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://oncora1.lyon.fnclcc.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 clitkUnsharpMaskGenericFilter_txx
19 #define clitkUnsharpMaskGenericFilter_txx
20
21 /* =================================================
22  * @file   clitkUnsharpMaskGenericFilter.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 "itkRecursiveGaussianImageFilter.h"
32 #include "itkSubtractImageFilter.h"
33 #include <clitkCommon.h>
34
35 namespace clitk
36 {
37
38 //--------------------------------------------------------------------
39 template<class args_info_type>
40 UnsharpMaskGenericFilter<args_info_type>::UnsharpMaskGenericFilter():
41         ImageToImageGenericFilter<Self>("UnsharpMask") {
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 UnsharpMaskGenericFilter<args_info_type>::InitializeImageType() {
53     ADD_IMAGE_TYPE(Dim, char);
54     ADD_IMAGE_TYPE(Dim, uchar);
55     ADD_IMAGE_TYPE(Dim, short);
56     ADD_IMAGE_TYPE(Dim, ushort);
57     ADD_IMAGE_TYPE(Dim, int);
58     ADD_IMAGE_TYPE(Dim, float);
59     ADD_IMAGE_TYPE(Dim, double);
60 }
61 //--------------------------------------------------------------------
62
63
64 //--------------------------------------------------------------------
65 template<class args_info_type>
66 void UnsharpMaskGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a) {
67     mArgsInfo=a;
68     SetIOVerbose(mArgsInfo.verbose_flag);
69     if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
70
71     if (mArgsInfo.input_given) {
72         SetInputFilename(mArgsInfo.input_arg);
73     }
74     if (mArgsInfo.output_given) {
75         SetOutputFilename(mArgsInfo.output_arg);
76     }
77 }
78 //--------------------------------------------------------------------
79
80 //--------------------------------------------------------------------
81 // Update with the number of dimensions and the pixeltype
82 //--------------------------------------------------------------------
83 template<class args_info_type>
84 template<class InputImageType>
85 void
86 UnsharpMaskGenericFilter<args_info_type>::UpdateWithInputImageType()
87 {
88
89     // Reading input
90     typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
91
92     // Main filter
93     typedef typename InputImageType::PixelType PixelType;
94     typedef itk::Image<float, InputImageType::ImageDimension> OutputImageType;
95
96     // Filter
97     typedef itk::RecursiveGaussianImageFilter<InputImageType, OutputImageType> RecursiveGaussianImageFilterType;
98     typename RecursiveGaussianImageFilterType::Pointer gaussianFilter=RecursiveGaussianImageFilterType::New();
99     gaussianFilter->SetInput(input);
100     gaussianFilter->SetSigma(mArgsInfo.sigma_arg);
101
102     typedef itk::SubtractImageFilter<InputImageType, OutputImageType, OutputImageType> SubtractFilterType;
103     typename SubtractFilterType::Pointer subtractFilter = SubtractFilterType::New();
104     subtractFilter->SetInput1(input);
105     subtractFilter->SetInput2(gaussianFilter->GetOutput());
106     subtractFilter->Update();
107
108     this->template SetNextOutput<OutputImageType>(subtractFilter->GetOutput());
109 }
110 //--------------------------------------------------------------------
111
112
113 }//end clitk
114
115 #endif //#define clitkUnsharpMaskGenericFilter_txx