
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-06-19 Etienne FOLIO <folio@lrde.epita.fr> Clean up. * folio/mln/histo/classify_with_histo_3d.hh: New algorithm more generalist than the rgb version. * folio/mln/histo/compute_histo_3d.hh: Add macros. * folio/mln/histo/project_histo_3d.hh: Add macros. * folio/test/histo/classify_with_histo_rgb.cc: Move file. * folio/test/histo/project_histo_3d_add.cc: Update definitions. * folio/test/histo/project_histo_3d_mean.cc: Update definitions. * folio/tools/histo/classify_with_histo.cc: Moved file cleaned up. * folio/tools/histo/project_histo_add.cc: Move file. * folio/tools/histo/projected_histo_gs.cc: Moved file. --- mln/histo/classify_with_histo_3d.hh | 59 +++++++++++++++ mln/histo/compute_histo_3d.hh | 5 + mln/histo/project_histo_3d.hh | 5 + test/histo/project_histo_3d_add.cc | 2 test/histo/project_histo_3d_mean.cc | 2 tools/histo/classify_with_histo.cc | 109 ++++++++++++++++++++++++++++ tools/histo/projected_histo_gs.cc | 138 ++++++++++++++++++++++++++++++++++++ 7 files changed, 318 insertions(+), 2 deletions(-) Index: trunk/milena/sandbox/folio/test/histo/classify_with_histo_rgb.cc (deleted) =================================================================== Index: trunk/milena/sandbox/folio/test/histo/project_histo_3d_mean.cc =================================================================== --- trunk/milena/sandbox/folio/test/histo/project_histo_3d_mean.cc (revision 4174) +++ trunk/milena/sandbox/folio/test/histo/project_histo_3d_mean.cc (revision 4175) @@ -32,7 +32,7 @@ #include "../../mln/histo/project_histo_3d.hh" using namespace mln; -using namespace value; +using namespace mln::value; inline Index: trunk/milena/sandbox/folio/test/histo/project_histo_3d_add.cc =================================================================== --- trunk/milena/sandbox/folio/test/histo/project_histo_3d_add.cc (revision 4174) +++ trunk/milena/sandbox/folio/test/histo/project_histo_3d_add.cc (revision 4175) @@ -32,7 +32,7 @@ #include "../../mln/histo/project_histo_3d.hh" using namespace mln; -using namespace value; +using namespace mln::value; inline Index: trunk/milena/sandbox/folio/tools/histo/project_histo_add.cc (deleted) =================================================================== Index: trunk/milena/sandbox/folio/tools/histo/classify_with_histo.cc =================================================================== --- trunk/milena/sandbox/folio/tools/histo/classify_with_histo.cc (revision 0) +++ trunk/milena/sandbox/folio/tools/histo/classify_with_histo.cc (revision 4175) @@ -0,0 +1,109 @@ +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + + +#include <mln/arith/revert.hh> +#include <mln/core/alias/neighb3d.hh> +#include <mln/io/pgm/save.hh> +#include <mln/io/ppm/load.hh> +#include <mln/morpho/closing/volume.hh> +#include <mln/morpho/elementary/dilation.hh> +#include <mln/morpho/watershed/flooding.hh> +#include <mln/value/label_8.hh> + +#include "../../mln/histo/compute_histo_3d.hh" +#include "../../mln/histo/classify_with_histo_3d.hh" + +using namespace mln; +using namespace mln::value; + + +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; + } + }; + +} + + +int +main(int argc, char** argv) +{ + // check arguments + if (argc != 4) + { + std::cerr << "Usage:" << std::endl + << " ./a.out ../../../../img/lena.ppm 51 out.pgm" << std::endl + << std::endl + << "BTW, the number is the closure's lambda." << std::endl; + exit(1); + } + + typedef value::rgb<6> rgb6; + typedef value::int_u<6> int_u6; + + // build test image + std::cout << " => loading " << argv[1] << "..." << std::endl; + image2d<value::rgb8> ima8; + io::ppm::load(ima8, argv[1]); + image2d<rgb6> ima6 = data::transform(ima8, rgb8to6()); + + // build histo + std::cout << " => computing histogram..." << std::endl; + image3d<unsigned> histo = histo::compute_histo_3d(ima6); + + // build reverted histo + std::cout << " => computing reverted histogram..." << std::endl; + image3d<unsigned> reverted = arith::revert(histo); + + // compute morpho closure + std::cout << " => computing closure..." << std::endl; + image3d<unsigned> closed = morpho::closing::volume(reverted, c6(), atoi(argv[2])); + + // compute watershed transform + 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; + + // close maximas + labels = morpho::elementary::dilation(labels, c18()); + + // compute output image + std::cout << " => computing output labelized image..." << std::endl; + image2d<label_8> out = histo::classify_with_histo_3d(ima6, labels); + + // save output image + std::cout << " => saving " << argv[3] << "..." << std::endl; + io::pgm::save(out, argv[3]); +} Index: trunk/milena/sandbox/folio/tools/histo/projected_histo_gs.cc =================================================================== --- trunk/milena/sandbox/folio/tools/histo/projected_histo_gs.cc (revision 0) +++ trunk/milena/sandbox/folio/tools/histo/projected_histo_gs.cc (revision 4175) @@ -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/math/count.hh> +#include <mln/accu/stat/mean.hh> +#include <mln/accu/math/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::math::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::stat::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/mln/histo/project_histo_3d.hh =================================================================== --- trunk/milena/sandbox/folio/mln/histo/project_histo_3d.hh (revision 4174) +++ trunk/milena/sandbox/folio/mln/histo/project_histo_3d.hh (revision 4175) @@ -23,6 +23,9 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. +#ifndef PROJECT_HISTO_3D_HH_ +# define PROJECT_HISTO_3D_HH_ + #include <mln/accu/image/init.hh> #include <mln/accu/image/take.hh> @@ -54,3 +57,5 @@ } } + +#endif /* !PROJECT_HISTO_3D_HH_ */ Index: trunk/milena/sandbox/folio/mln/histo/classify_with_histo_3d.hh =================================================================== --- trunk/milena/sandbox/folio/mln/histo/classify_with_histo_3d.hh (revision 0) +++ trunk/milena/sandbox/folio/mln/histo/classify_with_histo_3d.hh (revision 4175) @@ -0,0 +1,59 @@ +// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef CLASSIFY_WITH_HISTO_3D_HH_ +# define CLASSIFY_WITH_HISTO_3D_HH_ + + +namespace mln +{ + + namespace histo + { + + template <typename T, typename C> + image2d<C> + classify_with_histo_3d(image2d<T>& ref, + image3d<C>& regions) + { + image2d<C> out; + initialize(out, ref); + + mln_fwd_piter(image2d<T>) p(ref.domain()); + for_all(p) + { + // get 3d point in regions image. + point3d p3 = point3d(ref(p).comp(0), ref(p).comp(1), ref(p).comp(2)); + out(p) = regions(p3); // copy the label in out's pixel. + } + + return out; + } + + } // end of namespace mln::histo + +} // end of namespace mln + +#endif /* !CLASSIFY_WITH_HISTO_3D_HH_ */ Index: trunk/milena/sandbox/folio/mln/histo/compute_histo_3d.hh =================================================================== --- trunk/milena/sandbox/folio/mln/histo/compute_histo_3d.hh (revision 4174) +++ trunk/milena/sandbox/folio/mln/histo/compute_histo_3d.hh (revision 4175) @@ -23,6 +23,9 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. +#ifndef COMPUTE_HISTO_3D_HH_ +# define COMPUTE_HISTO_3D_HH_ + #include <mln/core/image/image2d.hh> #include <mln/core/image/image3d.hh> @@ -60,3 +63,5 @@ } } + +#endif /* !COMPUTE_HISTO_3D_HH_ */
participants (1)
-
Etienne FOLIO