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 CLITKRTSTRUCTSTATISTICSGENERICFILTER_TXX
19 #define CLITKRTSTRUCTSTATISTICSGENERICFILTER_TXX
21 #include "clitkImageCommon.h"
23 #include "itkConnectedComponentImageFilter.h"
24 #include "itkLabelImageToShapeLabelMapFilter.h"
29 //--------------------------------------------------------------------
30 template<class args_info_type>
31 RTStructStatisticsGenericFilter<args_info_type>::RTStructStatisticsGenericFilter()
32 :ImageToImageGenericFilter<Self>("RTStructStatisticsGenericFilter")
34 InitializeImageType<2>();
35 InitializeImageType<3>();
36 InitializeImageType<4>();
38 //--------------------------------------------------------------------
41 //--------------------------------------------------------------------
42 template<class args_info_type>
43 template<unsigned int Dim>
44 void RTStructStatisticsGenericFilter<args_info_type>::InitializeImageType()
46 ADD_DEFAULT_IMAGE_TYPES(Dim);
48 //--------------------------------------------------------------------
51 //--------------------------------------------------------------------
52 template<class args_info_type>
53 void RTStructStatisticsGenericFilter<args_info_type>::SetArgsInfo(const args_info_type & a)
58 this->SetIOVerbose(mArgsInfo.verbose_flag);
60 if (mArgsInfo.input_given) this->AddInputFilename(mArgsInfo.input_arg);
63 //--------------------------------------------------------------------
66 //--------------------------------------------------------------------
67 template<class args_info_type>
68 template<class ImageType>
69 void RTStructStatisticsGenericFilter<args_info_type>::UpdateWithInputImageType()
72 typedef itk::Image<unsigned char, ImageType::ImageDimension> MaskInputImageType;
73 typename MaskInputImageType::Pointer mask;
74 mask = this->template GetInput<MaskInputImageType>(0);
76 //Create the Shape Label Map from the mask
77 typedef itk::Image< unsigned char, ImageType::ImageDimension > OutputImageType;
78 typedef itk::ShapeLabelObject< unsigned char, ImageType::ImageDimension > ShapeLabelObjectType;
79 typedef itk::LabelMap< ShapeLabelObjectType > LabelMapType;
80 typedef itk::ConnectedComponentImageFilter <MaskInputImageType, OutputImageType > ConnectedComponentImageFilterType;
81 typedef itk::LabelImageToShapeLabelMapFilter< OutputImageType, LabelMapType> I2LType;
83 typename ConnectedComponentImageFilterType::Pointer connected = ConnectedComponentImageFilterType::New ();
84 connected->SetInput(mask);
85 connected->FullyConnectedOn();
88 //Create a map to contain all connectedComponent (even a little pixel)
89 typename I2LType::Pointer i2l = I2LType::New();
90 i2l->SetInput( connected->GetOutput() );
91 i2l->SetComputePerimeter(true);
94 // Retrieve the biggest component
95 LabelMapType *labelMap = i2l->GetOutput();
96 int largestComponent(0);
98 for (unsigned int n = 0; n < labelMap->GetNumberOfLabelObjects(); ++n)
100 ShapeLabelObjectType *labelObject = labelMap->GetNthLabelObject(n);
101 if (labelObject->GetNumberOfPixels() > nbPixel)
103 nbPixel = labelObject->GetNumberOfPixels();
104 largestComponent = n;
108 //Write statitistics on the largest component
109 ShapeLabelObjectType *labelObject = labelMap->GetNthLabelObject(largestComponent);
110 std::cout << " Centroid position (mm): " << std::endl;
111 std::cout << labelObject->GetCentroid()[0] << std::endl;
112 std::cout << labelObject->GetCentroid()[1] << std::endl;
113 std::cout << labelObject->GetCentroid()[2] << std::endl;
114 std::cout << " Roundness: " << std::endl;
115 std::cout << labelObject->GetRoundness() << std::endl;
118 //--------------------------------------------------------------------
124 #endif //#define CLITKRTSTRUCTSTATISTICSGENERICFILTER_TXX