r4159: Compute histo 3d test
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-06-17 Etienne FOLIO <folio@lrde.epita.fr> Compute histo 3d test. * folio/mln/histo/compute_histo_3d.hh: Algorithm. * folio/test/histo/compute_histo_3d.cc: Test file. --- mln/histo/compute_histo_3d.hh | 30 ++++++----------------------- test/histo/compute_histo_3d.cc | 42 ++++++++++++++++++----------------------- 2 files changed, 26 insertions(+), 46 deletions(-) Index: trunk/milena/sandbox/folio/test/histo/compute_histo_3d.cc =================================================================== --- trunk/milena/sandbox/folio/test/histo/compute_histo_3d.cc (revision 4158) +++ trunk/milena/sandbox/folio/test/histo/compute_histo_3d.cc (revision 4159) @@ -4,9 +4,8 @@ */ #include <iostream> -#include <mln/debug/println.hh> #include <mln/literal/all.hh> -#include <mln/value/rgb8.hh> +#include <mln/value/rgb.hh> #include <mln/value/int_u8.hh> #include "../../mln/histo/compute_histo_3d.hh" @@ -14,41 +13,38 @@ int main() { using namespace mln; + using namespace value; + typedef rgb<3> rgb3; // build test image - image2d<value::rgb8> ima(10, 10); + image2d<rgb3> ima(8, 8); - value::rgb8 red = literal::red; - value::rgb8 green = literal::green; - value::rgb8 black = literal::black; + rgb3 red = literal::red; + rgb3 green = literal::green; + rgb3 black = literal::black; - for (unsigned i = 0; i < 10; ++i) - for (unsigned j = 5; j < 10; ++j) + for (unsigned i = 1; i < 8; ++i) + for (unsigned j = 0; j < 8; ++j) { point2d p(j, i); ima(p) = black; } - for (unsigned i = 0; i < 10; ++i) - for (unsigned j = 0; j < 5; ++j) + for (unsigned i = 0; i < 8; ++i) { - point2d p(j, i); + point2d p(i, 0); ima(p) = red; } - point2d p(8, 2); + point2d p(4, 5); 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; + // build histo + image3d<unsigned> out = histo::compute_histo_3d(ima); - return 0; + // verify... + mln_assertion(out(point3d(255, 0, 0)) == 8); + mln_assertion(out(point3d(0, 255, 0)) == 1); + mln_assertion(out(point3d(0, 0, 0)) == 55); + mln_assertion(out(point3d(1, 0, 0)) == 0); } Index: trunk/milena/sandbox/folio/mln/histo/compute_histo_3d.hh =================================================================== --- trunk/milena/sandbox/folio/mln/histo/compute_histo_3d.hh (revision 4158) +++ trunk/milena/sandbox/folio/mln/histo/compute_histo_3d.hh (revision 4159) @@ -13,34 +13,20 @@ { template <typename T> - struct compute_histo_3d - { - image3d<unsigned> operator()(const image2d<T>& ima) const; - - namespace internal - { - } - - }; - - -# ifndef MLN_INCLUDE_ONLY - - template <typename T> inline image3d<unsigned> - operator()(const image2d<T>& ima) const + compute_histo_3d(const image2d<T>& ima) { typedef mln_trait_value_comp(T, 0)::enc enc_0; // R -> int_u8 typedef mln_trait_value_comp(T, 1)::enc enc_1; // G -> int_u8 typedef mln_trait_value_comp(T, 2)::enc enc_2; // B -> int_u8 - image3d<unsigned> out(box3d(point1d(mln_min(enc_0)), // -> 0 - point1d(mln_min(enc_1)), // -> 0 - point1d(mln_min(enc_2)), // -> 0 - point1d(mln_max(enc_0)), // -> 255 - point1d(mln_max(enc_1)), // -> 255 - point1d(mln_max(enc_2)))) // -> 255 + image3d<unsigned> out(box3d(point3d(mln_min(enc_0), // -> 0 + mln_min(enc_1), // -> 0 + mln_min(enc_2)), // -> 0 + point3d(mln_max(enc_0), // -> 255 + mln_max(enc_1), // -> 255 + mln_max(enc_2)))); // -> 255 data::fill(out, 0); mln_fwd_piter(image2d<T>) p(ima.domain()); @@ -50,7 +36,5 @@ return out; } -# endif // !MLN_INCLUDE_ONLY - } }
participants (1)
-
Etienne FOLIO