21 #ifndef otbMRFEnergy_h
22 #define otbMRFEnergy_h
24 #include "itkConstNeighborhoodIterator.h"
25 #include "itkObject.h"
42 template <
class TInput1,
class TInput2>
65 itkSetMacro(NumberOfParameters,
unsigned int);
66 itkGetConstMacro(NumberOfParameters,
unsigned int);
71 return this->m_Parameters;
76 if (parameters.Size() != m_NumberOfParameters)
78 itkExceptionMacro(<<
"Invalid number of parameters");
80 m_Parameters = parameters;
86 itkExceptionMacro(<<
"GetSingleValue() has to be declared in child classes.");
91 return GetSingleValue(value1, value2);
97 unsigned int centerIndex = it.GetCenterNeighborhoodIndex();
99 bool isInside =
false;
100 unsigned int insideNeighbors = 0;
101 for (
unsigned long pos = 0; pos < it.Size(); ++pos)
103 if (pos != centerIndex)
105 value1 = it.GetPixel(pos, isInside);
108 result += GetSingleValue(value1, value2);
113 return result / insideNeighbors;
119 unsigned int centerIndex = it.GetCenterNeighborhoodIndex();
121 bool isInside =
false;
122 unsigned int insideNeighbors = 0;
123 for (
unsigned long pos = 0; pos < it.Size(); ++pos)
125 if (pos != centerIndex)
127 value1 = it.GetPixel(pos, isInside);
130 result += GetSingleValue(value1, value2);
135 return result / insideNeighbors;
140 MRFEnergy() : m_NumberOfParameters(1), m_Parameters(0){};
148 template <
class TInput2>
149 class ITK_EXPORT
MRFEnergy<TInput2, TInput2> :
public itk::Object
167 itkSetMacro(NumberOfParameters,
unsigned int);
168 itkGetConstMacro(NumberOfParameters,
unsigned int);
173 return this->m_Parameters;
178 if (parameters.Size() != m_NumberOfParameters)
180 itkExceptionMacro(<<
"Invalid number of parameters");
182 m_Parameters = parameters;
188 itkExceptionMacro(<<
"GetSingleValue() has to be declared in child classes.");
193 return GetSingleValue(value1, value2);
199 unsigned int centerIndex = it.GetCenterNeighborhoodIndex();
201 bool isInside =
false;
202 unsigned int insideNeighbors = 0;
203 for (
unsigned long pos = 0; pos < it.Size(); ++pos)
205 if (pos != centerIndex)
207 value1 = it.GetPixel(pos, isInside);
210 result += GetSingleValue(value1, value2);
215 return result / insideNeighbors;
220 MRFEnergy() : m_NumberOfParameters(1), m_Parameters(0){};
This is the base class for energy function used in the MRF framework.
virtual double GetValue(const LabelledNeighborhoodIterator &it, const LabelledImagePixelType &value2)
TInput2 LabelledImageType
void SetParameters(const ParametersType ¶meters)
virtual double GetSingleValue(const InputImagePixelType &, const LabelledImagePixelType &)
itk::ConstNeighborhoodIterator< InputImageType > InputNeighborhoodIterator
const ParametersType & GetParameters(void) const
InputImageType::PixelType InputImagePixelType
itk::SmartPointer< Self > Pointer
virtual double GetValue(const InputNeighborhoodIterator &it, const LabelledImagePixelType &value2)
ParametersType m_Parameters
LabelledImageType::PixelType LabelledImagePixelType
itk::ConstNeighborhoodIterator< LabelledImageType > LabelledNeighborhoodIterator
unsigned int m_NumberOfParameters
virtual double GetValue(const InputImagePixelType &value1, const LabelledImagePixelType &value2)
itk::SmartPointer< const Self > ConstPointer
itk::Array< double > ParametersType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.