Commit 86531eba authored by Sebastien Harasse's avatar Sebastien Harasse

ENH: Mean shift. Changing internal image calculation in...

ENH: Mean shift. Changing internal image calculation in BeforeThreadedGenerateData to a functor filter
for multithreading support.
parent 66306721
......@@ -27,6 +27,52 @@
namespace otb
{
template<class TInputImage, class TOutputJointImage>
class SpatialRangeJointDomainTransform
{
public:
typedef double RealType;
SpatialRangeJointDomainTransform() {}
~SpatialRangeJointDomainTransform() {}
inline typename TOutputJointImage::PixelType operator() (const typename TInputImage::PixelType & inputPixel, const typename TInputImage::IndexType & index)
{
typename TOutputJointImage::PixelType jointPixel;
jointPixel.SetSize(ImageDimension + m_NumberOfComponentsPerPixel);
for(unsigned int comp = 0; comp < ImageDimension; comp++)
{
jointPixel[comp] = index[comp] / m_SpatialBandwidth;
}
for(unsigned int comp = 0; comp < m_NumberOfComponentsPerPixel; comp++)
{
jointPixel[ImageDimension + comp] = inputPixel[comp] / m_RangeBandwidth;
}
return jointPixel;
}
void Initialize(unsigned int _ImageDimension, unsigned int _m_NumberOfComponentsPerPixel, RealType _m_SpatialBandwidth, RealType _m_RangeBandwidth)
{
ImageDimension = _ImageDimension;
m_NumberOfComponentsPerPixel = _m_NumberOfComponentsPerPixel;
m_SpatialBandwidth = _m_SpatialBandwidth;
m_RangeBandwidth = _m_RangeBandwidth;
m_OutputSize = ImageDimension + m_NumberOfComponentsPerPixel;
}
unsigned int GetOutputSize()
{
return m_OutputSize;
}
private:
unsigned int ImageDimension;
unsigned int m_NumberOfComponentsPerPixel;
unsigned int m_OutputSize;
RealType m_SpatialBandwidth;
RealType m_RangeBandwidth;
};
/** \class MeanShiftImageFilter2
*
......
......@@ -23,6 +23,7 @@
#include "itkImageRegionConstIteratorWithIndex.h"
#include "itkImageRegionIterator.h"
#include "otbUnaryFunctorWithIndexWithOutputSizeImageFilter.h"
#include "otbMacro.h"
#include "itkProgressReporter.h"
......@@ -293,6 +294,18 @@ MeanShiftImageFilter2<TInputImage, TOutputImage, TKernel, TNorm, TOutputMetricIm
m_NumberOfComponentsPerPixel = this->GetInput()->GetNumberOfComponentsPerPixel();
typedef SpatialRangeJointDomainTransform<InputImageType, RealVectorImageType> FunctionType;
typedef otb::UnaryFunctorWithIndexWithOutputSizeImageFilter<InputImageType, RealVectorImageType, FunctionType> JointImageFunctorType;
typename JointImageFunctorType::Pointer jointImageFunctor = JointImageFunctorType::New();
jointImageFunctor->SetInput(inputPtr);
jointImageFunctor->GetFunctor().Initialize(ImageDimension, m_NumberOfComponentsPerPixel, m_SpatialBandwidth, m_RangeBandwidth);
jointImageFunctor->Update();
m_JointImage = jointImageFunctor->GetOutput();
/*
// Allocate the joint domain image
m_JointImage = RealVectorImageType::New();
m_JointImage->SetNumberOfComponentsPerPixel(ImageDimension + m_NumberOfComponentsPerPixel);
......@@ -325,7 +338,7 @@ MeanShiftImageFilter2<TInputImage, TOutputImage, TKernel, TNorm, TOutputMetricIm
++inputIt;
++jointIt;
}
*/
}
......
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