Skip to content
Snippets Groups Projects
Commit 49964234 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) in otbDynamicConvert
parent 010ea021
No related branches found
No related tags found
No related merge requests found
...@@ -273,13 +273,13 @@ private: ...@@ -273,13 +273,13 @@ private:
if ( rescaleType == "log2") if ( rescaleType == "log2")
{ {
// define lambda function that applies a log to all bands of the input pixel // define lambda function that applies a log to all bands of the input pixel
auto logFunction = [](const FloatVectorImageType::PixelType & vectorIn) { auto logFunction = [](FloatVectorImageType::PixelType & vectorOut, const FloatVectorImageType::PixelType & vectorIn) {
FloatVectorImageType::PixelType vectorOut(vectorIn.Size()); assert(vectorOut.Size() == vectorIn.Size() && "Input vector types don't have the same size");
for (unsigned int i = 0; i < vectorIn.Size() ; i++) { for (unsigned int i = 0; i < vectorIn.Size() ; i++) {
vectorOut[i] = std::log(vectorIn[i]); vectorOut[i] = std::log(vectorIn[i]);
} }
return vectorOut;
}; };
// creates functor filter // creates functor filter
auto transferLogFilter = NewFunctorFilter(logFunction,tempImage->GetNumberOfComponentsPerPixel(),{{0,0}}); auto transferLogFilter = NewFunctorFilter(logFunction,tempImage->GetNumberOfComponentsPerPixel(),{{0,0}});
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,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,20 +39,6 @@ namespace otb ...@@ -39,20 +39,6 @@ namespace otb
namespace Wrapper 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 class DynamicConvert : public Application
{ {
...@@ -80,11 +66,6 @@ public: ...@@ -80,11 +66,6 @@ public:
typedef StreamingShrinkImageFilter<UInt8ImageType, UInt8ImageType> UInt8ShrinkFilterType; typedef StreamingShrinkImageFilter<UInt8ImageType, UInt8ImageType> UInt8ShrinkFilterType;
typedef Functor::LogFunctor<FloatVectorImageType::InternalPixelType> TransferLogFunctor;
typedef UnaryImageFunctorWithVectorImageFilter<FloatVectorImageType,
FloatVectorImageType,
TransferLogFunctor> TransferLogType;
private: private:
void DoInit() override void DoInit() override
...@@ -273,13 +254,26 @@ private: ...@@ -273,13 +254,26 @@ 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 = [](FloatVectorImageType::PixelType & vectorOut, const FloatVectorImageType::PixelType & vectorIn) {
m_TransferLog->SetInput(tempImage); assert(vectorOut.Size() == vectorIn.Size() && "Input vector types don't have the same 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()); }
};
// 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(); shrinkFilter->Update();
} }
else else
...@@ -524,8 +518,6 @@ private: ...@@ -524,8 +518,6 @@ private:
} }
} }
itk::ProcessObject::Pointer m_TmpFilter;
TransferLogType::Pointer m_TransferLog;
std::vector<itk::LightObject::Pointer> m_Filters; std::vector<itk::LightObject::Pointer> m_Filters;
}; };
......
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