Commit cfefa67f authored by Julien Michel's avatar Julien Michel

Merge branch 'use_Functor_Filter_in_AppImageUtils' into 'develop'

Use functor filter in app image utils

See merge request !319
parents 527439d3 d6a9b0d3
......@@ -22,7 +22,7 @@
#include "otbWrapperApplicationFactory.h"
#include "otbVectorRescaleIntensityImageFilter.h"
#include "otbUnaryImageFunctorWithVectorImageFilter.h"
#include "otbFunctorImageFilter.h"
#include "otbStreamingShrinkImageFilter.h"
#include "itkListSample.h"
#include "otbListSampleToHistogramListGenerator.h"
......@@ -39,20 +39,6 @@ namespace otb
namespace Wrapper
{
namespace Functor
{
template< class TScalar >
class ITK_EXPORT LogFunctor
{
public:
TScalar operator() (const TScalar& v) const
{
return std::log(v);
}
};
} // end namespace Functor
class DynamicConvert : public Application
{
......@@ -80,11 +66,6 @@ public:
typedef StreamingShrinkImageFilter<UInt8ImageType, UInt8ImageType> UInt8ShrinkFilterType;
typedef Functor::LogFunctor<FloatVectorImageType::InternalPixelType> TransferLogFunctor;
typedef UnaryImageFunctorWithVectorImageFilter<FloatVectorImageType,
FloatVectorImageType,
TransferLogFunctor> TransferLogType;
private:
void DoInit() override
......@@ -277,13 +258,26 @@ 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());
// define lambda function that applies a log to all bands of the input pixel
auto logFunction = [](FloatVectorImageType::PixelType & vectorOut, const FloatVectorImageType::PixelType & vectorIn) {
assert(vectorOut.Size() == vectorIn.Size() && "Input vector types don't have the same size");
for (unsigned int i = 0; i < vectorIn.Size() ; i++) {
vectorOut[i] = std::log(vectorIn[i]);
}
};
// 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
......@@ -528,8 +522,6 @@ private:
}
}
itk::ProcessObject::Pointer m_TmpFilter;
TransferLogType::Pointer m_TransferLog;
std::vector<itk::LightObject::Pointer> m_Filters;
};
......
......@@ -38,6 +38,7 @@ otb_module(OTBAppImageUtils
OTBStatistics
OTBStreaming
OTBTransform
OTBFunctor
TEST_DEPENDS
OTBCommandLine
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment