URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-03-13 Etienne FOLIO <folio(a)lrde.epita.fr>
Classification of 2D images with their respective RGB histograms.
* sandbox/folio/mln/histo/classify_with_histo_rgb.hh: New
algorithm that classifies an image 2d with its rgb histogram.
* sandbox/folio/mln/histo/compute_histo_rgb.hh: Use component of
value's trait.
* sandbox/folio/test/histo/classify_with_histo_rgb.cc: New test
for the classification of 2d images with their respective RGB
histograms.
* sandbox/folio/test/histo/compute_histo_rgb.cc: Correct an include.
* sandbox/folio/test/histo/compute_histo_rgb_from_ppm.cc: New test
for building an histogram with a ppm image.
---
mln/histo/classify_with_histo_rgb.hh | 40 +++++++++++++
mln/histo/compute_histo_rgb.hh | 11 ++-
test/histo/classify_with_histo_rgb.cc | 89 +++++++++++++++++++++++++++++++
test/histo/compute_histo_rgb.cc | 2
test/histo/compute_histo_rgb_from_ppm.cc | 30 ++++++++++
5 files changed, 166 insertions(+), 6 deletions(-)
Index: trunk/milena/sandbox/folio/test/histo/compute_histo_rgb_from_ppm.cc
===================================================================
--- trunk/milena/sandbox/folio/test/histo/compute_histo_rgb_from_ppm.cc (revision 0)
+++ trunk/milena/sandbox/folio/test/histo/compute_histo_rgb_from_ppm.cc (revision 3530)
@@ -0,0 +1,30 @@
+/*!
+ * \file compute_histo_rgb_from_ppm.cc
+ * \author etiennefolio <ornthalas(a)gmail.com>
+ */
+
+#include <iostream>
+#include <mln/debug/println.hh>
+
+#include <mln/io/ppm/load.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/level/stretch.hh>
+
+#include "../../mln/histo/compute_histo_rgb.hh"
+
+int main()
+{
+ using namespace mln;
+
+ // build test image
+ image2d<value::rgb8> ima;
+ io::ppm::load(ima, "../../../../img/lena.ppm");
+
+ // let's run !
+ image3d<value::int_u8> out = histo::compute_histo_rgb<value::int_u8>(ima);
+
+ // output ?
+ // FIXME: need projection to visualize.
+
+ return 0;
+}
Index: trunk/milena/sandbox/folio/test/histo/compute_histo_rgb.cc
===================================================================
--- trunk/milena/sandbox/folio/test/histo/compute_histo_rgb.cc (revision 3529)
+++ trunk/milena/sandbox/folio/test/histo/compute_histo_rgb.cc (revision 3530)
@@ -7,7 +7,7 @@
#include <mln/debug/println.hh>
#include <mln/literal/all.hh>
-#include "../../histo/compute_histo_rgb.hh"
+#include "../../mln/histo/compute_histo_rgb.hh"
int main()
{
Index: trunk/milena/sandbox/folio/test/histo/classify_with_histo_rgb.cc
===================================================================
--- trunk/milena/sandbox/folio/test/histo/classify_with_histo_rgb.cc (revision 0)
+++ trunk/milena/sandbox/folio/test/histo/classify_with_histo_rgb.cc (revision 3530)
@@ -0,0 +1,89 @@
+/*!
+ * \file classify_with_histo_rgb.cc
+ * \author etiennefolio <ornthalas(a)gmail.com>
+ */
+
+#include <iostream>
+#include <mln/debug/println.hh>
+#include <mln/debug/slices_2d.hh>
+
+#include <mln/io/ppm/load.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/data/fill.hh>
+#include <mln/literal/all.hh>
+
+#include <mln/arith/revert.hh>
+#include <mln/core/alias/neighb3d.hh>
+#include <mln/morpho/closing/volume.hh>
+#include <mln/value/label_8.hh>
+#include <mln/morpho/watershed/flooding.hh>
+
+#include "../../mln/histo/compute_histo_rgb.hh"
+#include "../../mln/histo/classify_with_histo_rgb.hh"
+
+#include <mln/level/transform.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;
+ }
+ };
+}
+
+int main(int argc, char** argv)
+{
+ using namespace mln;
+
+ // check arguments
+ if (argc < 3)
+ {
+ std::cerr << "Usage:" << std::endl
+ << " ./a.out ../../../../lena.ppm 51" << 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> lena;
+ io::ppm::load(lena, argv[1]);
+ image2d<rgb6> ima = level::transform(lena, rgb8to6());
+
+ // let's run !
+ std::cout << " => computing histogram..." << std::endl;
+ image3d<unsigned> histo = histo::compute_histo_rgb<unsigned>(ima);
+
+ std::cout << " => computing reverted histogram..." <<
std::endl;
+ image3d<unsigned> reverted = arith::revert(histo);
+
+// std::cout << " => dump it to reverted.pgm..." <<
std::endl;
+// image2d<int_u6> d1 = debug::slices_2d(reverted, 1.f, 0);
+// io::pgm::save(d1, "reverted.pgm");
+
+ 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;
+
+ std::cout << " => computing output labelized image..." <<
std::endl;
+ image2d<value::label_8> out = histo::classify_with_histo_rgb(ima, labels);
+
+ std::cout << " => saving out.ppm..." << std::endl;
+ io::pgm::save(out, "out.ppm");
+
+ return 0;
+}
Index: trunk/milena/sandbox/folio/mln/histo/classify_with_histo_rgb.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/histo/classify_with_histo_rgb.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/histo/classify_with_histo_rgb.hh (revision 3530)
@@ -0,0 +1,40 @@
+/*!
+ * \file classify_with_histo.hh
+ * \author etiennefolio <ornthalas(a)gmail.com>
+ */
+
+
+#ifndef CLASSIFY_WITH_HISTO_HH_
+# define CLASSIFY_WITH_HISTO_HH_
+
+namespace mln
+{
+
+ namespace histo
+ {
+
+ template <typename T, typename C>
+ image2d<C>
+ classify_with_histo_rgb(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).red(), ref(p).green(), ref(p).blue());
+
+ 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_HH_ */
Index: trunk/milena/sandbox/folio/mln/histo/compute_histo_rgb.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/histo/compute_histo_rgb.hh (revision 3529)
+++ trunk/milena/sandbox/folio/mln/histo/compute_histo_rgb.hh (revision 3530)
@@ -8,6 +8,7 @@
#include <mln/value/int_u8.hh>
#include <mln/value/rgb8.hh>
#include <iostream>
+
namespace mln
{
namespace histo
@@ -17,11 +18,11 @@
image3d<C> compute_histo_rgb(image2d<T> ima)
{
// out
- typedef value::int_u8::enc 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);
- data::fill(out, mln_min(C));
+ 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));
+ data::fill(out, 0);
// count
mln_fwd_piter(image2d<T>) p(ima.domain());