diff --git a/Modules/Applications/AppImageUtils/app/otbConvert.cxx b/Modules/Applications/AppImageUtils/app/otbConvert.cxx index 41619d099161c66c556202025d93dc2403cf5898..5ae06486214b1936298388e31be9bb09c60bae5e 100644 --- a/Modules/Applications/AppImageUtils/app/otbConvert.cxx +++ b/Modules/Applications/AppImageUtils/app/otbConvert.cxx @@ -24,7 +24,7 @@ #include "otbWrapperApplicationFactory.h" #include "otbVectorRescaleIntensityImageFilter.h" -#include "otbUnaryImageFunctorWithVectorImageFilter.h" +#include "otbFunctorImageFilter.h" #include "otbStreamingShrinkImageFilter.h" #include "itkListSample.h" #include "otbListSampleToHistogramListGenerator.h" @@ -39,22 +39,6 @@ namespace otb namespace Wrapper { -namespace Functor -{ -template< class TScalar > -class ITK_EXPORT LogFunctor -{ -public: - LogFunctor(){}; - ~LogFunctor(){}; - TScalar operator() (const TScalar& v) const - { - return std::log(v); - } -}; -} // end namespace Functor - - class Convert : public Application { public: @@ -77,11 +61,6 @@ public: DFContainerType> HistogramsGeneratorType; typedef StreamingShrinkImageFilter<FloatVectorImageType, FloatVectorImageType> ShrinkFilterType; - typedef Functor::LogFunctor<FloatVectorImageType::InternalPixelType> TransferLogFunctor; - typedef UnaryImageFunctorWithVectorImageFilter<FloatVectorImageType, - FloatVectorImageType, - TransferLogFunctor> TransferLogType; - private: @@ -293,22 +272,35 @@ private: if ( rescaleType == "log2") { - //define the transfer log - m_TransferLog = TransferLogType::New(); - m_TransferLog->SetInput(tempImage); - m_TransferLog->UpdateOutputInformation(); - - shrinkFilter->SetInput(m_TransferLog->GetOutput()); - rescaler->SetInput(m_TransferLog->GetOutput()); - shrinkFilter->Update(); + // define lambda function that applies a log to all bands of the input pixel + auto logFunction = [](const FloatVectorImageType::PixelType & vectorIn) { + FloatVectorImageType::PixelType vectorOut(vectorIn.Size()); + + for (unsigned int i = 0; i < vectorIn.Size() ; i++) { + vectorOut[i] = std::log(vectorIn[i]); + } + return vectorOut; + }; + // creates functor filter + auto transferLogFilter = NewFunctorFilter(logFunction,tempImage->GetNumberOfComponentsPerPixel(),{{0,0}}); + + // save a reference to the functor + m_Filters.push_back(transferLogFilter.GetPointer()); + + transferLogFilter->SetVariadicInputs(tempImage); + transferLogFilter->UpdateOutputInformation(); + + shrinkFilter->SetInput(transferLogFilter->GetOutput()); + rescaler->SetInput(transferLogFilter->GetOutput()); + shrinkFilter->Update(); } else { - shrinkFilter->SetInput(tempImage); - rescaler->SetInput(tempImage); - shrinkFilter->Update(); + shrinkFilter->SetInput(tempImage); + rescaler->SetInput(tempImage); + shrinkFilter->Update(); } - + ShrinkFilterType::Pointer maskShrinkFilter = ShrinkFilterType::New(); otbAppLogDEBUG( << "Evaluating input Min/Max..." ); @@ -517,7 +509,6 @@ private: } } - TransferLogType::Pointer m_TransferLog; std::vector<itk::LightObject::Pointer> m_Filters; }; diff --git a/Modules/Applications/AppImageUtils/otb-module.cmake b/Modules/Applications/AppImageUtils/otb-module.cmake index 6b378f1f31adc8b54cab8249c2ec2a95f208de00..fa60474ae7c69ef15ed3ebc03a1bc8939ec346af 100644 --- a/Modules/Applications/AppImageUtils/otb-module.cmake +++ b/Modules/Applications/AppImageUtils/otb-module.cmake @@ -38,6 +38,7 @@ otb_module(OTBAppImageUtils OTBStatistics OTBStreaming OTBTransform + OTBFunctor TEST_DEPENDS OTBCommandLine