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 "itkLabelStatisticsImageFilter.h"
34 #include "itkMaskImageFilter.h"
35 #include "itkMaskNegatedImageFilter.h"
36 #include <clitkCommon.h>
41 //--------------------------------------------------------------------
42 template<class args_info_type>
43 ImageLaplacianGenericFilter<args_info_type>::ImageLaplacianGenericFilter():
44 ImageToImageGenericFilter<Self>("ImageLaplacian")
46 InitializeImageType<2>();
47 InitializeImageType<3>();
49 //--------------------------------------------------------------------
52 //--------------------------------------------------------------------
53 template<class args_info_type>
54 template<unsigned int Dim>
55 void ImageLaplacianGenericFilter<args_info_type>::InitializeImageType()
57 ADD_DEFAULT_IMAGE_TYPES(Dim);
59 //--------------------------------------------------------------------
62 //--------------------------------------------------------------------
63 template<class args_info_type>
64 void ImageLaplacianGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
67 this->SetIOVerbose(mArgsInfo.verbose_flag);
68 if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
70 if (mArgsInfo.input_given) {
71 this->SetInputFilename(mArgsInfo.input_arg);
73 if (mArgsInfo.output_given) {
74 this->SetOutputFilename(mArgsInfo.output_arg);
76 if (mArgsInfo.mask_given) {
77 this->AddInputFilename(mArgsInfo.mask_arg);
80 //--------------------------------------------------------------------
82 //--------------------------------------------------------------------
83 // Update with the number of dimensions and the pixeltype
84 //--------------------------------------------------------------------
85 template<class args_info_type>
86 template<class InputImageType>
88 ImageLaplacianGenericFilter<args_info_type>::UpdateWithInputImageType()
91 typedef typename InputImageType::PixelType InputPixelType;
92 typedef itk::Image<float, InputImageType::ImageDimension> FloatImageType;
93 typedef itk::Image<unsigned char, FloatImageType::ImageDimension> MaskImageType;
96 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
99 typedef itk::CastImageFilter< InputImageType, FloatImageType > CastFilterType;
100 typename CastFilterType::Pointer castFilter = CastFilterType::New();
101 castFilter->SetInput(input);
102 castFilter->Update();
104 typename MaskImageType::Pointer mask = NULL;
105 if(mArgsInfo.mask_given) {
106 mask = this->template GetInput<MaskImageType>(1);
109 mask = MaskImageType::New();
110 mask->SetRegions(input->GetLargestPossibleRegion());
111 mask->SetOrigin(input->GetOrigin());
112 mask->SetSpacing(input->GetSpacing());
118 // Create output image
119 typename FloatImageType::Pointer outputImage = FloatImageType::New();
120 outputImage->SetRegions(input->GetLargestPossibleRegion());
121 outputImage->SetOrigin(input->GetOrigin());
122 outputImage->SetSpacing(input->GetSpacing());
123 outputImage->Allocate();
124 outputImage->FillBuffer(0.0);
125 // Set output iterator
126 typedef itk::ImageRegionIterator<FloatImageType> IteratorOutputType;
127 IteratorOutputType ito = IteratorOutputType(outputImage, outputImage->GetLargestPossibleRegion());
130 typedef itk::LaplacianImageFilter<FloatImageType, FloatImageType> LaplacianImageFilterType;
131 typename LaplacianImageFilterType::Pointer laplacianFilter=LaplacianImageFilterType::New();
132 laplacianFilter->SetInput(castFilter->GetOutput());
133 laplacianFilter->Update();
135 typedef itk::ImageRegionIterator<FloatImageType> IteratorType;
136 IteratorType it(laplacianFilter->GetOutput(), laplacianFilter->GetOutput()->GetLargestPossibleRegion());
139 typedef itk::ImageRegionIterator<MaskImageType> IteratorMaskType;
140 IteratorMaskType itm(mask, mask->GetLargestPossibleRegion());
142 //typedef itk::MinimumMaximumImageCalculator <OutputImageType> ImageCalculatorFilterType;
143 //typename ImageCalculatorFilterType::Pointer imageCalculatorFilter = ImageCalculatorFilterType::New();
144 //imageCalculatorFilter->SetImage(gradientFilter->GetOutput());
145 //imageCalculatorFilter->Compute();
146 typedef itk::LabelStatisticsImageFilter< FloatImageType, MaskImageType > LabelStatisticsImageFilterType;
147 typename LabelStatisticsImageFilterType::Pointer labelStatisticsImageFilter = LabelStatisticsImageFilterType::New();
148 labelStatisticsImageFilter->SetLabelInput( mask );
149 labelStatisticsImageFilter->SetInput(laplacianFilter->GetOutput());
150 labelStatisticsImageFilter->Update();
152 //std::cout << "Number of labels: " << labelStatisticsImageFilter->GetNumberOfLabels() << std::endl;
154 float minImg = labelStatisticsImageFilter->GetMinimum(1);
155 //std::cout << "minImg: " << minImg << std::endl;
156 float maxImg = labelStatisticsImageFilter->GetMaximum(1);
157 //std::cout << "maxImg: " << maxImg << std::endl;
163 while (!ito.IsAtEnd()) {
164 if(mArgsInfo.normalize_flag && itm.Get() == 1) {
165 ito.Set(((float) it.Get() - minImg)/(maxImg-minImg));
167 if (mArgsInfo.normalize_flag == 0 && itm.Get() == 1) {
168 ito.Set((float) it.Get());
175 //typename OutputImageType::Pointer outputImage = gradientFilter->GetOutput();
176 this->template SetNextOutput<FloatImageType>(outputImage);
178 //--------------------------------------------------------------------
183 #endif //#define clitkImageLaplacianGenericFilter_txx