1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef clitkImageLaplacianGenericFilter_txx
19 #define clitkImageLaplacianGenericFilter_txx
21 /* =================================================
22 * @file clitkImageLaplacianGenericFilter.txx
23 * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
28 ===================================================*/
31 #include "itkCastImageFilter.h"
32 #include "itkLaplacianImageFilter.h"
33 #include "itkLaplacianRecursiveGaussianImageFilter.h"
34 #include "itkLabelStatisticsImageFilter.h"
35 #include "itkMaskImageFilter.h"
36 #include "itkMaskNegatedImageFilter.h"
37 #include <clitkCommon.h>
42 //--------------------------------------------------------------------
43 template<class args_info_type>
44 ImageLaplacianGenericFilter<args_info_type>::ImageLaplacianGenericFilter():
45 ImageToImageGenericFilter<Self>("ImageLaplacian")
47 InitializeImageType<2>();
48 InitializeImageType<3>();
50 //--------------------------------------------------------------------
53 //--------------------------------------------------------------------
54 template<class args_info_type>
55 template<unsigned int Dim>
56 void ImageLaplacianGenericFilter<args_info_type>::InitializeImageType()
58 ADD_DEFAULT_IMAGE_TYPES(Dim);
60 //--------------------------------------------------------------------
63 //--------------------------------------------------------------------
64 template<class args_info_type>
65 void ImageLaplacianGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
68 this->SetIOVerbose(mArgsInfo.verbose_flag);
69 if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
71 if (mArgsInfo.input_given) {
72 this->SetInputFilename(mArgsInfo.input_arg);
74 if (mArgsInfo.output_given) {
75 this->SetOutputFilename(mArgsInfo.output_arg);
77 if (mArgsInfo.mask_given) {
78 this->AddInputFilename(mArgsInfo.mask_arg);
81 //--------------------------------------------------------------------
83 //--------------------------------------------------------------------
84 // Update with the number of dimensions and the pixeltype
85 //--------------------------------------------------------------------
86 template<class args_info_type>
87 template<class InputImageType>
89 ImageLaplacianGenericFilter<args_info_type>::UpdateWithInputImageType()
92 typedef typename InputImageType::PixelType InputPixelType;
93 typedef itk::Image<float, InputImageType::ImageDimension> FloatImageType;
94 typedef itk::Image<unsigned char, FloatImageType::ImageDimension> MaskImageType;
97 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
100 typedef itk::CastImageFilter< InputImageType, FloatImageType > CastFilterType;
101 typename CastFilterType::Pointer castFilter = CastFilterType::New();
102 castFilter->SetInput(input);
103 castFilter->Update();
105 typename MaskImageType::Pointer mask = ITK_NULLPTR;
106 if(mArgsInfo.mask_given) {
107 mask = this->template GetInput<MaskImageType>(1);
110 mask = MaskImageType::New();
111 mask->SetRegions(input->GetLargestPossibleRegion());
112 mask->SetOrigin(input->GetOrigin());
113 mask->SetSpacing(input->GetSpacing());
119 // Create output image
120 typename FloatImageType::Pointer outputImage = FloatImageType::New();
121 outputImage->SetRegions(input->GetLargestPossibleRegion());
122 outputImage->SetOrigin(input->GetOrigin());
123 outputImage->SetSpacing(input->GetSpacing());
124 outputImage->Allocate();
125 outputImage->FillBuffer(0.0);
126 // Set output iterator
127 typedef itk::ImageRegionIterator<FloatImageType> IteratorOutputType;
128 IteratorOutputType ito = IteratorOutputType(outputImage, outputImage->GetLargestPossibleRegion());
131 typename FloatImageType::Pointer outputLaplacianFilter;
132 if (mArgsInfo.gaussian_filter_flag == 0) {
133 //std::cout<<"gaussian filter flag == 0"<<std::endl;
134 typedef itk::LaplacianImageFilter<FloatImageType, FloatImageType> LaplacianImageFilterType;
135 typename LaplacianImageFilterType::Pointer laplacianFilter=LaplacianImageFilterType::New();
136 laplacianFilter->SetInput(castFilter->GetOutput());
137 laplacianFilter->Update();
138 outputLaplacianFilter = laplacianFilter->GetOutput();
141 //std::cout<<"gaussian filter flag == 1"<<std::endl;
142 typedef itk::LaplacianRecursiveGaussianImageFilter< FloatImageType, FloatImageType > LaplacianImageFilterType;
143 typename LaplacianImageFilterType::Pointer laplacianFilter=LaplacianImageFilterType::New();
144 laplacianFilter->SetInput(castFilter->GetOutput());
145 laplacianFilter->Update();
146 //std::cout<<"sigma value="<<laplacianFilter->GetSigma()<<std::endl;
147 outputLaplacianFilter = laplacianFilter->GetOutput();
150 typedef itk::ImageRegionIterator<FloatImageType> IteratorType;
151 IteratorType it(outputLaplacianFilter, outputLaplacianFilter->GetLargestPossibleRegion());
154 typedef itk::ImageRegionIterator<MaskImageType> IteratorMaskType;
155 IteratorMaskType itm(mask, mask->GetLargestPossibleRegion());
157 //typedef itk::MinimumMaximumImageCalculator <OutputImageType> ImageCalculatorFilterType;
158 //typename ImageCalculatorFilterType::Pointer imageCalculatorFilter = ImageCalculatorFilterType::New();
159 //imageCalculatorFilter->SetImage(gradientFilter->GetOutput());
160 //imageCalculatorFilter->Compute();
161 typedef itk::LabelStatisticsImageFilter< FloatImageType, MaskImageType > LabelStatisticsImageFilterType;
162 typename LabelStatisticsImageFilterType::Pointer labelStatisticsImageFilter = LabelStatisticsImageFilterType::New();
163 labelStatisticsImageFilter->SetLabelInput( mask );
164 labelStatisticsImageFilter->SetInput(outputLaplacianFilter);
165 labelStatisticsImageFilter->Update();
167 //std::cout << "Number of labels: " << labelStatisticsImageFilter->GetNumberOfLabels() << std::endl;
169 float minImg = labelStatisticsImageFilter->GetMinimum(1);
170 //std::cout << "minImg: " << minImg << std::endl;
171 float maxImg = labelStatisticsImageFilter->GetMaximum(1);
172 //std::cout << "maxImg: " << maxImg << std::endl;
178 while (!ito.IsAtEnd()) {
179 if(mArgsInfo.normalize_flag && itm.Get() == 1) {
180 ito.Set(((float) it.Get() - minImg)/(maxImg-minImg));
182 if (mArgsInfo.normalize_flag == 0 && itm.Get() == 1) {
183 ito.Set((float) it.Get());
190 //typename OutputImageType::Pointer outputImage = gradientFilter->GetOutput();
191 this->template SetNextOutput<FloatImageType>(outputImage);
193 //--------------------------------------------------------------------
198 #endif //#define clitkImageLaplacianGenericFilter_txx