https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Update src of 'color labeling mean'.
* theo/exec/color_labeling_mean.cc: Update.
color_labeling_mean.cc | 36 +++++++++++++++++++++++++++---------
1 file changed, 27 insertions(+), 9 deletions(-)
Index: theo/exec/color_labeling_mean.cc
--- theo/exec/color_labeling_mean.cc (revision 3684)
+++ theo/exec/color_labeling_mean.cc (working copy)
@@ -6,6 +6,8 @@
#include <mln/level/transform.hh>
#include <mln/value/label_8.hh>
+#include <mln/value/int_u16.hh>
+#include <mln/level/convert.hh>
#include <mln/io/pgm/load.hh>
#include <mln/io/ppm/load.hh>
@@ -13,32 +15,48 @@
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.ppm
label.pgm output.pgm" << std::endl
+ << " Replace every label by its mean color value." <<
std::endl;
+ std::abort();
+}
int main(int argc, char* argv[])
{
using namespace mln;
using value::int_u8;
+ using value::int_u16;
using value::label_8;
using value::rgb8;
+ if (argc != 4)
+ usage(argv);
+
+
+ image2d<rgb8> ima;
+ io::ppm::load(ima, argv[1]);
+
+
image2d<int_u8> lab;
- io::pgm::load(lab, argv[1]);
+ io::pgm::load(lab, argv[2]);
- int_u8 min, nlabels;
- estim::min_max(lab, min, nlabels);
+ image2d<int_u16> lab_ = level::convert(int_u16(), lab);
- std::cout << min << ' ' << nlabels << std::endl;
+ int_u16 min, nlabels;
+ estim::min_max(lab_, min, nlabels);
- image2d<rgb8> ima;
- io::ppm::load(ima, argv[2]);
+ std::cout << "n labels = " << nlabels << std::endl;
accu::mean<rgb8> m_;
typedef algebra::vec<3,float> V;
- util::array<V> m = labeling::compute(m_, ima, lab, nlabels);
+ util::array<V> m = labeling::compute(m_, ima, lab_, nlabels);
+
+ util::array<rgb8> c(unsigned(nlabels) + 1);
- util::array<rgb8> c(nlabels + 1);
- for (unsigned l = 0; l <= nlabels; ++l)
+ c[0] = rgb8(0,0,0);
+ for (unsigned l = 1; l <= nlabels; ++l)
{
c[l].red() = m[l][0];
c[l].green() = m[l][1];