Commit 3426d050 authored by remi cresson's avatar remi cresson
Browse files

ADD: new functor (SlopeAndPValueLabelingFunctor)

parent 8c69473e
......@@ -22,6 +22,12 @@ namespace otb
namespace functor
{
/*
* \class SingleDate
*
* \brief Class to handle dates. Julian day is computed at instantiation.
*
*/
class SingleDate
{
public:
......@@ -65,6 +71,7 @@ public:
/**
* \class TSReduceFunctorBase
*
* \brief Base class for reducing N-components pixel into M-component pixel (N=nb. of images and M=nb. of years)
*
* Dates must be provided in chronological order, else the "SetDates()" method will throw an exception.
......@@ -119,8 +126,10 @@ private:
/**
* \class TSReduceFromRangeFunctor
*
* \brief Class for reducing N-components pixel into M-component pixel (N=nb. of images and M=nb. of years)
* given a range (dd/mm--->dd'/mm')
*
*/
template< class TInputPixel, class TOutputPixel>
class TSReduceFromRangeFunctor : TSReduceFunctorBase<TInputPixel,TOutputPixel>
......@@ -186,6 +195,17 @@ int m_Month2;
}; // TSReduceFromRangeFunctor
/**
* \class SlopeAndPValueFunctor
*
* \brief Class for computing the slope and the p-value from an input sample (pixel)
*
* The functor returns an output pixel of dimension 3 with:
* outputPixel[0] : slope (ordinary least square regression)
* outputPixel[1] : p-value (student coefficient)
* outputPixel[2] : correlation (linear pearson correlation coefficient)
*
*/
template< class TInputPixel, class TOutputPixel>
class SlopeAndPValueFunctor
{
......@@ -194,18 +214,32 @@ public:
typedef typename TInputPixel::ValueType InputPixelValueType;
typedef typename TOutputPixel::ValueType OutputPixelValueType;
SlopeAndPValueFunctor(){}
// Constructor
SlopeAndPValueFunctor()
{
/*
* The number of components for the output pixel is 3 (slope, p-value, correlation)
*/
numberOfComponentsPerPixel = 3;
}
// Destructor
~SlopeAndPValueFunctor(){}
// Purposely not implemented
bool operator!=( const SlopeAndPValueFunctor & ) const { return false; }
bool operator==( const SlopeAndPValueFunctor & other ) const { return !(*this != other); }
inline unsigned int GetOutputSize(){ return 2; }
// Get output size
inline unsigned int GetOutputSize(){ return numberOfComponentsPerPixel; }
// Compute output pixel
inline TOutputPixel operator ()(const TInputPixel& input) const
{
TOutputPixel outpixel;
outpixel.SetSize(2);
outpixel.Fill(0);
outpixel.SetSize(numberOfComponentsPerPixel);
outpixel.Fill(m_OutputNoDataValue);
// compute sum & sum of squares
unsigned int n = input.Size();
......@@ -273,6 +307,7 @@ public:
// output pixel
outpixel[0] = slope;
outpixel[1] = pvalue;
outpixel[2] = correlation;
}
return outpixel;
......@@ -282,9 +317,133 @@ public:
void SetInputNoDataValue(InputPixelValueType value) { m_InputNoDataValue = value; }
InputPixelValueType GetInputNoDataValue(){ return m_InputNoDataValue; }
/* Set / Get output no-data value */
void SetOutputNoDataValue(OutputPixelValueType value) { m_OutputNoDataValue = value; }
InputPixelValueType GetOutputNoDataValue(){ return m_OutputNoDataValue; }
protected:
InputPixelValueType m_InputNoDataValue;
OutputPixelValueType m_OutputNoDataValue;
unsigned int numberOfComponentsPerPixel;
}; // SlopeAndPValueFunctor
/**
* \class SlopeAndPValueLabelingFunctor
*
* \brief Class for computing the label corresponding to an input slope and p-value
*
*/
template< class TInputPixel, class TLabelPixel>
class SlopeAndPValueLabelingFunctor
{
public:
enum Def
{
VeryStrongNeg,
StrongNeg,
ModerateNeg,
VeryStrongPos,
StrongPos,
ModeratePos,
NoSignificant
};
typedef typename TInputPixel::ValueType InputPixelValueType;
typedef typename TLabelPixel::ValueType LabelPixelValueType;
// Constructor
SlopeAndPValueLabelingFunctor()
{
numberOfComponentsPerPixel = 1;
}
// Destructor
~SlopeAndPValueLabelingFunctor(){}
// Purposely not implemented
bool operator!=( const SlopeAndPValueLabelingFunctor & ) const { return false; }
bool operator==( const SlopeAndPValueLabelingFunctor & other ) const { return !(*this != other); }
// Get output size
inline unsigned int GetOutputSize(){ return numberOfComponentsPerPixel; }
// Compute output pixel
inline TLabelPixel operator ()(const TInputPixel& input) const
{
// Prepare output pixel
TLabelPixel label;
label.SetSize(numberOfComponentsPerPixel);
label.Fill(m_OutputNoDataValue);
// Get slope and p-value
InputPixelValueType slope = input[0];
InputPixelValueType pvalue = input[1];
if (slope != m_InputNoDataValue && pvalue != m_InputNoDataValue)
{
if (slope < 0)
{
// Slope is negative
if (pvalue <= 0.001)
{
label[0] = static_cast<LabelPixelValueType>(VeryStrongNeg);
}
else if (0.001 < pvalue && pvalue <= 0.01)
{
label[0] = static_cast<LabelPixelValueType>(StrongNeg);
}
else if (0.01 < pvalue && pvalue <= 0.05)
{
label[0] = static_cast<LabelPixelValueType>(ModerateNeg);
}
else
{
label[0] = static_cast<LabelPixelValueType>(NoSignificant);
}
}
else
{
// Slope is positive
if (pvalue <= 0.001)
{
label[0] = static_cast<LabelPixelValueType>(VeryStrongPos);
}
else if (0.001 < pvalue && pvalue <= 0.01)
{
label[0] = static_cast<LabelPixelValueType>(StrongPos);
}
else if (0.01 < pvalue && pvalue <= 0.05)
{
label[0] = static_cast<LabelPixelValueType>(ModeratePos);
}
else
{
label[0] = static_cast<LabelPixelValueType>(NoSignificant);
}
}
}
return label;
}
/* Set / Get input no-data value */
void SetInputNoDataValue(InputPixelValueType value) { m_InputNoDataValue = value; }
InputPixelValueType GetInputNoDataValue(){ return m_InputNoDataValue; }
/* Set / Get output no-data value */
void SetOutputNoDataValue(LabelPixelValueType value) { m_OutputNoDataValue = value; }
InputPixelValueType GetOutputNoDataValue(){ return m_OutputNoDataValue; }
protected:
InputPixelValueType m_InputNoDataValue;
LabelPixelValueType m_OutputNoDataValue;
unsigned int numberOfComponentsPerPixel;
};
} // namespace functor
} // namespace otb
......
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