
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-06-01 Etienne FOLIO <folio@lrde.epita.fr> Projected histograms for unsigned values. * folio/mln/histo/compute_histo_rgb.hh: Update algorithm. * folio/test/histo/projected3d.cc: Test file. --- mln/histo/compute_histo_rgb.hh | 16 ++++++++++----- test/histo/projected3d.cc | 42 +++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 27 deletions(-) Index: trunk/milena/sandbox/folio/test/histo/projected3d.cc =================================================================== --- trunk/milena/sandbox/folio/test/histo/projected3d.cc (revision 3938) +++ trunk/milena/sandbox/folio/test/histo/projected3d.cc (revision 3939) @@ -54,13 +54,25 @@ { mln_precondition(f > 0); return std::log(f + 1); -// return std::log(std::log(f + 1) + 1); } }; -} + template <typename A, unsigned direction, typename V> + image2d<float> + project_histo(const image3d<V>& h) + { + image2d<A> h_2d_a(h.nrows(), h.ncols()); + accu::image::init(h_2d_a); + accu::image::take( unproject( h_2d_a, + h.domain(), + fun::v2v::projection<point3d, direction>() ).rw(), + h ); + return accu::image::to_result(h_2d_a); + } + +} int main(int argc, char* argv[]) @@ -83,27 +95,13 @@ // image2d<rgb6> ima6 = data::transform(ima, rgb8to6()); std::cout << " => computing histogram..." << std::endl; - image3d<unsigned> histo = histo::compute_histo_rgb<unsigned>(ima); // 6); + image3d<unsigned> histo = histo::compute_histo_rgb<unsigned>(ima); - { - mln_VAR(h, histo); - - typedef accu::sum<unsigned> A; - - image2d<A> h_2d_a(h.nrows(), h.ncols()); - accu::image::init(h_2d_a); - - accu::image::take( unproject( h_2d_a, - h.domain(), - fun::v2v::projection<point3d, 2>() ).rw(), - h ); - - image2d<float> h_2d = accu::image::to_result(h_2d_a); - io::pgm::save( data::stretch( int_u8(), - data::transform( h_2d, - take_log() ) ), - "h_2d.pgm" ); - } + image2d<float> proj = project_histo<accu::sum<unsigned>, 2>(histo); + image2d<value::int_u8> proj_int = data::stretch( value::int_u8(), + data::transform( proj, + take_log() ) ); + io::pgm::save(proj_int, argv[2]); // std::cout << " => computing reverted histogram..." << std::endl; // image3d<unsigned> reverted = arith::revert(histo); Index: trunk/milena/sandbox/folio/mln/histo/compute_histo_rgb.hh =================================================================== --- trunk/milena/sandbox/folio/mln/histo/compute_histo_rgb.hh (revision 3938) +++ trunk/milena/sandbox/folio/mln/histo/compute_histo_rgb.hh (revision 3939) @@ -8,6 +8,7 @@ #include <mln/value/int_u8.hh> #include <mln/value/rgb8.hh> #include <iostream> +#include <mln/trait/value/comp.hh> namespace mln { @@ -17,11 +18,16 @@ template <typename C, typename T> image3d<C> compute_histo_rgb(image2d<T> ima) { - // out - typedef typename trait::value_<T>::comp enc; - image3d<C> out(mln_max(enc) + abs(mln_min(enc) + 1), - mln_max(enc) + abs(mln_min(enc) + 1), - mln_max(enc) + abs(mln_min(enc) + 1)); + 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(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); // count