From aacab78dce8db9842fc2f4f57e13cfb5ed96aeb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Traizet?= <cedric.traizet@c-s.fr> Date: Thu, 4 Jun 2020 11:04:46 +0200 Subject: [PATCH] ENH: copy band metadata from input to output in filters --- .../include/otbInnerProductPCAImageFilter.hxx | 4 ++++ .../ImageManipulation/include/otbPerBandVectorImageFilter.hxx | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Modules/Filtering/DimensionalityReduction/include/otbInnerProductPCAImageFilter.hxx b/Modules/Filtering/DimensionalityReduction/include/otbInnerProductPCAImageFilter.hxx index 86f192d058..a3db4b8178 100644 --- a/Modules/Filtering/DimensionalityReduction/include/otbInnerProductPCAImageFilter.hxx +++ b/Modules/Filtering/DimensionalityReduction/include/otbInnerProductPCAImageFilter.hxx @@ -53,6 +53,10 @@ void InnerProductPCAImageFilter<TInputImage, TOutputImage>::GenerateOutputInform this->GetOutput()->SetNumberOfComponentsPerPixel(m_NumberOfPrincipalComponentsRequired); else this->GetOutput()->SetNumberOfComponentsPerPixel(m_NumberOfPrincipalComponentsRequired + 1); + + // Band specific metadatas are not kept in the reduced space. + this->GetOutput()->SetBandImageMetadata( + ImageMetadata::ImageMetadataBandsType(this->GetOutput()->GetNumberOfComponentsPerPixel())); } /** diff --git a/Modules/Filtering/ImageManipulation/include/otbPerBandVectorImageFilter.hxx b/Modules/Filtering/ImageManipulation/include/otbPerBandVectorImageFilter.hxx index 4cfe11e021..89ec1e7818 100644 --- a/Modules/Filtering/ImageManipulation/include/otbPerBandVectorImageFilter.hxx +++ b/Modules/Filtering/ImageManipulation/include/otbPerBandVectorImageFilter.hxx @@ -48,6 +48,9 @@ void PerBandVectorImageFilter<TInputImage, TOutputImage, TFilter>::GenerateOutpu m_Filter->UpdateOutputInformation(); this->GetOutput()->CopyInformation(m_Filter->GetOutput(m_OutputIndex)); this->GetOutput()->SetNumberOfComponentsPerPixel(this->GetInput()->GetNumberOfComponentsPerPixel()); + + // Override default metadata copying behavior and copy all metadata from input to output. + this->GetOutput()->SetImageMetadata(this->GetInput()->GetImageMetadata()); } } -- GitLab