URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-06-19 Etienne FOLIO <folio(a)lrde.epita.fr>
Add tools for histogram projections and visualization.
* folio/tools/histo/classify_with_histo.cc: Move file.
* folio/tools/histo/classify_with_histo_gs.cc: Moved file updated.
* folio/tools/histo/projected_histo_classified_color_maj.cc: New tool
(still buggy).
* folio/tools/histo/projected_histo_classified_gs.cc: New tool (still
buggy).
* folio/tools/histo/projected_histo_gs.cc: New tool.
---
classify_with_histo_gs.cc | 110 +++++++++++++++++++++
projected_histo_classified_color_maj.cc | 116 +++++++++++++++++++++++
projected_histo_classified_gs.cc | 116 +++++++++++++++++++++++
projected_histo_gs.cc | 161 +++++++++++---------------------
4 files changed, 398 insertions(+), 105 deletions(-)
Index: trunk/milena/sandbox/folio/tools/histo/classify_with_histo.cc (deleted)
===================================================================
Index: trunk/milena/sandbox/folio/tools/histo/projected_histo_gs.cc
===================================================================
--- trunk/milena/sandbox/folio/tools/histo/projected_histo_gs.cc (revision 4176)
+++ trunk/milena/sandbox/folio/tools/histo/projected_histo_gs.cc (revision 4177)
@@ -1,51 +1,44 @@
-#include <mln/core/var.hh>
+// 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/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/data/stretch.hh>
#include <mln/io/pgm/save.hh>
-#include <mln/debug/println.hh>
+#include <mln/io/ppm/load.hh>
+#include <mln/value/rgb8.hh>
+#include "../../mln/histo/compute_histo_3d.hh"
+#include "../../mln/histo/project_histo_3d.hh"
-namespace mln
-{
+using namespace mln;
+using namespace mln::value;
- struct rgb8to6 : Function_v2v< rgb8to6 >
- {
- typedef value::rgb<6> result;
- value::rgb<6> operator()(const value::rgb<8>& c) const
+
+namespace mln
{
- value::rgb<6> res(c.red() / 4, c.green() / 4, c.blue() / 4);
- return res;
- }
- };
struct take_log : Function_v2v< take_log >
{
@@ -57,82 +50,40 @@
}
};
- 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[])
+int
+main(int argc, char** argv)
{
- if (argc != 3)
+ // check arguments
+ if (argc != 4)
{
- std::cout << "Usage:" << std::endl
- << "./a.out <ima_in> <ima_out>" << std::endl;
+ 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);
}
- using namespace mln;
-
- using value::int_u8;
- 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> ima;
- io::ppm::load(ima, argv[1]);
-// image2d<rgb6> ima6 = data::transform(ima, rgb8to6());
+ image2d<value::rgb8> ima8;
+ io::ppm::load(ima8, argv[1]);
+ // build histo
std::cout << " => computing histogram..." << std::endl;
- image3d<unsigned> histo = histo::compute_histo_rgb<unsigned>(ima);
+ image3d<unsigned> histo = histo::compute_histo_3d(ima8);
- image2d<unsigned> proj = project_histo<accu::math::sum<unsigned,
unsigned>, 2>(histo);
- image2d<value::int_u8> proj_int = data::stretch( value::int_u8(),
+ // project it
+ image2d<unsigned> proj =
+ histo::project_histo<accu::math::sum<unsigned, unsigned>, 2>(histo);
+
+ // compute output image
+ image2d<value::int_u8> out = 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]);
-
+ // 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_classified_color_maj.cc
===================================================================
---
trunk/milena/sandbox/folio/tools/histo/projected_histo_classified_color_maj.cc (revision
0)
+++
trunk/milena/sandbox/folio/tools/histo/projected_histo_classified_color_maj.cc (revision
4177)
@@ -0,0 +1,116 @@
+// 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/accu/math/sum.hh>
+#include <mln/arith/revert.hh>
+#include <mln/core/alias/neighb3d.hh>
+#include <mln/data/stretch.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/project_histo_3d.hh"
+
+using namespace mln;
+using namespace mln::value;
+
+
+namespace mln
+{
+
+ struct take_log : Function_v2v< take_log >
+ {
+ typedef float result;
+ float operator()(float f) const
+ {
+ mln_precondition(f > 0);
+ return std::log(f + 1);
+ }
+ };
+
+}
+
+
+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);
+ }
+
+ // build test image
+ std::cout << " => loading " << argv[1] <<
"..." << std::endl;
+ image2d<value::rgb8> ima8;
+ io::ppm::load(ima8, argv[1]);
+
+ // build histo
+ std::cout << " => computing histogram..." << std::endl;
+ image3d<unsigned> histo = histo::compute_histo_3d(ima8);
+
+ // 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());
+
+ // FIXME
+ // {
+
+ // project it
+ image2d<rgb8> proj =
+ histo::project_histo<accu::maj<rgb8>, 2>(labels);
+
+ // compute output image
+ image2d<value::int_u8> out = data::stretch( value::int_u8(),
+ data::transform( proj,
+ take_log() ) );
+ // 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_classified_gs.cc
===================================================================
--- trunk/milena/sandbox/folio/tools/histo/projected_histo_classified_gs.cc (revision 0)
+++ trunk/milena/sandbox/folio/tools/histo/projected_histo_classified_gs.cc (revision
4177)
@@ -0,0 +1,116 @@
+// 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/accu/math/sum.hh>
+#include <mln/arith/revert.hh>
+#include <mln/core/alias/neighb3d.hh>
+#include <mln/data/stretch.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/project_histo_3d.hh"
+
+using namespace mln;
+using namespace mln::value;
+
+
+namespace mln
+{
+
+ struct take_log : Function_v2v< take_log >
+ {
+ typedef float result;
+ float operator()(float f) const
+ {
+ mln_precondition(f > 0);
+ return std::log(f + 1);
+ }
+ };
+
+}
+
+
+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);
+ }
+
+ // build test image
+ std::cout << " => loading " << argv[1] <<
"..." << std::endl;
+ image2d<value::rgb8> ima8;
+ io::ppm::load(ima8, argv[1]);
+
+ // build histo
+ std::cout << " => computing histogram..." << std::endl;
+ image3d<unsigned> histo = histo::compute_histo_3d(ima8);
+
+ // 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());
+
+ // FIXME
+ // {
+
+ // project it
+ image2d<unsigned> proj =
+ histo::project_histo<accu::math::sum<unsigned, unsigned>, 2>(labels);
+
+ // compute output image
+ image2d<int_u8> out = data::stretch( int_u8(),
+ data::transform( proj,
+ take_log() ) );
+ // }
+
+ // save output image
+ std::cout << " => saving " << argv[3] <<
"..." << std::endl;
+ io::pgm::save(out, argv[3]);
+}
Index: trunk/milena/sandbox/folio/tools/histo/classify_with_histo_gs.cc
===================================================================
--- trunk/milena/sandbox/folio/tools/histo/classify_with_histo_gs.cc (revision 0)
+++ trunk/milena/sandbox/folio/tools/histo/classify_with_histo_gs.cc (revision 4177)
@@ -0,0 +1,110 @@
+// 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/data/stretch.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(data::stretch(int_u8(), out), argv[3]);
+}