21 #ifndef otbStreamingConnectedComponentSegmentationOBIAToVectorDataFilter_hxx
22 #define otbStreamingConnectedComponentSegmentationOBIAToVectorDataFilter_hxx
26 #include "itkAffineTransform.h"
31 template <
class TVImage,
class TLabelImage,
class TMaskImage,
class TOutputVectorData>
32 PersistentConnectedComponentSegmentationOBIAToVectorDataFilter<TVImage, TLabelImage, TMaskImage,
34 : m_MinimumObjectSize(2),
35 m_ShapeReducedSetOfAttributes(false),
36 m_StatsReducedSetOfAttributes(false),
37 m_ComputeFlusser(false),
38 m_ComputePolygon(false),
39 m_ComputeFeretDiameter(false),
40 m_ComputePerimeter(false)
44 template <
class TVImage,
class TLabelImage,
class TMaskImage,
class TOutputVectorData>
46 TOutputVectorData>::~PersistentConnectedComponentSegmentationOBIAToVectorDataFilter()
50 template <
class TVImage,
class TLabelImage,
class TMaskImage,
class TOutputVectorData>
53 Superclass::GenerateInputRequestedRegion();
56 template <
class TVImage,
class TLabelImage,
class TMaskImage,
class TOutputVectorData>
61 typename ExtractImageFilterType::Pointer extract = ExtractImageFilterType::New();
62 extract->SetInput(this->GetInput());
63 extract->SetExtractionRegion(this->GetOutput()->GetRequestedRegion());
66 typename MaskImageType::Pointer mask;
67 if (!m_MaskExpression.empty())
71 maskFilter = MaskMuParserFilterType::New();
72 maskFilter->SetInput(extract->GetOutput());
73 maskFilter->SetExpression(m_MaskExpression);
75 mask = maskFilter->GetOutput();
79 typename ConnectedComponentFilterType::Pointer connected = ConnectedComponentFilterType::New();
80 connected->SetInput(extract->GetOutput());
83 connected->SetMaskImage(mask);
84 connected->GetFunctor().SetExpression(m_ConnectedComponentExpression);
88 typename RelabelComponentFilterType::Pointer relabel = RelabelComponentFilterType::New();
89 relabel->SetInput(connected->GetOutput());
90 relabel->SetMinimumObjectSize(m_MinimumObjectSize);
96 labelImageToLabelMap->SetInput(relabel->GetOutput());
97 labelImageToLabelMap->SetBackgroundValue(0);
98 labelImageToLabelMap->Update();
102 if (!m_OBIAExpression.empty())
106 shapeLabelMapFilter->SetInput(labelImageToLabelMap->GetOutput());
107 shapeLabelMapFilter->SetReducedAttributeSet(m_ShapeReducedSetOfAttributes);
108 shapeLabelMapFilter->SetComputePolygon(m_ComputePolygon);
109 shapeLabelMapFilter->SetComputePerimeter(m_ComputePerimeter);
110 shapeLabelMapFilter->SetComputeFeretDiameter(m_ComputeFeretDiameter);
111 shapeLabelMapFilter->SetComputeFlusser(m_ComputeFlusser);
115 radiometricLabelMapFilter->SetInput(shapeLabelMapFilter->GetOutput());
116 radiometricLabelMapFilter->SetFeatureImage(extract->GetOutput());
117 radiometricLabelMapFilter->SetReducedAttributeSet(m_StatsReducedSetOfAttributes);
121 opening->SetExpression(m_OBIAExpression);
122 opening->SetInput(radiometricLabelMapFilter->GetOutput());
125 labelMap = opening->GetOutput();
130 labelMapToVectorDataFilter->SetInput(labelMap);
131 labelMapToVectorDataFilter->Update();
138 typedef itk::AffineTransform<typename VectorDataType::PrecisionType, 2> TransformType;
141 typename TransformType::ParametersType params;
143 params[0] = this->GetInput()->GetSignedSpacing()[0];
146 params[3] = this->GetInput()->GetSignedSpacing()[1];
147 params[4] = this->GetInput()->GetOrigin()[0];
148 params[5] = this->GetInput()->GetOrigin()[1];
150 typename TransformType::Pointer transform = TransformType::New();
151 transform->SetParameters(params);
153 typename VDTransformType::Pointer vdTransform = VDTransformType::New();
154 vdTransform->SetTransform(transform);
155 vdTransform->SetInput(labelMapToVectorDataFilter->GetOutput());
156 vdTransform->Update();
157 vdTransform->GetOutput()->SetProjectionRef(this->GetInput()->GetProjectionRef());
159 return vdTransform->GetOutput();