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://oncora1.lyon.fnclcc.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 ======================================================================-====*/
19 #ifndef CLITKCONNECTEDCOMPONENTLABELINGSGENERICFILTER_TXX
20 #define CLITKCONNECTEDCOMPONENTLABELINGSGENERICFILTER_TXX
23 #include "clitkImageCommon.h"
26 #include "itkConnectedComponentImageFilter.h"
27 #include "itkRelabelComponentImageFilter.h"
29 //--------------------------------------------------------------------
30 template<class ArgsInfoType>
31 clitk::ConnectedComponentLabelingGenericFilter<ArgsInfoType>::ConnectedComponentLabelingGenericFilter():
32 ImageToImageGenericFilter<Self>("ConnectedComponentLabeling")
34 // InitializeImageType<2>();
35 InitializeImageType<3>();
36 //InitializeImageType<4>();
38 //--------------------------------------------------------------------
41 //--------------------------------------------------------------------
42 template<class ArgsInfoType>
43 template<unsigned int Dim>
44 void clitk::ConnectedComponentLabelingGenericFilter<ArgsInfoType>::InitializeImageType()
46 ADD_IMAGE_TYPE(Dim, uchar);
47 ADD_IMAGE_TYPE(Dim, short);
48 // ADD_IMAGE_TYPE(Dim, int);
49 // ADD_IMAGE_TYPE(Dim, float);
51 //--------------------------------------------------------------------
54 //--------------------------------------------------------------------
55 template<class ArgsInfoType>
56 void clitk::ConnectedComponentLabelingGenericFilter<ArgsInfoType>::SetArgsInfo(const ArgsInfoType & a)
59 SetIOVerbose(mArgsInfo.verbose_flag);
60 if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
61 if (mArgsInfo.input_given) AddInputFilename(mArgsInfo.input_arg);
62 if (mArgsInfo.output_given) SetOutputFilename(mArgsInfo.output_arg);
64 //--------------------------------------------------------------------
67 //--------------------------------------------------------------------
68 // Update with the number of dimensions and the pixeltype
69 //--------------------------------------------------------------------
70 template<class ArgsInfoType>
71 template<class ImageType>
72 void clitk::ConnectedComponentLabelingGenericFilter<ArgsInfoType>::UpdateWithInputImageType()
74 DD("UpdateWithInputImageType");
77 typename ImageType::Pointer input = this->template GetInput<ImageType>(0);
80 typedef itk::Image<int, ImageType::ImageDimension> OutputImageType;
84 typedef itk::ConnectedComponentImageFilter<ImageType, OutputImageType> ConnectFilterType;
85 typename ConnectFilterType::Pointer connectFilter = ConnectFilterType::New();
86 connectFilter->SetInput(input);
87 connectFilter->SetBackgroundValue(mArgsInfo.inputBG_arg);
88 connectFilter->SetFullyConnected(mArgsInfo.full_flag);
90 // TODO SetBackgroud to zero forr relabel ?
93 // Sort by size and remove too small area.
94 typedef itk::RelabelComponentImageFilter<OutputImageType, OutputImageType> RelabelFilterType;
95 typename RelabelFilterType::Pointer relabelFilter = RelabelFilterType::New();
96 // relabelFilter->InPlaceOn();
97 relabelFilter->SetInput(connectFilter->GetOutput());
98 relabelFilter->SetMinimumObjectSize(mArgsInfo.minSize_arg);
99 relabelFilter->Update();
101 DD(mArgsInfo.inputBG_arg);
102 DD(mArgsInfo.full_flag);
103 DD(mArgsInfo.minSize_arg);
106 const std::vector<typename RelabelFilterType::ObjectSizeType> & a = relabelFilter->GetSizeOfObjectsInPixels();
107 m_SizeOfObjectsInPixels.resize(a.size());
108 for(unsigned int i=0; i<a.size(); i++) m_SizeOfObjectsInPixels[i] = a[i];
109 m_SizeOfObjectsInPhysicalUnits = relabelFilter->GetSizeOfObjectsInPhysicalUnits();
110 m_OriginalNumberOfObjects = relabelFilter->GetOriginalNumberOfObjects();
111 DD(m_OriginalNumberOfObjects);
112 DD(m_SizeOfObjectsInPhysicalUnits.size());
114 // Write/Save results
115 typename OutputImageType::Pointer output = relabelFilter->GetOutput();
116 this->template SetNextOutput<OutputImageType>(output);
118 //--------------------------------------------------------------------
120 #endif //#define CLITKCONNECTEDCOMPONENTLABELINGSGENERICFILTER_TXX