Message ID | 20230731094641.73646-2-david.plowman@raspberrypi.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Quoting David Plowman via libcamera-devel (2023-07-31 10:46:37) > From: Naushir Patuck <naush@raspberrypi.com> > > Add a new helper function Histogram::interBinMean() that essentially > replaces the existing Histogram::interQuantileMean() logic but working on > bins instead. > > Rework the interQuantileMean() to call into interBinMean() with the > appropriate convertion from quatiles to bins. /convertion/conversion/ > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > --- > src/ipa/rpi/controller/histogram.cpp | 22 ++++++++++++++-------- > src/ipa/rpi/controller/histogram.h | 2 ++ > 2 files changed, 16 insertions(+), 8 deletions(-) > > diff --git a/src/ipa/rpi/controller/histogram.cpp b/src/ipa/rpi/controller/histogram.cpp > index 16a9207f..0a27ba2c 100644 > --- a/src/ipa/rpi/controller/histogram.cpp > +++ b/src/ipa/rpi/controller/histogram.cpp > @@ -45,20 +45,26 @@ double Histogram::quantile(double q, int first, int last) const > return first + frac; > } > > -double Histogram::interQuantileMean(double qLo, double qHi) const > +double Histogram::interBinMean(double binLo, double binHi) const > { > - assert(qHi > qLo); > - double pLo = quantile(qLo); > - double pHi = quantile(qHi, (int)pLo); > + assert(binHi > binLo); > double sumBinFreq = 0, cumulFreq = 0; > - for (double pNext = floor(pLo) + 1.0; pNext <= ceil(pHi); > - pLo = pNext, pNext += 1.0) { > - int bin = floor(pLo); > + for (double binNext = floor(binLo) + 1.0; binNext <= ceil(binHi); > + binLo = binNext, binNext += 1.0) { > + int bin = floor(binLo); > double freq = (cumulative_[bin + 1] - cumulative_[bin]) * > - (std::min(pNext, pHi) - pLo); > + (std::min(binNext, binHi) - binLo); > sumBinFreq += bin * freq; > cumulFreq += freq; > } > /* add 0.5 to give an average for bin mid-points */ > return sumBinFreq / cumulFreq + 0.5; > } > + > +double Histogram::interQuantileMean(double qLo, double qHi) const > +{ > + assert(qHi > qLo); > + double pLo = quantile(qLo); > + double pHi = quantile(qHi, (int)pLo); > + return interBinMean(pLo, pHi); > +} > diff --git a/src/ipa/rpi/controller/histogram.h b/src/ipa/rpi/controller/histogram.h > index 6b3e3a9e..e2c5509b 100644 > --- a/src/ipa/rpi/controller/histogram.h > +++ b/src/ipa/rpi/controller/histogram.h > @@ -38,6 +38,8 @@ public: > uint64_t total() const { return cumulative_[cumulative_.size() - 1]; } > /* Cumulative frequency up to a (fractional) point in a bin. */ > uint64_t cumulativeFreq(double bin) const; > + /* Return the mean value between two (fractional) bins. */ > + double interBinMean(double binLo, double binHi) const; > /* > * Return the (fractional) bin of the point q (0 <= q <= 1) through the > * histogram. Optionally provide limits to help. > -- > 2.30.2 >
Actually also s/quatiles/quantiles/ !! I can send an update to this one (and add my own reviewed-by seeing as it's Naush's originally). David On Mon, 31 Jul 2023 at 10:59, Kieran Bingham <kieran.bingham@ideasonboard.com> wrote: > > Quoting David Plowman via libcamera-devel (2023-07-31 10:46:37) > > From: Naushir Patuck <naush@raspberrypi.com> > > > > Add a new helper function Histogram::interBinMean() that essentially > > replaces the existing Histogram::interQuantileMean() logic but working on > > bins instead. > > > > Rework the interQuantileMean() to call into interBinMean() with the > > appropriate convertion from quatiles to bins. > > /convertion/conversion/ > > > > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com> > > > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > > > --- > > src/ipa/rpi/controller/histogram.cpp | 22 ++++++++++++++-------- > > src/ipa/rpi/controller/histogram.h | 2 ++ > > 2 files changed, 16 insertions(+), 8 deletions(-) > > > > diff --git a/src/ipa/rpi/controller/histogram.cpp b/src/ipa/rpi/controller/histogram.cpp > > index 16a9207f..0a27ba2c 100644 > > --- a/src/ipa/rpi/controller/histogram.cpp > > +++ b/src/ipa/rpi/controller/histogram.cpp > > @@ -45,20 +45,26 @@ double Histogram::quantile(double q, int first, int last) const > > return first + frac; > > } > > > > -double Histogram::interQuantileMean(double qLo, double qHi) const > > +double Histogram::interBinMean(double binLo, double binHi) const > > { > > - assert(qHi > qLo); > > - double pLo = quantile(qLo); > > - double pHi = quantile(qHi, (int)pLo); > > + assert(binHi > binLo); > > double sumBinFreq = 0, cumulFreq = 0; > > - for (double pNext = floor(pLo) + 1.0; pNext <= ceil(pHi); > > - pLo = pNext, pNext += 1.0) { > > - int bin = floor(pLo); > > + for (double binNext = floor(binLo) + 1.0; binNext <= ceil(binHi); > > + binLo = binNext, binNext += 1.0) { > > + int bin = floor(binLo); > > double freq = (cumulative_[bin + 1] - cumulative_[bin]) * > > - (std::min(pNext, pHi) - pLo); > > + (std::min(binNext, binHi) - binLo); > > sumBinFreq += bin * freq; > > cumulFreq += freq; > > } > > /* add 0.5 to give an average for bin mid-points */ > > return sumBinFreq / cumulFreq + 0.5; > > } > > + > > +double Histogram::interQuantileMean(double qLo, double qHi) const > > +{ > > + assert(qHi > qLo); > > + double pLo = quantile(qLo); > > + double pHi = quantile(qHi, (int)pLo); > > + return interBinMean(pLo, pHi); > > +} > > diff --git a/src/ipa/rpi/controller/histogram.h b/src/ipa/rpi/controller/histogram.h > > index 6b3e3a9e..e2c5509b 100644 > > --- a/src/ipa/rpi/controller/histogram.h > > +++ b/src/ipa/rpi/controller/histogram.h > > @@ -38,6 +38,8 @@ public: > > uint64_t total() const { return cumulative_[cumulative_.size() - 1]; } > > /* Cumulative frequency up to a (fractional) point in a bin. */ > > uint64_t cumulativeFreq(double bin) const; > > + /* Return the mean value between two (fractional) bins. */ > > + double interBinMean(double binLo, double binHi) const; > > /* > > * Return the (fractional) bin of the point q (0 <= q <= 1) through the > > * histogram. Optionally provide limits to help. > > -- > > 2.30.2 > >
diff --git a/src/ipa/rpi/controller/histogram.cpp b/src/ipa/rpi/controller/histogram.cpp index 16a9207f..0a27ba2c 100644 --- a/src/ipa/rpi/controller/histogram.cpp +++ b/src/ipa/rpi/controller/histogram.cpp @@ -45,20 +45,26 @@ double Histogram::quantile(double q, int first, int last) const return first + frac; } -double Histogram::interQuantileMean(double qLo, double qHi) const +double Histogram::interBinMean(double binLo, double binHi) const { - assert(qHi > qLo); - double pLo = quantile(qLo); - double pHi = quantile(qHi, (int)pLo); + assert(binHi > binLo); double sumBinFreq = 0, cumulFreq = 0; - for (double pNext = floor(pLo) + 1.0; pNext <= ceil(pHi); - pLo = pNext, pNext += 1.0) { - int bin = floor(pLo); + for (double binNext = floor(binLo) + 1.0; binNext <= ceil(binHi); + binLo = binNext, binNext += 1.0) { + int bin = floor(binLo); double freq = (cumulative_[bin + 1] - cumulative_[bin]) * - (std::min(pNext, pHi) - pLo); + (std::min(binNext, binHi) - binLo); sumBinFreq += bin * freq; cumulFreq += freq; } /* add 0.5 to give an average for bin mid-points */ return sumBinFreq / cumulFreq + 0.5; } + +double Histogram::interQuantileMean(double qLo, double qHi) const +{ + assert(qHi > qLo); + double pLo = quantile(qLo); + double pHi = quantile(qHi, (int)pLo); + return interBinMean(pLo, pHi); +} diff --git a/src/ipa/rpi/controller/histogram.h b/src/ipa/rpi/controller/histogram.h index 6b3e3a9e..e2c5509b 100644 --- a/src/ipa/rpi/controller/histogram.h +++ b/src/ipa/rpi/controller/histogram.h @@ -38,6 +38,8 @@ public: uint64_t total() const { return cumulative_[cumulative_.size() - 1]; } /* Cumulative frequency up to a (fractional) point in a bin. */ uint64_t cumulativeFreq(double bin) const; + /* Return the mean value between two (fractional) bins. */ + double interBinMean(double binLo, double binHi) const; /* * Return the (fractional) bin of the point q (0 <= q <= 1) through the * histogram. Optionally provide limits to help.