22 #ifndef otbContinuousMinimumMaximumImageCalculator_hxx
23 #define otbContinuousMinimumMaximumImageCalculator_hxx
26 #include "itkImageRegionConstIteratorWithIndex.h"
34 template <
class TInputImage>
38 m_Maximum(
itk::NumericTraits<
PixelType>::NonpositiveMin()),
39 m_Image(TInputImage::New()),
40 m_RegionSetByUser(false)
49 template <
class TInputImage>
52 if (!m_RegionSetByUser)
54 m_Region = m_Image->GetRequestedRegion();
57 itk::ImageRegionConstIteratorWithIndex<TInputImage> it(m_Image, m_Region);
58 m_Maximum = itk::NumericTraits<PixelType>::NonpositiveMin();
59 m_Minimum = itk::NumericTraits<PixelType>::max();
66 m_Maximum =
static_cast<PixelType>(value);
67 m_IndexOfMaximum = it.GetIndex();
71 m_Minimum =
static_cast<PixelType>(value);
72 m_IndexOfMinimum = it.GetIndex();
81 indexNeighbor[0] = m_IndexOfMinimum[0] - 1;
82 indexNeighbor[1] = m_IndexOfMinimum[1];
83 it.SetIndex(indexNeighbor);
85 indexNeighbor[0] = m_IndexOfMinimum[0] + 1;
86 indexNeighbor[1] = m_IndexOfMinimum[1];
87 it.SetIndex(indexNeighbor);
90 double hOffset = -(rightValue - leftValue) / (2 * (rightValue + leftValue - 2 * m_Minimum));
93 indexNeighbor[0] = m_IndexOfMinimum[0];
94 indexNeighbor[1] = m_IndexOfMinimum[1] - 1;
95 it.SetIndex(indexNeighbor);
97 indexNeighbor[0] = m_IndexOfMinimum[0];
98 indexNeighbor[1] = m_IndexOfMinimum[1] + 1;
99 it.SetIndex(indexNeighbor);
102 double vOffset = -(bottomValue - topValue) / (2 * (bottomValue + topValue - 2 * m_Minimum));
104 m_ContinuousIndexOfMinimum[0] = m_IndexOfMinimum[0] + hOffset;
105 m_ContinuousIndexOfMinimum[1] = m_IndexOfMinimum[1] + vOffset;
110 indexNeighbor[0] = m_IndexOfMaximum[0] - 1;
111 indexNeighbor[1] = m_IndexOfMaximum[1];
112 it.SetIndex(indexNeighbor);
114 indexNeighbor[0] = m_IndexOfMaximum[0] + 1;
115 indexNeighbor[1] = m_IndexOfMaximum[1];
116 it.SetIndex(indexNeighbor);
119 double hOffset = -(rightValue - leftValue) / (2 * (rightValue + leftValue - 2 * m_Maximum));
122 indexNeighbor[0] = m_IndexOfMaximum[0];
123 indexNeighbor[1] = m_IndexOfMaximum[1] - 1;
124 it.SetIndex(indexNeighbor);
126 indexNeighbor[0] = m_IndexOfMaximum[0];
127 indexNeighbor[1] = m_IndexOfMaximum[1] + 1;
128 it.SetIndex(indexNeighbor);
131 double vOffset = -(bottomValue - topValue) / (2 * (bottomValue + topValue - 2 * m_Maximum));
133 m_ContinuousIndexOfMaximum[0] = m_IndexOfMaximum[0] + hOffset;
134 m_ContinuousIndexOfMaximum[1] = m_IndexOfMaximum[1] + vOffset;
141 template <
class TInputImage>
144 if (!m_RegionSetByUser)
146 m_Region = m_Image->GetRequestedRegion();
148 itk::ImageRegionConstIteratorWithIndex<TInputImage> it(m_Image, m_Region);
149 m_Minimum = itk::NumericTraits<PixelType>::max();
151 while (!it.IsAtEnd())
156 m_Minimum =
static_cast<PixelType>(value);
157 m_IndexOfMinimum = it.GetIndex();
165 indexNeighbor[0] = m_IndexOfMinimum[0] - 1;
166 indexNeighbor[1] = m_IndexOfMinimum[1];
167 it.SetIndex(indexNeighbor);
169 indexNeighbor[0] = m_IndexOfMinimum[0] + 1;
170 indexNeighbor[1] = m_IndexOfMinimum[1];
171 it.SetIndex(indexNeighbor);
174 double hOffset = -(rightValue - leftValue) / (2 * (rightValue + leftValue - 2 * m_Minimum));
177 indexNeighbor[0] = m_IndexOfMinimum[0];
178 indexNeighbor[1] = m_IndexOfMinimum[1] - 1;
179 it.SetIndex(indexNeighbor);
181 indexNeighbor[0] = m_IndexOfMinimum[0];
182 indexNeighbor[1] = m_IndexOfMinimum[1] + 1;
183 it.SetIndex(indexNeighbor);
186 double vOffset = -(bottomValue - topValue) / (2 * (bottomValue + topValue - 2 * m_Minimum));
188 m_ContinuousIndexOfMinimum[0] = m_IndexOfMinimum[0] + hOffset;
189 m_ContinuousIndexOfMinimum[1] = m_IndexOfMinimum[1] + vOffset;
195 template <
class TInputImage>
198 if (!m_RegionSetByUser)
200 m_Region = m_Image->GetRequestedRegion();
202 itk::ImageRegionConstIteratorWithIndex<TInputImage> it(m_Image, m_Region);
203 m_Maximum = itk::NumericTraits<PixelType>::NonpositiveMin();
205 while (!it.IsAtEnd())
210 m_Maximum =
static_cast<PixelType>(value);
211 m_IndexOfMaximum = it.GetIndex();
231 indexNeighbor[0] = m_IndexOfMaximum[0] - 1;
232 indexNeighbor[1] = m_IndexOfMaximum[1];
233 it.SetIndex(indexNeighbor);
235 indexNeighbor[0] = m_IndexOfMaximum[0] + 1;
236 indexNeighbor[1] = m_IndexOfMaximum[1];
237 it.SetIndex(indexNeighbor);
240 double hOffset = -(rightValue - leftValue) / (2 * (rightValue + leftValue - 2 * m_Maximum));
243 indexNeighbor[0] = m_IndexOfMaximum[0];
244 indexNeighbor[1] = m_IndexOfMaximum[1] - 1;
245 it.SetIndex(indexNeighbor);
247 indexNeighbor[0] = m_IndexOfMaximum[0];
248 indexNeighbor[1] = m_IndexOfMaximum[1] + 1;
249 it.SetIndex(indexNeighbor);
252 double vOffset = -(bottomValue - topValue) / (2 * (bottomValue + topValue - 2 * m_Maximum));
254 m_ContinuousIndexOfMaximum[0] = m_IndexOfMaximum[0] + hOffset;
255 m_ContinuousIndexOfMaximum[1] = m_IndexOfMaximum[1] + vOffset;
258 template <
class TInputImage>
262 m_RegionSetByUser =
true;
265 template <
class TInputImage>
268 Superclass::PrintSelf(os, indent);
270 os << indent <<
"Minimum: " <<
static_cast<typename itk::NumericTraits<PixelType>::PrintType
>(m_Minimum) << std::endl;
271 os << indent <<
"Maximum: " <<
static_cast<typename itk::NumericTraits<PixelType>::PrintType
>(m_Maximum) << std::endl;
272 os << indent <<
"Index of Minimum: " << m_IndexOfMinimum << std::endl;
273 os << indent <<
"Index of Maximum: " << m_IndexOfMaximum << std::endl;
274 os << indent <<
"Continuous Index of Minimum: " << m_ContinuousIndexOfMinimum << std::endl;
275 os << indent <<
"Continuous Index of Maximum: " << m_ContinuousIndexOfMaximum << std::endl;
277 os << indent <<
"Image: " << std::endl;
278 m_Image->Print(os, indent.GetNextIndent());
279 os << indent <<
"Region: " << std::endl;
280 m_Region.Print(os, indent.GetNextIndent());
281 os << indent <<
"Region set by User: " << m_RegionSetByUser << std::endl;