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 clitkImageIntensityWindowingGenericFilter_txx
19 #define clitkImageIntensityWindowingGenericFilter_txx
21 /* =================================================
22 * @file clitkImageIntensityWindowingGenericFilter.txx
23 * @author Jef Vandemeulebroucke <jef@creatis.insa-lyon.fr>
28 ===================================================*/
31 #include "itkIntensityWindowingImageFilter.h"
32 #include "itkLabelStatisticsImageFilter.h"
33 #include "itkMaskImageFilter.h"
34 #include "itkMaskNegatedImageFilter.h"
35 #include <clitkCommon.h>
40 //--------------------------------------------------------------------
41 template<class args_info_type>
42 ImageIntensityWindowingGenericFilter<args_info_type>::ImageIntensityWindowingGenericFilter():
43 ImageToImageGenericFilter<Self>("ImageIntensityWindowing")
45 InitializeImageType<2>();
46 InitializeImageType<3>();
48 //--------------------------------------------------------------------
51 //--------------------------------------------------------------------
52 template<class args_info_type>
53 template<unsigned int Dim>
54 void ImageIntensityWindowingGenericFilter<args_info_type>::InitializeImageType()
56 ADD_DEFAULT_IMAGE_TYPES(Dim);
58 //--------------------------------------------------------------------
61 //--------------------------------------------------------------------
62 template<class args_info_type>
63 void ImageIntensityWindowingGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
66 this->SetIOVerbose(mArgsInfo.verbose_flag);
67 if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
69 if (mArgsInfo.input_given) {
70 this->SetInputFilename(mArgsInfo.input_arg);
72 if (mArgsInfo.output_given) {
73 this->SetOutputFilename(mArgsInfo.output_arg);
75 if (mArgsInfo.mask_given) {
76 this->AddInputFilename(mArgsInfo.mask_arg);
79 //--------------------------------------------------------------------
81 //--------------------------------------------------------------------
82 // Update with the number of dimensions and the pixeltype
83 //--------------------------------------------------------------------
84 template<class args_info_type>
85 template<class InputImageType>
87 ImageIntensityWindowingGenericFilter<args_info_type>::UpdateWithInputImageType()
91 typedef typename InputImageType::PixelType InputPixelType;
92 typedef itk::Image<float, InputImageType::ImageDimension> OutputImageType;
93 typedef itk::Image<unsigned char, InputImageType::ImageDimension> MaskImageType;
96 typename OutputImageType::Pointer input = this->template GetInput<OutputImageType>(0);
98 typename MaskImageType::Pointer mask = ITK_NULLPTR;
99 if(mArgsInfo.mask_given) {
100 mask = this->template GetInput<MaskImageType>(1);
103 mask = MaskImageType::New();
104 mask->SetRegions(input->GetLargestPossibleRegion());
105 mask->SetOrigin(input->GetOrigin());
106 mask->SetSpacing(input->GetSpacing());
111 typedef itk::ImageRegionIterator<MaskImageType> IteratorMaskType;
112 IteratorMaskType itm(mask, mask->GetLargestPossibleRegion());
114 typedef itk::LabelStatisticsImageFilter< OutputImageType, MaskImageType > LabelStatisticsImageFilterType;
115 typename LabelStatisticsImageFilterType::Pointer labelStatisticsImageFilter = LabelStatisticsImageFilterType::New();
116 labelStatisticsImageFilter->SetLabelInput( mask );
117 labelStatisticsImageFilter->SetInput(input);
118 labelStatisticsImageFilter->Update();
119 float maxImg = labelStatisticsImageFilter->GetMaximum(1);
120 //std::cout << "maxImg: " << maxImg << std::endl;
122 typedef itk::IntensityWindowingImageFilter <OutputImageType, OutputImageType> IntensityWindowingImageFilterType;
123 typename IntensityWindowingImageFilterType::Pointer filter = IntensityWindowingImageFilterType::New();
124 filter->SetInput(input);
125 filter->SetWindowMinimum(0.0);
126 filter->SetWindowMaximum(maxImg);
127 filter->SetOutputMinimum(0.0);
128 filter->SetOutputMaximum(1.0);
132 typedef itk::ImageRegionIterator<OutputImageType> IteratorType;
133 IteratorType it(filter->GetOutput(), filter->GetOutput()->GetLargestPossibleRegion());
134 //A little bit strange to do that but I think I need to do it.
135 // Create output image
136 typename OutputImageType::Pointer outputImage = OutputImageType::New();
137 outputImage->SetRegions(filter->GetOutput()->GetLargestPossibleRegion());
138 outputImage->SetOrigin(filter->GetOutput()->GetOrigin());
139 outputImage->SetSpacing(filter->GetOutput()->GetSpacing());
140 outputImage->Allocate();
141 outputImage->FillBuffer(-100.0);
142 // Set output iterator
143 typedef itk::ImageRegionIterator<OutputImageType> IteratorOutputType;
144 IteratorOutputType ito = IteratorOutputType(outputImage, outputImage->GetLargestPossibleRegion());
150 while (!ito.IsAtEnd()) {
159 // Write/Save results
160 this->template SetNextOutput<OutputImageType>(outputImage);
162 //--------------------------------------------------------------------
167 #endif //#define clitkImageIntensityWindowingGenericFilter_txx