00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <iostream>
00027
00028 #include <mln/core/image/image2d.hh>
00029 #include <mln/core/alias/window2d.hh>
00030 #include <mln/core/alias/neighb2d.hh>
00031
00032 #include <mln/value/int_u8.hh>
00033 #include <mln/value/int_u16.hh>
00034
00035 #include <mln/morpho/watershed/flooding.hh>
00036 #include <mln/data/transform.hh>
00037
00038 #include <mln/io/pgm/load.hh>
00039 #include <mln/io/pgm/save.hh>
00040
00041 #include <mln/util/timer.hh>
00042
00043 #include "tests/data.hh"
00044
00045 struct f_16_to_8 : mln::Function_v2v< f_16_to_8 >
00046 {
00047 typedef mln::value::int_u8 result;
00048 result operator()(const mln::value::int_u16& v) const
00049 {
00050 if (v == 0)
00051 return 0;
00052 return 1 + (v - 1) % 255;
00053 }
00054 };
00055
00056
00057 int main()
00058 {
00059 using namespace mln;
00060 using value::int_u8;
00061 using value::int_u16;
00062
00063 image2d<int_u8> input;
00064 io::pgm::load(input, MLN_IMG_DIR "/squares.pgm");
00065
00066 typedef int_u16 L;
00067 L n_basins;
00068 {
00069 util::timer t;
00070 t.start();
00071 image2d<L> output = morpho::watershed::impl::generic::flooding(input, c4(), n_basins);
00072 std::cout << "gen: " << t << std::endl;
00073 io::pgm::save(data::transform(output, f_16_to_8()),
00074 "tmp_ref.pgm");
00075 }
00076 {
00077 util::timer t;
00078 t.start();
00079 image2d<L> output = morpho::watershed::impl::flooding_fastest(input, c4(), n_basins);
00080 std::cout << "fast: " << t << std::endl;
00081 io::pgm::save(data::transform(output, f_16_to_8()),
00082 "tmp_out.pgm");
00083 }
00084 }