26 #include <mln/core/image/image2d.hh>
27 #include <mln/core/alias/neighb2d.hh>
28 #include <mln/core/var.hh>
30 #include <mln/value/int_u8.hh>
31 #include <mln/value/label_16.hh>
32 #include <mln/value/rgb8.hh>
34 #include <mln/io/pgm/all.hh>
35 #include <mln/io/ppm/save.hh>
37 #include <mln/data/convert.hh>
38 #include <mln/data/fill.hh>
39 #include <mln/debug/int2rgb.hh>
40 #include <mln/display/display_region.hh>
41 #include <mln/literal/colors.hh>
42 #include <mln/math/diff_abs.hh>
43 #include <mln/morpho/closing/volume.hh>
44 #include <mln/morpho/elementary/gradient.hh>
45 #include <mln/morpho/watershed/flooding.hh>
46 #include <mln/world/inter_pixel/compute.hh>
47 #include <mln/world/inter_pixel/display_edge.hh>
48 #include <mln/world/inter_pixel/display_region.hh>
49 #include <mln/world/inter_pixel/immerse.hh>
50 #include <mln/world/inter_pixel/is_pixel.hh>
51 #include <mln/world/inter_pixel/is_separator.hh>
52 #include <mln/world/inter_pixel/neighb2d.hh>
66 int_u8 operator()(
const V v1,
const V v2)
const
74 int main(
int argc,
char* argv[])
78 std::cout <<
"Usage: " << argv[0] <<
" input.pgm" << std::endl;
109 convert::from_to(input(
p), opt::at(edge_color, p.row() * 2, p.col() * 2));
110 data::
fill((edge_color | world::inter_pixel::is_separator()).rw(), literal::green);
111 data::
fill((edge_color | world::inter_pixel::is_zero_face()).rw(), literal::blue);
112 io::ppm::
save(edge_color, "edge_color.ppm");
116 image2d<
rgb8> edge_stretch(make::
box2d(((b.pmin()[0] + 1) / 2) * 4, ((b.pmin()[1] + 1) / 2) * 4,
117 ((b.pmax()[0] + 1) / 2 + 1) * 4 - 2, ((b.pmax()[1] + 1) / 2 + 1) * 4 - 2));
119 edge_t edge_sep = edge_color | world::inter_pixel::is_separator();
120 mln_piter_(edge_t) q(edge_sep.domain());
124 unsigned row = (q.row() / 2 + 1) * 4 - 1;
125 unsigned col = (q.col() / 2) * 4;
126 for (
unsigned i = 0; i < 3; ++i)
131 unsigned row = (q.row() / 2) * 4;
132 unsigned col = (q.col() / 2 + 1) * 4 - 1;
133 for (
unsigned i = 0; i < 3; ++i)
136 mln_VAR(edge_zero, edge_color | world::inter_pixel::is_zero_face());
137 mln_piter_(edge_zero_t) ez(edge_zero.domain());
139 opt::at(edge_stretch, ((ez.row() + 1) / 2) * 4 - 1, ((ez.col() + 1) / 2) * 4 - 1) = literal::blue;
140 mln_VAR(edge_pix, edge_color | world::inter_pixel::is_pixel());
141 mln_piter_(edge_pix_t) ex(edge_pix.domain());
143 for (
int i = 0; i < 3; ++i)
144 for (
int j = 0; j < 3; ++j)
145 opt::at(edge_stretch, (ex.row() / 2) * 4 + i, (ex.col() / 2) * 4 + j) = edge_color(ex);
146 io::ppm::
save(edge_stretch, "edge_stretch.ppm");
150 mln_VAR(edge_clo, morpho::closing::
volume(edges, world::inter_pixel::e2e(), 25));
151 mln_VAR(edge_wst, morpho::watershed::
flooding(edge_clo, world::inter_pixel::e2e(), nbasins));
152 io::ppm::
save(world::inter_pixel::display_region(input, edge_wst.unmorph_(), literal::red), "edge_watershed.ppm");