Commit 1e58a782 authored by Roland Levillain's avatar Roland Levillain
Browse files

Add examples of morphers.

	* apps/morphers/mask+channel.cc,
	* apps/morphers/recorder.cc,
	* apps/morphers/mask+recorder.cc:
	New.
	* apps/morphers/Makefile.am: New.
	* apps/Makefile.am (SUBDIRS): Add morphers.
parent 8f46b1c9
2011-11-14 Roland Levillain <roland@lrde.epita.fr>
Add examples of morphers.
* apps/morphers/mask+channel.cc,
* apps/morphers/recorder.cc,
* apps/morphers/mask+recorder.cc:
New.
* apps/morphers/Makefile.am: New.
* apps/Makefile.am (SUBDIRS): Add morphers.
2011-10-04 Roland Levillain <roland@lrde.epita.fr>
 
Handle the case of filling an empty border.
# Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE).
# Copyright (C) 2008, 2009, 2011 EPITA Research and Development
# Laboratory (LRDE).
#
# This file is part of Olena.
#
......@@ -16,7 +17,7 @@
#
# Applied examples of Milena.
SUBDIRS = mesh-segm-skel graph-morpho constrained-connectivity
SUBDIRS = mesh-segm-skel graph-morpho constrained-connectivity morphers
# Examples from papers.
SUBDIRS += papers
# 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/>.
# Illustrations of morphers.
# Find Milena headers.
AM_CPPFLAGS = -I$(top_srcdir)/milena -I$(top_builddir)/milena
# Produce fast code.
APPS_CXXFLAGS = @APPS_CXXFLAGS@
AM_CXXFLAGS = $(APPS_CXXFLAGS)
noinst_PROGRAMS = \
mask+channel \
recorder \
mask+recorder
mask_channel_SOURCES = mask+channel.cc
recorder_SOURCES = recorder.cc
mask_recorder_SOURCES = mask+recorder.cc
MOSTLYCLEANFILES = \
lena-mask-channel.ppm \
lena-fill??????.ppm \
lena-roi-fill??????.ppm
# FIXME: Also produce movies (see comments in recorder.cc and
# mask+recorder.cc.)
// 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 Example projecting a RGB image to the green channel and
/// then applying a domain restricting with a mask.
#include <sstream>
#include <iomanip>
#include <string>
#include <mln/core/image/image2d.hh>
#include <mln/core/image/dmorph/image_if.hh>
#include <mln/fun/component/green.hh>
#include <mln/value/rgb8.hh>
/* FIXME: We wanted to use `fun_image' and `operator<<' from
<mln/core/image/vmorph/fun_image.hh, but they only create read-only
images. Use `thru_image' instead. */
#include <mln/core/image/vmorph/thru_image.hh>
#include <mln/core/routine/duplicate.hh>
#include <mln/literal/colors.hh>
#include <mln/data/fill.hh>
#include <mln/io/ppm/all.hh>
#include "apps/data.hh"
int main()
{
using namespace mln;
using mln::value::rgb8;
image2d<rgb8> lena = io::ppm::load<rgb8>(MLN_IMG_DIR "/tiny.ppm");
fun::green green;
/* FIXME: Cheat: use generic fill as mln::decorated_image does not
define properly its properties. */
data::impl::generic::fill_with_value((thru(green, lena).rw() |
box2d(point2d(5,5), point2d(10,10))).rw(),
255);
io::ppm::save(lena, "lena-mask-channel.ppm");
}
// 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 Morpher recording every change in the morphed image
/// followed by the application of a domain restriction with a mask.
///
/// To produce an AVI movie from the `lena-roi-fill*.ppm' files, use:
///
/// for f in lena-roi-fill*ppm; convert $f -scale 2500% $(basename $f .ppm).png
/// mencoder "mf://lena-roi-fill*.png" -o lena-roi-fill.avi -ovc lavc -lavcopts vcodec=mjpeg
///
/// The output `lena-roi-fill.avi' can be embedded in a PDF file. */
// FIXME: Factor with recorder.cc.
#include <sstream>
#include <iomanip>
#include <string>
#include <mln/core/image/image2d.hh>
#include <mln/core/image/dmorph/image_if.hh>
#include <mln/core/image/imorph/decorated_image.hh>
#include <mln/value/rgb8.hh>
#include <mln/core/routine/duplicate.hh>
#include <mln/literal/colors.hh>
#include <mln/data/fill.hh>
#include <mln/io/ppm/all.hh>
#include "apps/data.hh"
// FIXME: mln::decorated_image lacks a proper definition of
// properties! (see mln/core/image/imorph/decorated_image.hh
namespace mln
{
namespace trait
{
template <typename I, typename D>
struct image_< decorated_image<I,D> >
: default_image_morpher< I,
mln_value(I),
decorated_image<I,D> >
{
typedef trait::image::category::identity_morpher category;
};
} // end of namespace mln::trait
} // end of namespace mln
// Recorder.
template <typename I>
struct recorder
{
void reading(const I&, const mln_psite(I)&) const
{
// N/A.
}
void writing(I& ima, const mln_psite(I)&, const mln_value(I)&)
{
sequence.push_back(mln::duplicate(ima));
}
std::vector<I> sequence;
};
template <typename I>
mln::decorated_image< I, recorder<I> >
record(mln::Image<I>& ima)
{
return mln::decorate(ima, recorder<I>());
}
// I/O.
namespace ppm
{
template <typename I>
void
save(const mln::decorated_image< I, recorder<I> >& rec,
const std::string& prefix)
{
for (size_t i = 0; i < rec.decoration().sequence.size(); ++i)
{
std::stringstream s;
s << std::setfill ('0') << std::setw (6) << i;
mln::io::ppm::save(rec.decoration().sequence[i],
prefix + s.str() + ".ppm");
}
}
}
int main()
{
using namespace mln;
using mln::value::rgb8;
typedef image2d<rgb8> I;
I lena = io::ppm::load<rgb8>(MLN_IMG_DIR "/tiny.ppm");
decorated_image< I, recorder<I> > lena_rec = record(lena);
/* FIXME: Cheat: use generic fill as mln::decorated_image does not
define properly its properties. */
data::impl::generic::fill_with_value((lena_rec | box2d(point2d(5,5),
point2d(10,10))).rw(),
literal::green);
ppm::save(lena_rec, "lena-roi-fill");
}
// 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 Morpher recording every change in the morphed image.
///
/// To produce an AVI movie from the `lena-fill*.ppm' files, use:
///
/// for f in lena-fill*ppm; convert $f -scale 2500% $(basename $f .ppm).png
/// mencoder "mf://lena-fill*.png" -o lena-fill.avi -ovc lavc -lavcopts vcodec=mjpeg
///
/// The output `lena-fill.avi' can be embedded in a PDF file. */
#include <sstream>
#include <iomanip>
#include <string>
#include <mln/core/image/image2d.hh>
#include <mln/core/image/imorph/decorated_image.hh>
#include <mln/value/rgb8.hh>
#include <mln/core/routine/duplicate.hh>
#include <mln/literal/colors.hh>
#include <mln/data/fill.hh>
#include <mln/io/ppm/all.hh>
#include "apps/data.hh"
// FIXME: mln::decorated_image lacks a proper definition of
// properties! (see mln/core/image/imorph/decorated_image.hh
namespace mln
{
namespace trait
{
template <typename I, typename D>
struct image_< decorated_image<I,D> >
: default_image_morpher< I,
mln_value(I),
decorated_image<I,D> >
{
typedef trait::image::category::identity_morpher category;
};
} // end of namespace mln::trait
} // end of namespace mln
// Recorder.
template <typename I>
struct recorder
{
void reading(const I&, const mln_psite(I)&) const
{
// N/A.
}
void writing(I& ima, const mln_psite(I)&, const mln_value(I)&)
{
sequence.push_back(mln::duplicate(ima));
}
std::vector<I> sequence;
};
template <typename I>
mln::decorated_image< I, recorder<I> >
record(mln::Image<I>& ima)
{
return mln::decorate(ima, recorder<I>());
}
// I/O.
namespace ppm
{
template <typename I>
void
save(const mln::decorated_image< I, recorder<I> >& rec,
const std::string& prefix)
{
for (size_t i = 0; i < rec.decoration().sequence.size(); ++i)
{
std::stringstream s;
s << std::setfill ('0') << std::setw (6) << i;
mln::io::ppm::save(rec.decoration().sequence[i],
prefix + s.str() + ".ppm");
}
}
}
int main()
{
using namespace mln;
using mln::value::rgb8;
typedef image2d<rgb8> I;
I lena = io::ppm::load<rgb8>(MLN_IMG_DIR "/tiny.ppm");
decorated_image< I, recorder<I> > lena_rec = record(lena);
/* FIXME: Cheat: use generic fill as mln::decorated_image does not
define properly its properties. */
data::impl::generic::fill_with_value(lena_rec,
literal::green);
ppm::save(lena_rec, "lena-fill");
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment