* apps/morphers/recorder-wst.cc: New.
* apps/morphers/Makefile.am (noinst_PROGRAMS): Add recorder-wst.
(recorder_wst_SOURCES): New.
(MOSTLYCLEANFILES): lena-wst??????.ppm.
---
milena/ChangeLog | 9 +++
milena/apps/morphers/Makefile.am | 3 +
milena/apps/morphers/recorder-wst.cc | 106 ++++++++++++++++++++++++++++++++++
3 files changed, 118 insertions(+), 0 deletions(-)
create mode 100644 milena/apps/morphers/recorder-wst.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 4b904dc..2b98497 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,14 @@
2011-11-24 Roland Levillain <roland(a)lrde.epita.fr>
+ New morpher example: recording a watershed transform.
+
+ * apps/morphers/recorder-wst.cc: New.
+ * apps/morphers/Makefile.am (noinst_PROGRAMS): Add recorder-wst.
+ (recorder_wst_SOURCES): New.
+ (MOSTLYCLEANFILES): lena-wst??????.ppm.
+
+2011-11-24 Roland Levillain <roland(a)lrde.epita.fr>
+
Work around decorated_image's lack of properties, for the recorder.
* apps/morphers/recorder.hh
diff --git a/milena/apps/morphers/Makefile.am b/milena/apps/morphers/Makefile.am
index d448c1d..a3b9a41 100644
--- a/milena/apps/morphers/Makefile.am
+++ b/milena/apps/morphers/Makefile.am
@@ -25,15 +25,18 @@ AM_CXXFLAGS = $(APPS_CXXFLAGS)
noinst_PROGRAMS = \
mask+channel \
recorder \
+ recorder-wst \
mask+recorder
mask_channel_SOURCES = mask+channel.cc
recorder_SOURCES = recorder.cc recorder.hh
+recorder_wst_SOURCES = recorder-wst.cc recorder.hh
mask_recorder_SOURCES = mask+recorder.cc recorder.hh
MOSTLYCLEANFILES = \
lena-mask-channel.ppm \
lena-fill??????.ppm \
+ lena-wst??????.ppm \
lena-roi-fill??????.ppm
# FIXME: Also produce movies (see comments in recorder.cc and
diff --git a/milena/apps/morphers/recorder-wst.cc b/milena/apps/morphers/recorder-wst.cc
new file mode 100644
index 0000000..e4aade5
--- /dev/null
+++ b/milena/apps/morphers/recorder-wst.cc
@@ -0,0 +1,106 @@
+// Copyright (C) 2011 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.
+
+/// \file
+/// \brief Exercise a morpher recording every change in the morphed
+/// image with the watershed transform.
+///
+/// To produce an AVI movie from the `lena-wst*.ppm' files, use:
+///
+/// for f in lena-wst*ppm; convert $f -scale 2500% $(basename $f .ppm).png
+/// mencoder "mf://lena-wst*.png" -o lena-wst.avi -ovc lavc -lavcopts
vcodec=mjpeg
+///
+/// The output `lena-wst.avi' can be embedded in a PDF file. */
+
+#include <string>
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/label_8.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/literal/colors.hh>
+
+#include <mln/morpho/gradient.hh>
+#include <mln/morpho/closing/area.hh>
+#include <mln/morpho/watershed/flooding.hh>
+
+#include <mln/test/predicate.hh>
+#include <mln/pw/value.hh>
+
+#include <mln/labeling/colorize.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/ppm/save.hh>
+
+#include "apps/morphers/recorder.hh"
+
+#include "apps/data.hh"
+
+
+int main()
+{
+ using namespace mln;
+ using mln::value::int_u8;
+ using mln::value::label_8;
+
+ typedef image2d<int_u8> I;
+ I lena = io::pgm::load<int_u8>(MLN_IMG_DIR "/tiny.pgm");
+
+ // Gradient.
+ I grad = morpho::gradient(lena, win_c4p());
+ // Simplification of the gradient.
+ unsigned lambda = 5;
+ I closed_grad = morpho::closing::area(grad, c4(), lambda);
+ // Attach recorder to closed gradient.
+ decorated_image< I, recorder<I> > closed_grad_rec = record(closed_grad);
+
+ // Watershed transform.
+ typedef label_8 L;
+ L nbasins;
+ typedef mln_ch_value_(I, L) J;
+ decorated_image< J, recorder<J> > wst_rec =
+ morpho::watershed::flooding(closed_grad_rec, c4(), nbasins);
+ std::cout << nbasins << std::endl;
+
+ // Dump recorded frames.
+ /* FIXME: Hand-made (it partly duplicates ppm::save() for
+ decorated_image's). We should be able to process sequences of
+ images. */
+ for (size_t i = 0; i < wst_rec.decoration().sequence.size(); ++i)
+ {
+ J frame = wst_rec.decoration().sequence[i];
+
+ // Skip ``empty'' frames.
+ if (test::predicate(frame.domain(), pw::value(frame) == 0))
+ continue;
+
+ std::stringstream s;
+ s << std::setfill ('0') << std::setw (6) << i;
+ io::ppm::save(labeling::colorize(value::rgb8(), frame, nbasins),
+ std::string("lena-wst") + s.str() + ".ppm");
+ }
+}
--
1.7.2.5