---
milena/ChangeLog | 4 ++++
milena/mln/histo/equalize.hh | 24 +++++++++++++++++-------
2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index a9f96d8..d9f0ffa 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2012-11-13 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * mln/histo/equalize.hh: Fix.
+
+2012-11-13 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* mln/histo/equalize.hh: Revamp.
2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/milena/mln/histo/equalize.hh b/milena/mln/histo/equalize.hh
index d1de0e9..7f994df 100644
--- a/milena/mln/histo/equalize.hh
+++ b/milena/mln/histo/equalize.hh
@@ -27,6 +27,7 @@
#ifndef MLN_HISTO_EQUALIZE_HH
# define MLN_HISTO_EQUALIZE_HH
+# include <cmath>
# include <mln/core/concept/image.hh>
# include <mln/histo/all.hh>
@@ -43,6 +44,9 @@ namespace mln
/*! \brief Equalizes the histogram of image \p input.
\author J. Fabrizio, R. Levillain
+
+ Source:
+
http://en.wikipedia.org/wiki/Histogram_equalization
*/
template <typename I>
mln_concrete(I) equalize(const Image<I>& input);
@@ -63,19 +67,25 @@ namespace mln
array<V> histogram = compute(input);
array<V> histo_correction;
- unsigned cumulation = 0;
- unsigned number_of_pixels = input.nsites();
- //int number_of_colors=histogram.nvalues();
- //int number_of_colors=mln_card(V);
+ unsigned nsites = input.nsites();
V max_color = mln_max(V);
+ unsigned h_min = nsites;
mln_viter(mln::value::set<V>) v(histogram.vset());
+
+ // Looking for minimum occurence in histogram
+ for_all(v)
+ if (histogram(v) > 0 && h_min > histogram(v))
+ h_min = histogram(v);
+
+ // Computing new histogram.
+ unsigned cdf_v = 0;
for_all(v)
if (histogram(v) != 0)
{
- cumulation += histogram(v);
- histo_correction(v) = (/*number_of_colors-1*/max_color)
- * cumulation / number_of_pixels;
+ cdf_v += histogram(v);
+ histo_correction(v)
+ = round((cdf_v - h_min) / (float)(nsites - h_min) * max_color);
}
mln_concrete(I) output;
--
1.7.2.5