r3666: Compute histograms on 3d and generic images. Still not fully working

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-04-15 Etienne FOLIO <folio@lrde.epita.fr> Compute histograms on 3d and generic images. Still not fully working. * folio/mln/histo/compute_histo.hh: New algorithm that computes an histogram on a generic image * folio/mln/histo/compute_histo_3d.hh: New algorithm that computes an histogram on a 3d image. * folio/test/histo/compute_histo_3d.cc: New test file for the compute_histo_3d.hh algorithm. --- mln/histo/compute_histo.hh | 47 +++++++++++++++++++++++++++++++++++ mln/histo/compute_histo_3d.hh | 38 ++++++++++++++++++++++++++++ test/histo/compute_histo_3d.cc | 54 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) Index: trunk/milena/sandbox/folio/test/histo/compute_histo_3d.cc =================================================================== --- trunk/milena/sandbox/folio/test/histo/compute_histo_3d.cc (revision 0) +++ trunk/milena/sandbox/folio/test/histo/compute_histo_3d.cc (revision 3666) @@ -0,0 +1,54 @@ +/*! + * \file compute_histo_rgb.cc<2> + * \author etiennefolio <ornthalas@gmail.com> + */ + +#include <iostream> +#include <mln/debug/println.hh> +#include <mln/literal/all.hh> +#include <mln/value/rgb8.hh> +#include <mln/value/int_u8.hh> + +#include "../../mln/histo/compute_histo_3d.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_3d<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/mln/histo/compute_histo.hh =================================================================== --- trunk/milena/sandbox/folio/mln/histo/compute_histo.hh (revision 0) +++ trunk/milena/sandbox/folio/mln/histo/compute_histo.hh (revision 3666) @@ -0,0 +1,47 @@ +/*! + * \file compute_histo.cc + * \author etiennefolio <ornthalas@gmail.com> + */ + +#include <mln/core/image/image.hh> +#include <mln/trait/value/comp.hh> + +#include <mln/trait/image_from_grid.hh> + +namespace mln +{ + namespace histo + { + + template <typename C, typename I> + Image<C> compute_histo(Image<I> ima_) + { + I ima = exact(ima); + typedef mln_value(I) V; + typedef mln_regular_grid_from_dim(V::dim + 1) G; + typedef mln_image_from_grid(G, C) O; + O out; + + for (unsigned i = 0; i < V::dim + 1; ++i) + { + typedef mln_trait_value_comp(I, i)::enc enc[i]; + // FIXME: define here the domain of `out'. + // out(mln_max(enc[0]) + abs(mln_min(enc[0])) + 1, + // mln_max(enc[1]) + abs(mln_min(enc[1])) + 1, + // mln_max(enc[2]) + abs(mln_min(enc[2])) + 1); + } + data::fill(out, mln_min(C)); + + // count + mln_fwd_piter(box2d) p(ima.domain()); + for_all(p) + // FIXME: call macro comp()? + // FIXME: pointnd + ++out(point3d(ima(p).comp(0), ima(p).comp(1), ima(p).comp(2))); + + // return + return out; + } + + } +} Index: trunk/milena/sandbox/folio/mln/histo/compute_histo_3d.hh =================================================================== --- trunk/milena/sandbox/folio/mln/histo/compute_histo_3d.hh (revision 0) +++ trunk/milena/sandbox/folio/mln/histo/compute_histo_3d.hh (revision 3666) @@ -0,0 +1,38 @@ +/*! + * \file compute_histo_3d.cc + * \author etiennefolio <ornthalas@gmail.com> + */ + +#include <mln/core/image/image2d.hh> +#include <mln/core/image/image3d.hh> +#include <mln/trait/value/comp.hh> + +namespace mln +{ + namespace histo + { + + template <typename C, typename T> + image3d<C> compute_histo_3d(image2d<T> ima) + { + // out + typedef mln_trait_value_comp(T, 0)::enc enc_0; + typedef mln_trait_value_comp(T, 1)::enc enc_1; + typedef mln_trait_value_comp(T, 2)::enc enc_2; + image3d<C> out(mln_max(enc_0) + abs(mln_min(enc_0)) + 1, + mln_max(enc_1) + abs(mln_min(enc_1)) + 1, + mln_max(enc_2) + abs(mln_min(enc_2)) + 1); + data::fill(out, mln_min(C)); + + // count + mln_fwd_piter(box2d) p(ima.domain()); + for_all(p) + // FIXME: call macro comp()? + ++out(point3d(ima(p).comp(0), ima(p).comp(1), ima(p).comp(2))); + + // return + return out; + } + + } +}
participants (1)
-
Etienne FOLIO