
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-03-11 Etienne FOLIO <folio@lrde.epita.fr> compute_histo_rgb. * folio/histo/compute_histo_rgb.hh: New algorithm for computing an histogram on image2d<rgb8>. * folio/histo: New directory for histogram-related algorithms. * folio/test/histo/compute_histo_rgb.cc: New tests about the algorithm above. * folio/test/histo: New directory for testing histogram-related algorithms. --- histo/compute_histo_rgb.hh | 35 ++++++++++++++++++++++++++ test/histo/compute_histo_rgb.cc | 52 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) Index: trunk/milena/sandbox/folio/test/histo/compute_histo_rgb.cc =================================================================== --- trunk/milena/sandbox/folio/test/histo/compute_histo_rgb.cc (revision 0) +++ trunk/milena/sandbox/folio/test/histo/compute_histo_rgb.cc (revision 3513) @@ -0,0 +1,52 @@ +/*! + * \file compute_histo_rgb.cc<2> + * \author etiennefolio <ornthalas@gmail.com> + */ + +#include <iostream> +#include <mln/debug/println.hh> +#include <mln/literal/all.hh> + +#include "../../histo/compute_histo_rgb.hh" + +int main() +{ + using namespace mln; + + // build test image + image2d<value::rgb8> ima(10, 10); + + value::rgb8 red = literal::red; + value::rgb8 green = literal::green; + value::rgb8 black = literal::black; + + for (unsigned i = 0; i < 10; ++i) + for (unsigned j = 5; j < 10; ++j) + { + point2d p(j, i); + ima(p) = black; + } + + for (unsigned i = 0; i < 10; ++i) + for (unsigned j = 0; j < 5; ++j) + { + point2d p(j, i); + ima(p) = red; + } + + point2d p(8, 2); + ima(p) = green; + + std::cout << "input :" << std::endl; + debug::println(ima); + + // let's run ! + image3d<value::int_u8> out = histo::compute_histo_rgb<value::int_u8>(ima); + + // output ? + std::cout << "out(0, 0, 0) = " << out(point3d(0, 0, 0)) << std::endl; + std::cout << "out(255, 0, 0) = " << out(point3d(255, 0, 0)) << std::endl; + std::cout << "out(0, 255, 0) = " << out(point3d(0, 255, 0)) << std::endl; + + return 0; +} Index: trunk/milena/sandbox/folio/histo/compute_histo_rgb.hh =================================================================== --- trunk/milena/sandbox/folio/histo/compute_histo_rgb.hh (revision 0) +++ trunk/milena/sandbox/folio/histo/compute_histo_rgb.hh (revision 3513) @@ -0,0 +1,35 @@ +/*! + * \file compute_histo_rgb.cc + * \author etiennefolio <ornthalas@gmail.com> + */ + +#include <mln/core/image/image2d.hh> +#include <mln/core/image/image3d.hh> +#include <mln/value/int_u8.hh> +#include <mln/value/rgb8.hh> + +namespace mln +{ + namespace histo + { + + template <typename C, typename T> + image3d<C> compute_histo_rgb(image2d<T> ima) + { + // out + image3d<C> out(mln_max(C), + mln_max(C), + mln_max(C)); + data::fill(out, mln_min(C)); + + // count + mln_fwd_piter(image2d<T>) p(ima.domain()); + for_all(p) + ++out(point3d(ima(p).red(), ima(p).green(), ima(p).blue())); + + // return + return out; + } + + } +}
participants (1)
-
Etienne FOLIO