22 #ifndef otbGreyLevelCooccurrenceIndexedList_hxx
23 #define otbGreyLevelCooccurrenceIndexedList_hxx
29 template <
class TPixel>
31 : m_Size(), m_Symmetry(true), m_TotalFrequency(0), m_ClipBinsAtEnds(true), m_InputImageMinimum(0), m_InputImageMaximum(255)
35 template <
class TPixel>
42 m_InputImageMinimum = min;
43 m_InputImageMaximum = max;
45 upperBound.Fill(max + 1);
47 m_Symmetry = symmetry;
49 m_LookupArray.Fill(-1);
54 m_Min.resize(PixelPairSize);
55 for (dim = 0; dim < PixelPairSize; dim++)
57 m_Min[dim].resize(m_Size[dim]);
60 m_Max.resize(PixelPairSize);
61 for (dim = 0; dim < PixelPairSize; dim++)
63 m_Max[dim].resize(m_Size[dim]);
67 for (
unsigned int i = 0; i < PixelPairSize; i++)
71 interval =
static_cast<float>(upperBound[i] - lowerBound[i]) /
static_cast<PixelValueType>(m_Size[i]);
74 for (
unsigned int j = 0; j < static_cast<unsigned int>(m_Size[i] - 1); j++)
76 this->SetBinMin(i, j, (
PixelValueType)(lowerBound[i] + ((
float)j * interval)));
77 this->SetBinMax(i, j, (
PixelValueType)(lowerBound[i] + (((
float)j + 1) * interval)));
79 this->SetBinMin(i, m_Size[i] - 1, (
PixelValueType)(lowerBound[i] + (((
float)m_Size[i] - 1) * interval)));
80 this->SetBinMax(i, m_Size[i] - 1, (
PixelValueType)(upperBound[i]));
85 template <
class TPixel>
88 m_Min[dimension][nbin] = min;
91 template <
class TPixel>
94 m_Max[dimension][nbin] = max;
97 template <
class TPixel>
111 for (dim = 0; dim < PixelPairSize; dim++)
113 tempPixelValue = pixelPair[dim];
116 if (tempPixelValue < m_Min[dim][begin])
120 if (!m_ClipBinsAtEnds)
132 end = m_Min[dim].size() - 1;
133 if (tempPixelValue >= m_Max[dim][end])
138 if (!m_ClipBinsAtEnds || tempPixelValue == m_Max[dim][end])
156 if (tempPixelValue <
median)
160 else if (tempPixelValue >
median)
164 if (tempPixelValue < m_Max[dim][mid] && tempPixelValue >= m_Min[dim][mid])
177 mid = begin + (end - begin) / 2;
184 template <
class TPixel>
188 if (pixelvalue1 < m_InputImageMinimum || pixelvalue1 > m_InputImageMaximum)
194 if (pixelvalue2 < m_InputImageMinimum || pixelvalue2 > m_InputImageMaximum)
202 ppair[0] = pixelvalue1;
203 ppair[1] = pixelvalue2;
206 this->GetIndex(ppair, index);
209 this->AddPairToVector(index);
216 this->AddPairToVector(index);
220 template <
class TPixel>
224 double frequency = 0;
226 if (instanceId < m_LookupArray.size())
228 int findex = m_LookupArray[instanceId];
230 frequency = m_Vector[findex].second / m_TotalFrequency;
235 template <
class TPixel>
239 double frequency = 0;
241 if (instanceId < m_LookupArray.size())
243 int findex = m_LookupArray[instanceId];
245 frequency = vect[findex].second;
250 template <
class TPixel>
256 template <
class TPixel>
260 instanceId = index[1] * m_Size[0] + index[0];
261 int vindex = m_LookupArray[instanceId];
264 m_LookupArray[instanceId] = m_Vector.size();
267 cooccur = std::make_pair(index, 1);
268 m_Vector.push_back(cooccur);
272 m_Vector[vindex].second++;
274 m_TotalFrequency = m_TotalFrequency + 1;
277 template <
class TPixel>
280 Superclass::PrintSelf(os, indent);
281 os << indent <<
"Symmetry: " << this->m_Symmetry << std::endl;
282 os << indent <<
"TotalFrequency: " << this->m_TotalFrequency << std::endl;
283 os << indent <<
"Size: " << m_Size;
284 os << indent <<
"CooccurrenceIndexedList: " << std::endl;
285 typename VectorType::const_iterator it;
286 for (it = m_Vector.begin(); it != m_Vector.end(); ++it)
288 std::cerr <<
"index=" << (*it).first <<
", frequency=" << (*it).second << std::endl;
290 std::cerr << std::endl;