URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-05-28 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Add tools for plotting multiple points in an image.
* fabien/igr/min_max_float.cc: Return min and max values of an image.
* fabien/igr/plot_points/Makefile: New Makefile for plot tools.
* fabien/igr/plot_points/README: Explain how tools works.
* fabien/igr/plot_points/main.cc: Plot all points in an image.
* fabien/igr/plot_points/plot_points_of_label.cc: Plot all points of
a specific label.
---
min_max_float.cc | 89 ++++++++++++++++++++++++++++++++++++
plot_points/Makefile | 11 ++++
plot_points/README | 2
plot_points/main.cc | 77 +++++++++++++++++++++++++++++++
plot_points/plot_points_of_label.cc | 88 +++++++++++++++++++++++++++++++++++
5 files changed, 267 insertions(+)
Index: trunk/milena/sandbox/fabien/igr/min_max_float.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/min_max_float.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/min_max_float.cc (revision 3914)
@@ -0,0 +1,89 @@
+#include <iostream>
+#include <cmath>
+#include <mln/core/image/image1d.hh>
+#include <mln/core/image/image3d.hh>
+
+#include <mln/io/dump/all.hh>
+#include <mln/io/plot/save.hh>
+
+#include <mln/value/int_u12.hh>
+
+#include <mln/histo/array.hh>
+#include <mln/histo/compute.hh>
+#include <mln/level/transform.hh>
+
+
+namespace mln
+{
+ struct int_u12_from_float : Function_v2v< int_u12_from_float >
+ {
+ int_u12_from_float(float min, float max)
+ {
+ min_ = min;
+ max_ = max;
+ }
+
+ typedef value::int_u12 result;
+ float min_;
+ float max_;
+
+ result operator()(float f) const
+ {
+ if (f > max_)
+ f = max_;
+ f -= min_;
+ f /= (max_ - min_);
+ f *= 4095; // int_u12 max
+
+ return (int) floor(f);
+ }
+ };
+
+} // end of namespace mln
+
+
+///////////////////
+// //
+// Main Function //
+// //
+///////////////////
+
+
+int main(int argc, char *argv[])
+{
+ using namespace mln;
+
+ if (argc != 2)
+ {
+ std::cout << "Usage: " << argv[0] << "
ima.dump"
+ << std::endl;
+ return 1;
+ }
+
+ float min = 1;
+ float max = -1;
+
+ image3d<float> input;
+ io::dump::load(input, argv[1]);
+
+ mln_piter_(image3d<float>) p(input.domain());
+ for_all(p)
+ {
+ if (input(p) > max)
+ max = input(p);
+ if (input(p) < min)
+ min = input(p);
+ }
+
+ std::cout << "min: " << min << std::endl;
+ std::cout << "max: " << max << std::endl;
+
+ /*image3d<value::int_u12> quantified = level::transform(input,
int_u12_from_float(min, max));
+
+ histo::array<value::int_u12> histogram = histo::compute(quantified);
+ image1d<value::int_u12> hist_ima;
+ convert::from_to(histogram, hist_ima);
+ io::plot::save(hist_ima, "histogram.plot");*/
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/plot_points/plot_points_of_label.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/plot_points/plot_points_of_label.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/plot_points/plot_points_of_label.cc (revision 3914)
@@ -0,0 +1,88 @@
+#include <sstream>
+
+#include <mln/core/image/image1d.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/dmorph/image_if.hh>
+#include <mln/core/image/dmorph/slice_image.hh>
+#include <mln/core/routine/duplicate.hh>
+#include <mln/core/var.hh>
+
+#include <mln/io/dump/all.hh>
+#include <mln/io/plot/save.hh>
+
+#include <mln/value/int_u12.hh>
+#include <mln/value/label_16.hh>
+
+#include <mln/pw/all.hh>
+#include <mln/util/array.hh>
+
+
+using namespace mln;
+using value::int_u12;
+using value::label_16;
+
+
+
+
+int usage(const char* bin)
+{
+ std::cout << "Usage: " << bin << " input.dump wst.dump
label" << std::endl;
+ return 1;
+}
+
+int main(int argc, char* argv[])
+{
+ if (argc != 4)
+ return usage(argv[0]);
+
+ unsigned label = atoi(argv[3]);
+
+
+ // Initialization.
+ typedef int_u12 V;
+ image3d<V> input;
+ io::dump::load(input, argv[1]);
+ typedef image2d<util::array<V> > I;
+ I ima_arr;
+ initialize(ima_arr, slice(input, 0));
+ for (unsigned int i = 0; i < input.nslices(); ++i)
+ {
+ image2d<V> tmp_slice = duplicate(slice(input, i));
+ mln_piter_(image2d<V>) p(tmp_slice.domain());
+ for_all(p)
+ ima_arr(p).append(tmp_slice(p));
+ }
+
+ image2d<label_16> ima_labels;
+ io::dump::load(ima_labels, argv[2]);
+
+ // Plot points.
+ int origin_x = ima_arr.bbox().pmin()[1];
+ int origin_y = ima_arr.bbox().pmin()[0];
+
+ mln_VAR(ima_if, ima_arr | pw::value(ima_labels) == pw::cst(label));
+ mln_piter_(ima_if_t) p(ima_if.domain());
+ for_all(p)
+ {
+ int x = p[1] - origin_x;
+ int y = p[0] - origin_y;
+ std::ostringstream slabel;
+ slabel << "x";
+ if (x < 100)
+ slabel << "0";
+ if (x < 10)
+ slabel << "0";
+ slabel << x << "_y";
+ if (y < 100)
+ slabel << "0";
+ if (y < 10)
+ slabel << "0";
+ slabel << y << ".plot";
+
+ io::plot::save(ima_arr(p), slabel.str());
+ }
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/plot_points/main.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/plot_points/main.cc (revision 0)
+++ trunk/milena/sandbox/fabien/igr/plot_points/main.cc (revision 3914)
@@ -0,0 +1,77 @@
+#include <sstream>
+
+#include <mln/core/image/image1d.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/slice_image.hh>
+#include <mln/core/routine/duplicate.hh>
+
+#include <mln/io/dump/all.hh>
+#include <mln/io/plot/save.hh>
+
+#include <mln/value/int_u12.hh>
+#include <mln/util/array.hh>
+
+
+using namespace mln;
+using value::int_u12;
+
+
+
+
+int usage(const char* bin)
+{
+ std::cout << "Usage: " << bin << " input.dump"
<< std::endl;
+ return 1;
+}
+
+int main(int argc, char* argv[])
+{
+ if (argc != 2)
+ return usage(argv[0]);
+
+
+ // Initialization.
+ typedef int_u12 V;
+ image3d<V> input;
+ io::dump::load(input, argv[1]);
+ typedef image2d<util::array<V> > I;
+ I ima_arr;
+ initialize(ima_arr, slice(input, 0));
+ for (unsigned int i = 0; i < input.nslices(); ++i)
+ {
+ image2d<V> tmp_slice = duplicate(slice(input, i));
+ mln_piter_(image2d<V>) p(tmp_slice.domain());
+ for_all(p)
+ ima_arr(p).append(tmp_slice(p));
+ }
+
+
+ // Plot points.
+ int origin_x = ima_arr.bbox().pmin()[1];
+ int origin_y = ima_arr.bbox().pmin()[0];
+
+ mln_piter_(I) p (ima_arr.domain());
+ for_all(p)
+ {
+ int x = p[1] - origin_x;
+ int y = p[0] - origin_y;
+ std::ostringstream slabel;
+ slabel << "x";
+ if (x < 100)
+ slabel << "0";
+ if (x < 10)
+ slabel << "0";
+ slabel << x << "_y";
+ if (y < 100)
+ slabel << "0";
+ if (y < 10)
+ slabel << "0";
+ slabel << y << ".plot";
+
+ io::plot::save(ima_arr(p), slabel.str());
+ }
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/igr/plot_points/Makefile
===================================================================
--- trunk/milena/sandbox/fabien/igr/plot_points/Makefile (revision 0)
+++ trunk/milena/sandbox/fabien/igr/plot_points/Makefile (revision 3914)
@@ -0,0 +1,11 @@
+include ../Makefile.rules
+
+all: main.cc
+ ${CXX} -I../../../../ ${CXXFLAGS} $^ -o plot_all_points
+
+plot_points_of_label: plot_points_of_label.cc
+ ${CXX} -I../../../../ ${CXXFLAGS} $^ -o plot_points_all_label
+
+
+clean:
+ rm -rf *.dump *.p?m *.plot *.log *.csv *.dSYM
Index: trunk/milena/sandbox/fabien/igr/plot_points/README
===================================================================
--- trunk/milena/sandbox/fabien/igr/plot_points/README (revision 0)
+++ trunk/milena/sandbox/fabien/igr/plot_points/README (revision 3914)
@@ -0,0 +1,2 @@
+This directory is used for demonstrating that different points of the same label share
the same behavior.
+We show this by extracting plot functions.