Commit 3864857f authored by Thierry Geraud's avatar Thierry Geraud Committed by Roland Levillain
Browse files

New example demonstrating the use of influence zones.



	* apps/morphers/iz.cc: New.
	* apps/morphers/iz_input.pbm: New.
Signed-off-by: Roland Levillain's avatarRoland Levillain <roland@lrde.epita.fr>
parent f8e2ffe5
2012-06-20 Thierry Geraud <thierry.geraud@lrde.epita.fr>
New example demonstrating the use of influence zones.
* apps/morphers/iz.cc: New.
* apps/morphers/iz_input.pbm: New.
2012-06-21 Roland Levillain <roland@lrde.epita.fr>
 
New ``lazy'' recorder morpher in apps/morpher.
#include <mln/core/image/image2d.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/data/fill.hh>
#include <mln/data/paste.hh>
#include <mln/data/convert.hh>
#include <mln/data/saturate.hh>
#include <mln/labeling/value.hh>
#include <mln/labeling/colorize.hh>
#include <mln/morpho/watershed/superpose.hh>
#include <mln/morpho/watershed/flooding.hh>
#include <mln/morpho/elementary/dilation.hh>
#include <mln/morpho/closing/area.hh>
#include <mln/morpho/closing/structural.hh>
#include <mln/transform/distance_front.hh>
#include <mln/transform/influence_zone_front.hh>
#include <mln/pw/all.hh>
#include <mln/core/image/dmorph/image_if.hh>
#include <mln/core/image/dmorph/sub_image.hh>
#include <mln/make/w_window2d.hh>
#include <mln/io/pbm/load.hh>
#include <mln/io/pbm/save.hh>
#include <mln/io/pgm/save.hh>
#include <mln/io/ppm/save.hh>
#include <mln/literal/colors.hh>
void usage(char* argv[])
{
std::cerr << "usage: " << argv[0] << " input.pbm output.ppm" << std::endl;
std::abort();
}
int main(int argc, char* argv[])
{
using namespace mln;
using value::int_u8;
if (argc != 3)
usage(argv);
image2d<bool> input, clo;
io::pbm::load(input, argv[1]);
/// Structural closing.
clo = morpho::closing::structural(input,
win::rectangle2d(5, 17));
io::pbm::save(clo, "tmp_clo.pgm");
/// Distance map computation.
int ww[] = { 00, 11, 0, 11, 0,
11, 7, 5, 7, 11,
00, 5, 0, 5, 0,
11, 7, 5, 7, 11,
00, 11, 0, 11, 0 };
image2d<int_u8> dmap;
dmap = transform::distance_front(clo,
c4(), make::w_window2d(ww),
mln_max(int_u8));
dmap = morpho::closing::area(dmap, c4(), 500);
io::pgm::save(dmap, "tmp_dmap.pgm");
unsigned nbasins;
image2d<unsigned> ws = morpho::watershed::flooding(dmap,
c4(),
nbasins);
io::ppm::save(labeling::colorize(value::rgb8(), ws), "tmp_ws.ppm");
{
image2d<value::rgb8> ws_ = data::convert(value::rgb8(), input);
data::fill((ws_ | (pw::value(ws) == pw::cst(0))).rw(), literal::red);
io::ppm::save(ws_, "tmp_ws_superpose.ppm");
// test% g++ -I. main.cc -DNDEBUG -O2
// main.cc: In function ‘int main(int, char**)’:
// main.cc:85: error: no matching function for call to ‘convert(mln::image2d<bool>&, mln::value::rgb8)’
// /// Convert the image \p input by changing the value type.
// ///
// /// \param[in] v A value of the destination type.
// /// \param[in] input The input image.
// //
// template <typename V, typename I>
// mln_ch_value(I, V)
// convert(const V& v, const Image<I>& input);
}
image2d<unsigned> lab(input.domain());
data::fill(lab, 0);
unsigned nlabels;
data::paste(labeling::value(ws | make::box2d(0,0,input.nrows()-1,0),
0, c4(), nlabels),
lab);
io::pgm::save(data::saturate(value::int_u8(), lab), "tmp_lab.pgm");
data::paste(transform::influence_zone_front(lab | (pw::value(ws) == pw::cst(0)),
c8(),
make::w_window2d(ww)),
lab);
io::pgm::save(data::saturate(value::int_u8(), lab), "tmp_iz.pgm");
image2d<value::rgb8> output = labeling::colorize(value::rgb8(), lab);
io::ppm::save(output, "tmp_iz.ppm");
data::fill((output | pw::value(input)).rw(), literal::white);
io::ppm::save(output, "tmp_iz_input.ppm");
}
Supports Markdown
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