21 #ifndef otbComputeGainLutFilter_hxx
22 #define otbComputeGainLutFilter_hxx
25 #include "itkImageRegionIterator.h"
33 template <
class TInputImage,
class TOutputImage>
38 m_Min = std::numeric_limits<double>::quiet_NaN();
39 m_Max = std::numeric_limits<double>::quiet_NaN();
43 template <
class TInputImage,
class TOutputImage>
46 m_NbBin = this->GetInput()->GetNumberOfComponentsPerPixel();
47 m_Step =
static_cast<double>(m_Max - m_Min) /
static_cast<double>(m_NbBin - 1);
50 template <
class TInputImage,
class TOutputImage>
52 itk::ThreadIdType itkNotUsed(threadId))
60 typename InputImageType::ConstPointer input(this->GetInput());
61 typename OutputImageType::Pointer output(this->GetOutput());
63 itk::ImageRegionConstIterator<InputImageType> it(input, outputRegionForThread);
65 itk::ImageRegionIterator<OutputImageType> oit(output, outputRegionForThread);
68 target.SetSize(m_NbBin);
75 for (it.GoToBegin(), oit.GoToBegin(); !oit.IsAtEnd() || !it.IsAtEnd(); ++oit, ++it)
77 currentHisto = it.Get();
80 if (IsValid(currentHisto))
82 CreateTarget(currentHisto, target);
83 Equalized(currentHisto, target, lut);
87 assert(oit.IsAtEnd() && it.IsAtEnd());
90 template <
class TInputImage,
class TOutputImage>
93 double denum(countValue * m_Step + m_Min);
96 return static_cast<OutputPixelType>((countMapValue * m_Step + m_Min) / denum);
99 template <
class TInputImage,
class TOutputImage>
102 unsigned int countValue(0), countMapValue(0);
105 unsigned int countInput(inputHisto[0] + inputHisto[countValue]);
106 lut[m_NbBin - 1] = 1;
107 unsigned int countTarget(targetHisto[countMapValue]);
109 while ((countMapValue < m_NbBin) && countValue < (m_NbBin - 1))
111 if (countInput > countTarget)
114 countTarget += targetHisto[countMapValue];
118 lut[countValue] = PostProcess(countValue, countMapValue);
120 countInput += inputHisto[countValue];
123 for (
unsigned int i = 0; i < m_NbBin; i++)
132 template <
class TInputImage,
class TOutputImage>
135 unsigned int nbPixel(0);
136 for (
unsigned int i = 0; i < m_NbBin; i++)
138 nbPixel += inputHisto[i];
140 unsigned int rest(nbPixel % m_NbBin), height(nbPixel / m_NbBin);
141 targetHisto.Fill(height);
142 for (
unsigned int i = 0; i < rest; i++)
144 ++targetHisto[(m_NbBin - rest) / 2 + i];
148 template <
class TInputImage,
class TOutputImage>
151 long acc = std::accumulate(&inputHisto[0], &inputHisto[m_NbBin - 1], 0);
152 return acc >= (0.5 * m_NbPixel);
158 template <
class TInputImage,
class TOutputImage>
161 Superclass::PrintSelf(os, indent);
162 os << indent <<
"Minimum: " << m_Min << std::endl;
163 os << indent <<
"Maximum: " << m_Max << std::endl;
164 os << indent <<
"Step: " << m_Step << std::endl;
165 os << indent <<
"Number of bin: " << m_NbBin << std::endl;
166 os << indent <<
"Number of pixel by histogram: " << m_NbPixel << std::endl;