22 #ifndef otbStreamingMinMaxImageFilter_hxx
23 #define otbStreamingMinMaxImageFilter_hxx
27 #include "itkImageRegionIterator.h"
28 #include "itkProgressReporter.h"
34 template <
class TInputImage>
44 for (
int i = 1; i < 5; ++i)
46 this->itk::ProcessObject::SetNthOutput(i, this->MakeOutput(i));
49 this->GetMinimumOutput()->Set(itk::NumericTraits<PixelType>::max());
50 this->GetMaximumOutput()->Set(itk::NumericTraits<PixelType>::NonpositiveMin());
55 template <
class TInputImage>
58 itk::DataObject::Pointer ret;
62 ret =
static_cast<itk::DataObject*
>(TInputImage::New().GetPointer());
66 ret =
static_cast<itk::DataObject*
>(PixelObjectType::New().GetPointer());
70 ret =
static_cast<itk::DataObject*
>(IndexObjectType::New().GetPointer());
76 template <
class TInputImage>
79 return static_cast<PixelObjectType*
>(this->itk::ProcessObject::GetOutput(1));
82 template <
class TInputImage>
85 return static_cast<const PixelObjectType*
>(this->itk::ProcessObject::GetOutput(1));
88 template <
class TInputImage>
91 return static_cast<PixelObjectType*
>(this->itk::ProcessObject::GetOutput(2));
94 template <
class TInputImage>
97 return static_cast<const PixelObjectType*
>(this->itk::ProcessObject::GetOutput(2));
101 template <
class TInputImage>
104 return static_cast<IndexObjectType*
>(this->itk::ProcessObject::GetOutput(3));
107 template <
class TInputImage>
110 return static_cast<const IndexObjectType*
>(this->itk::ProcessObject::GetOutput(3));
113 template <
class TInputImage>
116 return static_cast<IndexObjectType*
>(this->itk::ProcessObject::GetOutput(4));
119 template <
class TInputImage>
122 return static_cast<const IndexObjectType*
>(this->itk::ProcessObject::GetOutput(4));
125 template <
class TInputImage>
128 Superclass::GenerateOutputInformation();
129 if (this->GetInput())
131 this->GetOutput()->CopyInformation(this->GetInput());
132 this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetLargestPossibleRegion());
134 if (this->GetOutput()->GetRequestedRegion().GetNumberOfPixels() == 0)
136 this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetLargestPossibleRegion());
140 template <
class TInputImage>
150 template <
class TInputImage>
154 int numberOfThreads = this->GetNumberOfThreads();
156 PixelType minimum = itk::NumericTraits<PixelType>::max();
157 PixelType maximum = itk::NumericTraits<PixelType>::NonpositiveMin();
161 for (i = 0; i < numberOfThreads; ++i)
163 if (m_ThreadMin[i] < minimum)
165 minimum = m_ThreadMin[i];
166 minimumIdx = m_ThreadMinIndex[i];
168 if (m_ThreadMax[i] > maximum)
170 maximum = m_ThreadMax[i];
171 maximumIdx = m_ThreadMaxIndex[i];
176 this->GetMinimumOutput()->Set(minimum);
177 this->GetMaximumOutput()->Set(maximum);
178 this->GetMinimumIndexOutput()->Set(minimumIdx);
179 this->GetMaximumIndexOutput()->Set(maximumIdx);
182 template <
class TInputImage>
185 int numberOfThreads = this->GetNumberOfThreads();
187 m_ThreadMin.resize(numberOfThreads);
188 m_ThreadMax.resize(numberOfThreads);
189 std::fill(m_ThreadMin.begin(), m_ThreadMin.end(), itk::NumericTraits<PixelType>::max());
190 std::fill(m_ThreadMax.begin(), m_ThreadMax.end(), itk::NumericTraits<PixelType>::NonpositiveMin());
194 m_ThreadMinIndex.resize(numberOfThreads);
195 m_ThreadMaxIndex.resize(numberOfThreads);
196 std::fill(m_ThreadMinIndex.begin(), m_ThreadMinIndex.end(), zeroIdx);
197 std::fill(m_ThreadMaxIndex.begin(), m_ThreadMaxIndex.end(), zeroIdx);
200 template <
class TInputImage>
204 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
207 itk::ImageRegionConstIterator<TInputImage> it(inputPtr, outputRegionForThread);
210 while (!it.IsAtEnd())
213 if (value < m_ThreadMin[threadId])
215 m_ThreadMin[threadId] = value;
216 m_ThreadMinIndex[threadId] = it.GetIndex();
218 if (value > m_ThreadMax[threadId])
220 m_ThreadMax[threadId] = value;
221 m_ThreadMaxIndex[threadId] = it.GetIndex();
224 progress.CompletedPixel();
228 template <
class TImage>
231 Superclass::PrintSelf(os, indent);
233 os << indent <<
"Minimum: " <<
static_cast<typename itk::NumericTraits<PixelType>::PrintType
>(this->GetMinimum()) << std::endl;
234 os << indent <<
"Maximum: " <<
static_cast<typename itk::NumericTraits<PixelType>::PrintType
>(this->GetMaximum()) << std::endl;
235 os << indent <<
"Minimum Index: " << this->GetMinimumIndex() << std::endl;
236 os << indent <<
"Maximum Index: " << this->GetMaximumIndex() << std::endl;