
* mln/labeling/colorize.hh: use our own random generator. * tests/labeling/colorize.cc: add an assertion. --- milena/ChangeLog | 8 +++++++ milena/mln/labeling/colorize.hh | 40 +++++++++++++++++++++++++++++++++--- milena/tests/labeling/colorize.cc | 5 ++- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 384b9ac..9acd79e 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,11 @@ +2009-06-15 Guillaume Lazzara <guillaume.lazzara@lrde.epita.fr> + + Make labeling::colorize deterministic. + + * mln/labeling/colorize.hh: use our own random generator. + + * tests/labeling/colorize.cc: add an assertion. + 2009-06-14 Roland Levillain <roland@lrde.epita.fr> Aesthetic changes. diff --git a/milena/mln/labeling/colorize.hh b/milena/mln/labeling/colorize.hh index 3f8b6c4..19d00af 100644 --- a/milena/mln/labeling/colorize.hh +++ b/milena/mln/labeling/colorize.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of Olena. // @@ -71,12 +72,23 @@ namespace mln const mln_value(L)& nlabels); + /// \overload + // template <typename V, typename L> mln_ch_value(L, V) colorize(const V& value, const Image<L>& labeled_image); + /// \overload + // + template <typename L> + inline + mln_ch_value(L, value::rgb8) + colorize(const Image<L>& input, + const mln_value(L)& nlabels); + + # ifndef MLN_INCLUDE_ONLY namespace colorize_ @@ -89,6 +101,15 @@ namespace mln namespace internal { + unsigned random_number() + { + static unsigned last = 1; + + last = (323 * last + 6603) % 1025; + + return colorize_::min_value + last % colorize_::max_value; + } + template <typename V> V random_color(const V&); @@ -96,9 +117,9 @@ namespace mln mln::value::rgb<n> random_color(const mln::value::rgb<n>&) { - return mln::value::rgb<n>(colorize_::min_value + (rand() % colorize_::max_value), - colorize_::min_value + (rand() % colorize_::max_value), - colorize_::min_value + (rand() % colorize_::max_value)); + return mln::value::rgb<n>(random_number(), + random_number(), + random_number()); } } @@ -159,6 +180,17 @@ namespace mln return output; } + + template <typename L> + inline + mln_ch_value(L, value::rgb8) + colorize(const Image<L>& input, + const mln_value(L)& nlabels) + { + return colorize(value::rgb8(), input, nlabels); + } + + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::labeling diff --git a/milena/tests/labeling/colorize.cc b/milena/tests/labeling/colorize.cc index 18ae5ae..c0bba3c 100644 --- a/milena/tests/labeling/colorize.cc +++ b/milena/tests/labeling/colorize.cc @@ -29,7 +29,6 @@ # include <mln/labeling/colorize.hh> # include <mln/data/compare.hh> - int main() { using namespace mln; @@ -38,11 +37,13 @@ int main() { 0, 0 } }; typedef value::rgb8 rgb_t; - value::rgb8 ref_data[][2] = { { rgb_t(89,92,86), rgb_t(89,92,86) }, + value::rgb8 ref_data[][2] = { { rgb_t(231,46,171), rgb_t(231,46,171) }, { rgb_t(0,0,0), rgb_t(0,0,0) } }; image2d<value::int_u8> ima = make::image(values); image2d<rgb_t> ref = make::image(ref_data); image2d<value::rgb8> ima_color = labeling::colorize(value::rgb8(), ima); + + mln_assertion(ima_color == ref); } -- 1.5.6.5