Skip to content
Snippets Groups Projects
Commit 010ea021 authored by Yannick TANGUY's avatar Yannick TANGUY
Browse files

REFAC : replaces the UnaryImageFunctor with the new FunctorFilter (apply log...

REFAC : replaces the UnaryImageFunctor with the new FunctorFilter (apply log function to the input image)
parent 8aa9f900
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "otbWrapperApplicationFactory.h" #include "otbWrapperApplicationFactory.h"
#include "otbVectorRescaleIntensityImageFilter.h" #include "otbVectorRescaleIntensityImageFilter.h"
#include "otbUnaryImageFunctorWithVectorImageFilter.h" #include "otbFunctorImageFilter.h"
#include "otbStreamingShrinkImageFilter.h" #include "otbStreamingShrinkImageFilter.h"
#include "itkListSample.h" #include "itkListSample.h"
#include "otbListSampleToHistogramListGenerator.h" #include "otbListSampleToHistogramListGenerator.h"
...@@ -39,22 +39,6 @@ namespace otb ...@@ -39,22 +39,6 @@ namespace otb
namespace Wrapper 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 class Convert : public Application
{ {
public: public:
...@@ -77,11 +61,6 @@ public: ...@@ -77,11 +61,6 @@ public:
DFContainerType> HistogramsGeneratorType; DFContainerType> HistogramsGeneratorType;
typedef StreamingShrinkImageFilter<FloatVectorImageType, typedef StreamingShrinkImageFilter<FloatVectorImageType,
FloatVectorImageType> ShrinkFilterType; FloatVectorImageType> ShrinkFilterType;
typedef Functor::LogFunctor<FloatVectorImageType::InternalPixelType> TransferLogFunctor;
typedef UnaryImageFunctorWithVectorImageFilter<FloatVectorImageType,
FloatVectorImageType,
TransferLogFunctor> TransferLogType;
private: private:
...@@ -293,22 +272,35 @@ private: ...@@ -293,22 +272,35 @@ private:
if ( rescaleType == "log2") if ( rescaleType == "log2")
{ {
//define the transfer log // define lambda function that applies a log to all bands of the input pixel
m_TransferLog = TransferLogType::New(); auto logFunction = [](const FloatVectorImageType::PixelType & vectorIn) {
m_TransferLog->SetInput(tempImage); FloatVectorImageType::PixelType vectorOut(vectorIn.Size());
m_TransferLog->UpdateOutputInformation();
for (unsigned int i = 0; i < vectorIn.Size() ; i++) {
shrinkFilter->SetInput(m_TransferLog->GetOutput()); vectorOut[i] = std::log(vectorIn[i]);
rescaler->SetInput(m_TransferLog->GetOutput()); }
shrinkFilter->Update(); 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 else
{ {
shrinkFilter->SetInput(tempImage); shrinkFilter->SetInput(tempImage);
rescaler->SetInput(tempImage); rescaler->SetInput(tempImage);
shrinkFilter->Update(); shrinkFilter->Update();
} }
ShrinkFilterType::Pointer maskShrinkFilter = ShrinkFilterType::New(); ShrinkFilterType::Pointer maskShrinkFilter = ShrinkFilterType::New();
otbAppLogDEBUG( << "Evaluating input Min/Max..." ); otbAppLogDEBUG( << "Evaluating input Min/Max..." );
...@@ -517,7 +509,6 @@ private: ...@@ -517,7 +509,6 @@ private:
} }
} }
TransferLogType::Pointer m_TransferLog;
std::vector<itk::LightObject::Pointer> m_Filters; std::vector<itk::LightObject::Pointer> m_Filters;
}; };
......
...@@ -38,6 +38,7 @@ otb_module(OTBAppImageUtils ...@@ -38,6 +38,7 @@ otb_module(OTBAppImageUtils
OTBStatistics OTBStatistics
OTBStreaming OTBStreaming
OTBTransform OTBTransform
OTBFunctor
TEST_DEPENDS TEST_DEPENDS
OTBCommandLine OTBCommandLine
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment