From febd870c3ea07de9b04917fd291759276b71d75c Mon Sep 17 00:00:00 2001 From: remi <remi.cresson@irstea.fr> Date: Fri, 28 Jun 2019 09:25:09 +0000 Subject: [PATCH] ENH: clip output to moving image roi --- app/otbSuperSuperimpose.cxx | 33 ++++++++++++++++++++++++--------- otb-module.cmake | 1 + 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/otbSuperSuperimpose.cxx b/app/otbSuperSuperimpose.cxx index c10db9e..e501692 100644 --- a/app/otbSuperSuperimpose.cxx +++ b/app/otbSuperSuperimpose.cxx @@ -10,11 +10,14 @@ =========================================================================*/ #include "otbWrapperApplicationFactory.h" -#include "otbGridResampleImageFilter.h" +#include "otbStreamingResampleImageFilter.h" #include "otbBCOInterpolateImageFunction.h" #include "itkNearestNeighborInterpolateImageFunction.h" +#include "otbRegionComparator.h" +#include "otbMultiChannelExtractROI.h" + namespace otb { @@ -45,8 +48,8 @@ public: typedef itk::LinearInterpolateImageFunction<FloatVectorImageType, double> LinInterpolatorType; typedef itk::NearestNeighborInterpolateImageFunction<FloatVectorImageType, double> NNInterpolatorType; typedef otb::BCOInterpolateImageFunction<FloatVectorImageType> BCOInterpolatorType; - - typedef otb::GridResampleImageFilter<FloatVectorImageType, FloatVectorImageType> BasicResamplerType; + typedef otb::MultiChannelExtractROI<FloatVectorImageType::InternalPixelType,FloatVectorImageType::InternalPixelType> ExtractROIFilterType; + typedef otb::StreamingResampleImageFilter<FloatVectorImageType, FloatVectorImageType> BasicResamplerType; private: void DoInit() override @@ -111,13 +114,13 @@ private: } void DoUpdateParameters() override - { + { - } + } void DoExecute() override - { + { // Get the inputs FloatVectorImageType* refImage = GetParameterImage("inr"); FloatVectorImageType* movingImage = GetParameterImage("inm"); @@ -173,13 +176,25 @@ private: m_BasicResampler->SetOutputSize(size); m_BasicResampler->SetOutputStartIndex(start); m_BasicResampler->SetEdgePaddingValue(defaultValue); + m_BasicResampler->UpdateOutputInformation(); + + // Keep only overlap + otb::RegionComparator<FloatVectorImageType, FloatVectorImageType> comparator; + comparator.SetImage1(m_BasicResampler->GetOutput()); + comparator.SetImage2(movingImage); + + // Initialize ROI extract filters + m_ExtractROI = ExtractROIFilterType::New(); + m_ExtractROI->SetInput(m_BasicResampler->GetOutput()); + m_ExtractROI->SetExtractionRegion(comparator.GetOverlapInImage1Indices()); // Set the output image - SetParameterOutputImage("out", m_BasicResampler->GetOutput()); + SetParameterOutputImage("out", m_ExtractROI->GetOutput()); - } - BasicResamplerType::Pointer m_BasicResampler; + } + BasicResamplerType::Pointer m_BasicResampler; + ExtractROIFilterType::Pointer m_ExtractROI; }; } // end namespace Wrapper diff --git a/otb-module.cmake b/otb-module.cmake index f4bf8de..55409d1 100644 --- a/otb-module.cmake +++ b/otb-module.cmake @@ -7,6 +7,7 @@ otb_module(MLUtils OTBApplicationEngine Mosaic SimpleExtractionTools + OTBProjection TEST_DEPENDS OTBTestKernel -- GitLab