https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
INIM: Classif: Make palette.
* classif/iccvg04.cc: Beautify.
* classif/proj.hh: Add palette creation.
* classif/v2.cc: Avoid useless implicit cast.
* classif/Makefile: Change default streching.
Makefile | 2 +-
iccvg04.cc | 9 +++++----
proj.hh | 26 ++++++++++++++++++++++----
v2.cc | 5 ++++-
4 files changed, 32 insertions(+), 10 deletions(-)
Index: classif/iccvg04.cc
--- classif/iccvg04.cc (revision 2734)
+++ classif/iccvg04.cc (working copy)
@@ -96,7 +96,8 @@
sum[w] += histo(p3) * convert::to< algebra::vec<3, value::int_u8>
>(p3);
}
- std::cerr << "p3 : " << p3 << " == " <<
convert::to<algebra::vec<3, value::int_u8> >(p3) << std::endl;
+ std::cerr << "p3 : " << p3 << " == " <<
+ convert::to<algebra::vec<3, value::int_u8> >(p3) << std::endl;
}
for (int i = 1; i < nbasins + 1; ++i)
@@ -118,10 +119,12 @@
//if w == 0, out(pi) = 0 ie is part of a border of the watershed
out(pi) = convert::to<value::rgb8>(sum[w]);
- std::cerr << "out(" << pi << ") = sum["
<< w << "]; //" << sum[w] << " : rgb8("
<< convert::to<value::rgb8>(sum[w]) << ")" <<
std::endl;
+ std::cerr << "out(" << pi << ") = sum["
<< w << "]; //"
+ << sum[w] << " : rgb8(" << sum[w] <<
")" << std::endl;
}
io::ppm::save(out, "out.ppm");
+ save_class(histo, ws, sum, "palette.ppm");
}
bool usage(int argc, char ** argv)
@@ -161,6 +164,4 @@
//classify image
classify_image(ima, histo, ws, nbasins, div_factor);
-
- save_class(histo_filtered, "histo.ppm");
}
Index: classif/proj.hh
--- classif/proj.hh (revision 2734)
+++ classif/proj.hh (working copy)
@@ -32,6 +32,8 @@
#include <mln/io/pgm/save.hh>
#include <mln/level/paste.hh>
#include <mln/accu/mean.hh>
+#include <mln/accu/max.hh>
+#include <mln/literal/white.hh>
namespace mln
{
@@ -50,12 +52,28 @@
return output;
}
- template <typename T>
+ template <typename T, typename U, typename K>
void
- save_class(const image3d<T>& histo, const char * fn)
+ save_class(const image3d<T>& histo, const image3d<U>& ws,
+ K mean, const char * fn)
{
- accu::mean<unsigned, unsigned long, value::int_u8> mean;
- io::pgm::save(proj(histo, mean), fn);
+
+ //accu::mean<unsigned, unsigned long, value::int_u8> mean_accu;
+ accu::max<value::int_u8> max_1;//FIXME: use majoritaire accu
+ image2d<value::int_u8> hproj = proj(histo, max_1);
+
+ accu::max<U> max_2;//FIXME: use majoritaire accu
+ image2d<U> proj_class = proj(ws, max_2);
+
+ image2d<value::rgb8> out(proj_class.domain());
+
+ level::fill(out, literal::white);
+ mln_piter(image2d<value::int_u8>) p(hproj.domain());
+ for_all(p)
+ if (hproj(p) > 0)
+ out(p) = convert::to<value::rgb8>(mean[proj_class(p)]);
+
+ io::ppm::save(out, fn);
}
} // end of namespace mln
Index: classif/v2.cc
--- classif/v2.cc (revision 2734)
+++ classif/v2.cc (working copy)
@@ -48,10 +48,13 @@
mln_piter(I) p(ima.domain());
for_all(p)
{
- algebra::vec<3, value::int_u8> v = make::vec(ima(p).red() / f,
+ //color at ima(p)
+ point3d v = point3d(ima(p).red() / f,
ima(p).green() / f,
ima(p).blue() / f);
+ //node the class of color with same density as v
point3d pn = run.parent(v);
+ //out(p) = color pn
out(p) = value::rgb8(pn[0] * f, pn[1] * f, pn[2] * f);
}
io::ppm::save(out, "tmp.ppm");
Index: classif/Makefile
--- classif/Makefile (revision 2734)
+++ classif/Makefile (working copy)
@@ -7,7 +7,7 @@
ICCVG_DBG=iccvg_dbg
IMG?=../../img/lena.ppm
-DIV?=8
+DIV?=4
LAMBDA?=10