r3996: Tests around projected histograms for the report

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-06-05 Etienne FOLIO <folio@lrde.epita.fr> Tests around projected histograms for the report. * folio/test/histo/classify_with_histo_rgb.cc: . * folio/test/histo/project_histo_add.cc: New. * folio/test/histo/project_screen.cc: New. * folio/test/histo/projected3d.cc: . * folio/test/value/comp.cc: New. --- histo/classify_with_histo_rgb.cc | 13 +++ histo/project_histo_add.cc | 138 ++++++++++++++++++++++++++++++++++++ histo/project_screen.cc | 149 +++++++++++++++++++++++++++++++++++++++ histo/projected3d.cc | 50 ++++++------- value/comp.cc | 9 ++ 5 files changed, 334 insertions(+), 25 deletions(-) Index: trunk/milena/sandbox/folio/test/histo/project_histo_add.cc =================================================================== --- trunk/milena/sandbox/folio/test/histo/project_histo_add.cc (revision 0) +++ trunk/milena/sandbox/folio/test/histo/project_histo_add.cc (revision 3996) @@ -0,0 +1,138 @@ +#include <mln/core/var.hh> + +#include <mln/core/image/image1d.hh> +#include <mln/core/image/image2d.hh> +#include <mln/core/image/dmorph/unproject_image.hh> +#include <mln/fun/v2v/projection.hh> + +#include <mln/core/image/dmorph/image_if.hh> +#include <mln/pw/value.hh> +#include <mln/data/transform.hh> +#include <mln/data/stretch.hh> + +#include <mln/arith/revert.hh> +#include <mln/core/alias/neighb3d.hh> +#include <mln/value/label_8.hh> + +#include <mln/morpho/closing/volume.hh> +#include <mln/morpho/watershed/flooding.hh> +#include <mln/morpho/elementary/dilation.hh> + +#include "../../mln/histo/compute_histo_rgb.hh" +#include "../../mln/histo/classify_with_histo_rgb.hh" + +#include <mln/accu/count.hh> +#include <mln/accu/mean.hh> +#include <mln/accu/sum.hh> +#include <mln/accu/image/init.hh> +#include <mln/accu/image/take.hh> +#include <mln/accu/image/to_result.hh> + +#include <mln/io/ppm/load.hh> +#include <mln/io/ppm/save.hh> +#include <mln/io/pgm/save.hh> +#include <mln/debug/println.hh> + + +namespace mln +{ + + struct rgb8to6 : Function_v2v< rgb8to6 > + { + typedef value::rgb<6> result; + value::rgb<6> operator()(const value::rgb<8>& c) const + { + value::rgb<6> res(c.red() / 4, c.green() / 4, c.blue() / 4); + return res; + } + }; + + struct take_log : Function_v2v< take_log > + { + typedef float result; + float operator()(float f) const + { + mln_precondition(f > 0); + return std::log(f + 1); + } + }; + + template <typename A, unsigned direction, typename V> + image2d<mln_result(A)> + 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[]) +{ + if (argc != 3) + { + std::cout << "Usage:" << std::endl + << "./a.out <ima_in> <ima_out>" << std::endl; + } + + using namespace mln; + + using value::int_u8; + typedef value::rgb<6> rgb6; + typedef value::int_u<6> int_u6; + + std::cout << " => loading " << argv[1] << "..." << std::endl; + image2d<value::rgb8> ima; + io::ppm::load(ima, argv[1]); +// image2d<rgb6> ima6 = data::transform(ima, rgb8to6()); + + std::cout << " => computing histogram..." << std::endl; + image3d<unsigned> histo = histo::compute_histo_rgb<unsigned>(ima); + + image2d<unsigned> proj = project_histo<accu::sum<unsigned, 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); + +// std::cout << " => computing closure..." << std::endl; +// image3d<unsigned> closed = +// morpho::closing::volume(reverted, c6(), atoi(argv[2])); + +// std::cout << " => computing watershed..." << std::endl; +// value::label_8 nbasin; +// image3d<value::label_8> labels = +// morpho::watershed::flooding(closed, c6(), nbasin); +// std::cout << "found " << nbasin << " labels" << std::endl; + +// labels = morpho::elementary::dilation(labels, c18()); + +// std::cout << " => computing output labelized image..." << std::endl; +// image2d<value::label_8> lab = histo::classify_with_histo_rgb(ima, labels); + +// std::cout << " => computing projection..." << std::endl; + +// typedef accu::mean<int_u8, unsigned, int_u8> A; +// image2d<A> vmean(lab.nrows(), lab.ncols()); +// accu::image::init(vmean); +// { +// fun::v2v::projection<point3d, 0> vproj; +// mln_VAR( vmean_, unproject(vmean, lab.domain(), vproj) ); +// accu::image::take(vmean_, lab); +// } + +// std::cout << " => saving " << argv[2] << "..." << std::endl; +// io::ppm::save(vmean, argv[2]); + +} Index: trunk/milena/sandbox/folio/test/histo/project_screen.cc =================================================================== --- trunk/milena/sandbox/folio/test/histo/project_screen.cc (revision 0) +++ trunk/milena/sandbox/folio/test/histo/project_screen.cc (revision 3996) @@ -0,0 +1,149 @@ +#include <mln/core/var.hh> + +#include <mln/core/image/image1d.hh> +#include <mln/core/image/image2d.hh> +#include <mln/core/image/dmorph/unproject_image.hh> +#include <mln/fun/v2v/projection.hh> + +#include <mln/core/image/dmorph/image_if.hh> +#include <mln/pw/value.hh> +#include <mln/data/transform.hh> +#include <mln/data/stretch.hh> + +#include <mln/arith/revert.hh> +#include <mln/core/alias/neighb3d.hh> +#include <mln/value/label_8.hh> + +#include <mln/morpho/closing/volume.hh> +#include <mln/morpho/watershed/flooding.hh> +#include <mln/morpho/elementary/dilation.hh> + +#include "../../mln/histo/compute_histo_rgb.hh" +#include "../../mln/histo/classify_with_histo_rgb.hh" + +#include <mln/accu/count.hh> +#include <mln/accu/mean.hh> +#include <mln/accu/sum.hh> +#include <mln/accu/image/init.hh> +#include <mln/accu/image/take.hh> +#include <mln/accu/image/to_result.hh> + +#include <mln/io/ppm/load.hh> +#include <mln/io/ppm/save.hh> +#include <mln/io/pgm/save.hh> +#include <mln/debug/println.hh> + + +namespace mln +{ + + struct rgb8to6 : Function_v2v< rgb8to6 > + { + typedef value::rgb<6> result; + value::rgb<6> operator()(const value::rgb<8>& c) const + { + value::rgb<6> res(c.red() / 4, c.green() / 4, c.blue() / 4); + return res; + } + }; + + struct take_log : Function_v2v< take_log > + { + typedef float result; + float operator()(float f) const + { + mln_precondition(f > 0); + return std::log(f + 1); + } + }; + + template <typename A, unsigned direction, typename V> + image2d<mln_result(A)> + 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); + } + +void +save_proj_histo(image3d<unsigned> histo, char* name) +{ + std::cout << " => save..." << std::endl; + image2d<unsigned> proj = project_histo<accu::sum<unsigned, unsigned>, 2>(histo); + image2d<value::int_u8> proj_int = data::stretch( value::int_u8(), + data::transform( proj, + take_log() ) ); + io::pgm::save(proj_int, name); +} + +} + + +int main(int argc, char* argv[]) +{ + if (argc != 3) + { + std::cout << "Usage:" << std::endl + << "./a.out <ima_in> <ima_out>" << std::endl; + } + + using namespace mln; + + using value::int_u8; + typedef value::rgb<6> rgb6; + typedef value::int_u<6> int_u6; + + std::cout << " => loading " << argv[1] << "..." << std::endl; + image2d<value::rgb8> ima; + io::ppm::load(ima, argv[1]); + image2d<rgb6> ima6 = data::transform(ima, rgb8to6()); + + std::cout << " => computing histogram..." << std::endl; + image3d<unsigned> histo = histo::compute_histo_rgb<unsigned>(ima6); +// save_proj_histo(histo, argv[2]); + + std::cout << " => computing reverted histogram..." << std::endl; + image3d<unsigned> reverted = arith::revert(histo); + + std::cout << " => computing closure..." << std::endl; + image3d<unsigned> closed = + morpho::closing::volume(reverted, c6(), atoi(argv[3])); + + // std::cout << " => computing rereverted histo..." << std::endl; + // image3d<unsigned> reverted2 = arith::revert(closed); +// save_proj_histo(reverted2, argv[4]); + + std::cout << " => computing watershed..." << std::endl; + value::label_8 nbasin; + image3d<value::label_8> labels = + morpho::watershed::flooding(closed, c6(), nbasin); + std::cout << "found " << nbasin << " labels" << std::endl; + + labels = morpho::elementary::dilation(labels, c18()); + + std::cout << " => computing output labelized image..." << std::endl; + image2d<value::label_8> lab = histo::classify_with_histo_rgb(ima, labels); + io::pgm::save(lab, "labelized.pgm"); + +// std::cout << " => computing projection..." << std::endl; + +// typedef accu::mean<int_u8, unsigned, int_u8> A; +// image2d<A> vmean(lab.nrows(), lab.ncols()); +// accu::image::init(vmean); +// { +// fun::v2v::projection<point3d, 0> vproj; +// mln_VAR( vmean_, unproject(vmean, lab.domain(), vproj) ); +// accu::image::take(vmean_, lab); +// } + +// std::cout << " => saving " << argv[2] << "..." << std::endl; +// io::ppm::save(vmean, argv[2]); + +} Index: trunk/milena/sandbox/folio/test/histo/projected3d.cc =================================================================== --- trunk/milena/sandbox/folio/test/histo/projected3d.cc (revision 3995) +++ trunk/milena/sandbox/folio/test/histo/projected3d.cc (revision 3996) @@ -58,7 +58,7 @@ }; template <typename A, unsigned direction, typename V> - image2d<float> + image2d<mln_result(A)> project_histo(const image3d<V>& h) { image2d<A> h_2d_a(h.nrows(), h.ncols()); @@ -97,31 +97,31 @@ std::cout << " => computing histogram..." << std::endl; image3d<unsigned> histo = histo::compute_histo_rgb<unsigned>(ima); - 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); - -// std::cout << " => computing closure..." << std::endl; -// image3d<unsigned> closed = -// morpho::closing::volume(reverted, c6(), atoi(argv[2])); - -// std::cout << " => computing watershed..." << std::endl; -// value::label_8 nbasin; -// image3d<value::label_8> labels = -// morpho::watershed::flooding(closed, c6(), nbasin); -// std::cout << "found " << nbasin << " labels" << std::endl; + // image2d<unsigned> proj = project_histo<accu::sum<unsigned, 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); + + std::cout << " => computing closure..." << std::endl; + image3d<unsigned> closed = + morpho::closing::volume(reverted, c6(), atoi(argv[2])); + + std::cout << " => computing watershed..." << std::endl; + value::label_8 nbasin; + image3d<value::label_8> labels = + morpho::watershed::flooding(closed, c6(), nbasin); + std::cout << "found " << nbasin << " labels" << std::endl; -// labels = morpho::elementary::dilation(labels, c18()); + labels = morpho::elementary::dilation(labels, c18()); -// std::cout << " => computing output labelized image..." << std::endl; -// image2d<value::label_8> lab = histo::classify_with_histo_rgb(ima, labels); + std::cout << " => computing output labelized image..." << std::endl; + image2d<value::label_8> lab = histo::classify_with_histo_rgb(ima, labels); -// std::cout << " => computing projection..." << std::endl; + std::cout << " => computing projection..." << std::endl; // typedef accu::mean<int_u8, unsigned, int_u8> A; // image2d<A> vmean(lab.nrows(), lab.ncols()); @@ -132,7 +132,7 @@ // accu::image::take(vmean_, lab); // } -// std::cout << " => saving " << argv[2] << "..." << std::endl; -// io::ppm::save(vmean, argv[2]); + std::cout << " => saving " << argv[2] << "..." << std::endl; + io::ppm::save(vmean, argv[2]); } Index: trunk/milena/sandbox/folio/test/histo/classify_with_histo_rgb.cc =================================================================== --- trunk/milena/sandbox/folio/test/histo/classify_with_histo_rgb.cc (revision 3995) +++ trunk/milena/sandbox/folio/test/histo/classify_with_histo_rgb.cc (revision 3996) @@ -81,6 +81,19 @@ image3d<value::label_8> labels = morpho::watershed::flooding(closed, c6(), nbasin); std::cout << "found " << nbasin << " labels" << std::endl; + // // Create output image + // image2d<value::label_8> out; + // initialize(out, ima); + + // // Fill output image + // mln_fwd_piter_(image2d<rgb6>) p(ima.domain()); + // for_all(p) + // { + // // get 3d point in regions image. + // point3d p3 = point3d(ima(p).red(), ima(p).green(), ima(p).blue()); + // out(p) = labels(p3); + // } + labels = morpho::elementary::dilation(labels, c18()); std::cout << " => computing output labelized image..." << std::endl; Index: trunk/milena/sandbox/folio/test/value/comp.cc =================================================================== --- trunk/milena/sandbox/folio/test/value/comp.cc (revision 0) +++ trunk/milena/sandbox/folio/test/value/comp.cc (revision 3996) @@ -0,0 +1,9 @@ +#include <iostream> +#include <mln/value/rgb8.hh> + +int main() +{ + using namespace mln; + value::rgb8 v(1, 2, 3); + std::cout << v.comp(0); // Prints `1' +}
participants (1)
-
Etienne FOLIO