21 #ifndef __otbStreamingImageToOGRLayerSegmentationFilter_txx
22 #define __otbStreamingImageToOGRLayerSegmentationFilter_txx
36 template <
class TImageType,
class TSegmentationFilter>
39 m_FilterSmallObject(false), m_MinimumObjectSize(1),m_Simplify(false), m_SimplificationTolerance(0.3)
41 this->SetNumberOfInputs(2);
42 this->SetNumberOfRequiredInputs(1);
43 m_SegmentationFilter = SegmentationFilterType::New();
47 template <
class TImageType,
class TSegmentationFilter>
53 template <
class TImageType,
class TSegmentationFilter>
61 template <
class TImageType,
class TSegmentationFilter>
71 template <
class TImageType,
class TSegmentationFilter>
83 typename ExtractImageFilterType::Pointer extract = ExtractImageFilterType::New();
84 extract->SetInput( this->GetInput() );
85 extract->SetExtractionRegion( this->GetInput()->GetRequestedRegion() );
89 extract->GetOutput()->SetMetaDataDictionary(this->GetInput()->GetMetaDataDictionary());
94 LabelImageToOGRDataSourceFilterType::New();
98 m_SegmentationFilter->SetInput(extract->GetOutput());
99 m_SegmentationFilter->UpdateLargestPossibleRegion();
106 typename LabelImageType::ConstPointer inputMask = this->GetInputMask();
107 if (!inputMask.IsNull())
111 typename ExtractLabelImageFilterType::Pointer maskExtract = ExtractLabelImageFilterType::New();
112 maskExtract->SetInput( this->GetInputMask() );
113 maskExtract->SetExtractionRegion( this->GetInputMask()->GetRequestedRegion() );
114 maskExtract->Update();
116 maskExtract->GetOutput()->SetMetaDataDictionary(this->GetInputMask()->GetMetaDataDictionary());
118 labelImageToOGRDataFilter->SetInputMask(maskExtract->GetOutput());
121 labelImageToOGRDataFilter->SetInput(dynamic_cast<LabelImageType *>(m_SegmentationFilter->GetOutputs().at(labelImageIndex).GetPointer()));
122 labelImageToOGRDataFilter->SetFieldName(m_FieldName);
123 labelImageToOGRDataFilter->SetUse8Connected(m_Use8Connected);
124 labelImageToOGRDataFilter->Update();
135 const typename InputImageType::SpacingType inSpacing = this->GetInput()->GetSpacing();
136 const double tol = m_SimplificationTolerance * std::max(vcl_abs(inSpacing[0]),vcl_abs(inSpacing[1]));
139 for(featIt = tmpLayer.
begin(); featIt!=tmpLayer.
end(); ++featIt)
149 const OGRGeometry *
geom = (*featIt).GetGeometry();
150 assert(geom &&
"geometry is NULL ! Can't simplify it.");
158 if(m_FilterSmallObject)
160 double area =
static_cast<const OGRPolygon *
>((*featIt).GetGeometry())->get_Area();
162 typename InputImageType::SpacingType spacing = this->GetInput()->GetSpacing();
163 double pixelsArea = area / (vcl_abs(spacing[0]*spacing[1]));
165 if( pixelsArea < m_MinimumObjectSize )
172 otbMsgDebugMacro(<<
"relabeling, filtering small objects and simplifying geometries took " << chrono3.GetTotal() <<
" sec");