
* mln/debug/colorize.hh: create a color image from a labeled image. Use (cached) random colors. --- milena/ChangeLog | 7 ++ milena/mln/debug/colorize.hh | 125 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 0 deletions(-) create mode 100644 milena/mln/debug/colorize.hh diff --git a/milena/ChangeLog b/milena/ChangeLog index 6dc42f8..c1f5639 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,12 @@ 2008-11-03 Guillaume Lazzara <z@lrde.epita.fr> + Add debug::colorize. + + * mln/debug/colorize.hh: create a color image from a labeled image. + Use (cached) random colors. + +2008-11-03 Guillaume Lazzara <z@lrde.epita.fr> + Rewrite not_inplace. * mln/logical/not.hh, diff --git a/milena/mln/debug/colorize.hh b/milena/mln/debug/colorize.hh new file mode 100644 index 0000000..179518e --- /dev/null +++ b/milena/mln/debug/colorize.hh @@ -0,0 +1,125 @@ +// Copyright (C) 2008 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef MLN_DEBUG_COLORIZE_HH +# define MLN_DEBUG_COLORIZE_HH + +/*! \file mln/debug/colorize.hh + * + * \brief Fill an image with successive values. + */ + +# include <mln/core/concept/image.hh> +# include <mln/fun/i2v/array.hh> +# include <mln/value/rgb8.hh> +# include <mln/literal/black.hh> +# include <mln/level/transform.hh> + + +namespace mln +{ + + namespace debug + { + + namespace colorize_ + { + static unsigned min_value = 20; + static unsigned max_value = 220; + } + + + /// Create a new color image from a labeled image and fill each component + /// with a random color. + /*! + * litera::black is used for component 0, e.g. the background. + * Min and max values for RGB values can be set through the global + * variables mln::debug::colorize_::min_value and + * mln::debug::colorize_::max_value. + * + * \param[in] labeled_image A labeled image (\sa labeling::blobs). + * \param[in] nlabels Number of labels. + */ + template <typename I, typename J> + mln_concrete(I) colorize(const Image<J>& labeled_image, mln_value(J) nlabels); + + +# ifndef MLN_INCLUDE_ONLY + + + namespace internal + { + + template <typename V> + V random_color(); + + mln::value::rgb8 + random_color() + { + return mln::value::rgb8(colorize_::min_value + (rand() % colorize_::max_value), + colorize_::min_value + (rand() % colorize_::max_value), + colorize_::min_value + (rand() % colorize_::max_value)); + } + + } + + template <typename I, typename J> + inline + mln_concrete(I) + colorize(const Image<J>& input, mln_value(J) nlabels) + { + trace::entering("debug::colorize"); + mln_precondition(exact(input).has_data()); + + static fun::i2v::array<mln_value(I)> f(0); + int diff_size = f.size() - (nlabels + 1); + if (diff_size < 0) + { + f.resize(nlabels + 1); + unsigned i = f.size() + diff_size; + // We want to treat comp 0 differently since it is the background. + if (i == 0) + i = 1; + f(0) = literal::black; + for (; i < f.size(); ++i) + f(i) = internal::random_color(); + } + mln_precondition(f.size() == (nlabels + 1)); + mln_concrete(I) output = level::transform(input, f); + + trace::exiting("debug::colorize"); + return output; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::debug + +} // end of namespace mln + + +#endif // ! MLN_DEBUG_COLORIZE_HH -- 1.5.6.5
participants (1)
-
Guillaume Lazzara