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 clitkNormalizeImageFilterGenericFilter_txx
19 #define clitkNormalizeImageFilterGenericFilter_txx
21 /* =================================================
22 * @file clitkNormalizeImageFilterGenericFilter.txx
23 * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
28 ===================================================*/
31 #include "itkLabelStatisticsImageFilter.h"
32 #include "itkMaskImageFilter.h"
33 #include "itkMaskNegatedImageFilter.h"
34 #include <clitkCommon.h>
39 //--------------------------------------------------------------------
40 template<class args_info_type>
41 NormalizeImageFilterGenericFilter<args_info_type>::NormalizeImageFilterGenericFilter():
42 ImageToImageGenericFilter<Self>("NormalizeImageFilter")
44 InitializeImageType<2>();
45 InitializeImageType<3>();
47 //--------------------------------------------------------------------
50 //--------------------------------------------------------------------
51 template<class args_info_type>
52 template<unsigned int Dim>
53 void NormalizeImageFilterGenericFilter<args_info_type>::InitializeImageType()
55 ADD_DEFAULT_IMAGE_TYPES(Dim);
57 //--------------------------------------------------------------------
60 //--------------------------------------------------------------------
61 template<class args_info_type>
62 void NormalizeImageFilterGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
65 this->SetIOVerbose(mArgsInfo.verbose_flag);
66 if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
68 if (mArgsInfo.input_given) {
69 this->SetInputFilename(mArgsInfo.input_arg);
71 if (mArgsInfo.output_given) {
72 this->SetOutputFilename(mArgsInfo.output_arg);
74 if (mArgsInfo.mask_given) {
75 this->AddInputFilename(mArgsInfo.mask_arg);
78 //--------------------------------------------------------------------
80 //--------------------------------------------------------------------
81 // Update with the number of dimensions and the pixeltype
82 //--------------------------------------------------------------------
83 template<class args_info_type>
84 template<class InputImageType>
86 NormalizeImageFilterGenericFilter<args_info_type>::UpdateWithInputImageType()
90 typedef typename InputImageType::PixelType InputPixelType;
91 typedef itk::Image<float, InputImageType::ImageDimension> OutputImageType;
92 typedef itk::Image<unsigned char, OutputImageType::ImageDimension> MaskImageType;
95 typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
97 typename MaskImageType::Pointer mask = NULL;
98 if(mArgsInfo.mask_given) {
99 mask = this->template GetInput<MaskImageType>(1);
102 mask = MaskImageType::New();
103 mask->SetRegions(input->GetLargestPossibleRegion());
104 mask->SetOrigin(input->GetOrigin());
105 mask->SetSpacing(input->GetSpacing());
110 // Create output image
111 typename OutputImageType::Pointer outputImage = OutputImageType::New();
112 outputImage->SetRegions(input->GetLargestPossibleRegion());
113 outputImage->SetOrigin(input->GetOrigin());
114 outputImage->SetSpacing(input->GetSpacing());
115 outputImage->Allocate();
116 outputImage->FillBuffer(0.0);
117 // Set output iterator
118 typedef itk::ImageRegionIterator<OutputImageType> IteratorOutputType;
119 IteratorOutputType ito = IteratorOutputType(outputImage, outputImage->GetLargestPossibleRegion());
123 typedef itk::ImageRegionIterator<InputImageType> IteratorType;
124 IteratorType it(input, input->GetLargestPossibleRegion());
127 typedef itk::ImageRegionIterator<MaskImageType> IteratorMaskType;
128 IteratorMaskType itm(mask, mask->GetLargestPossibleRegion());
130 typedef itk::LabelStatisticsImageFilter< InputImageType, MaskImageType > LabelStatisticsImageFilterType;
131 typename LabelStatisticsImageFilterType::Pointer labelStatisticsImageFilter = LabelStatisticsImageFilterType::New();
132 labelStatisticsImageFilter->SetLabelInput( mask );
133 labelStatisticsImageFilter->SetInput(input);
134 labelStatisticsImageFilter->Update();
136 //std::cout << "Number of labels: " << labelStatisticsImageFilter->GetNumberOfLabels() << std::endl;
138 float minImg = labelStatisticsImageFilter->GetMinimum(1);
139 //std::cout << "minImg= " << minImg << std::endl;
140 float maxImg = labelStatisticsImageFilter->GetMaximum(1);
141 //std::cout << "maxImg= " << maxImg << std::endl;
147 while (!ito.IsAtEnd()) {
149 ito.Set(((float) it.Get() - minImg)/(maxImg-minImg));
157 // Write/Save results
158 this->template SetNextOutput<OutputImageType>(outputImage);
160 //--------------------------------------------------------------------
165 #endif //#define clitkNormalizeImageFilterGenericFilter_txx