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
00064 #include <cstdio>
00065
00066 #include <set>
00067 #include <iostream>
00068
00069 #include <mln/value/int_u8.hh>
00070 #include <mln/core/image/image2d.hh>
00071
00072 #include <mln/pw/all.hh>
00073
00074 #include <mln/fun/vv2v/diff_abs.hh>
00075 #include <mln/world/inter_pixel/immerse.hh>
00076 #include <mln/world/inter_pixel/compute.hh>
00077 #include <mln/world/inter_pixel/neighb2d.hh>
00078
00079 #include <mln/morpho/watershed/topological.hh>
00080
00081 #include <mln/morpho/tree/compute_attribute_image.hh>
00082 #include <mln/accu/stat/min.hh>
00083 #include <mln/accu/stat/max.hh>
00084
00085 #include <mln/io/pgm/load.hh>
00086 #include <mln/debug/println.hh>
00087
00088 #include <mln/core/var.hh>
00089
00090
00091 int main(int argc, char* argv[])
00092 {
00093 if (argc != 2)
00094 {
00095 std::cerr << "Usage: " << argv[0] << " input.pgm" << std::endl;
00096 std::exit(1);
00097 }
00098
00099 using namespace mln;
00100 using mln::value::int_u8;
00101
00102
00103 image2d<int_u8> input;
00104 io::pgm::load(input, argv[1]);
00105
00106
00107 image2d<int_u8> f_(input.nrows() * 2, input.ncols() * 2);
00108 mln_piter_(image2d<int_u8>) p_ima(f_.domain());
00109 for_all(p_ima)
00110 {
00111
00112
00113
00114
00115 point2d p_ima_ = p_ima;
00116 point2d p_f(p_ima_.row() / 2, p_ima_.col() / 2);
00117 f_(p_ima) = input(p_f);
00118 }
00119 debug::println("f_:", f_);
00120
00121 image_if<image2d<int_u8>, world::inter_pixel::is_pixel> f =
00122 world::inter_pixel::immerse(f_);
00123 debug::println("f:", f);
00124
00125
00126 mln_VAR(g, world::inter_pixel::compute (f, fun::vv2v::diff_abs<int_u8>()));
00127
00128 debug::println("g:", g);
00129
00130
00131 typedef morpho::watershed::topo_wst<g_t, world::inter_pixel::dbl_neighb2d> tree_t;
00132 tree_t tree(g, world::inter_pixel::e2e());
00133 tree.go();
00134 mln_VAR(w, morpho::watershed::topological(tree));
00135 debug::println("w:", w);
00136
00137
00138
00139 std::set<int_u8> values;
00140 mln_piter_(w_t) p2(w.domain());
00141 for_all(p2)
00142 values.insert(w(p2));
00143
00144
00145 for (std::set<int_u8>::const_iterator alpha = values.begin();
00146 alpha != values.end(); ++alpha)
00147 {
00148 mln_VAR(alpha_cc, w | (pw::value(w) > pw::cst(*alpha)));
00149 std::cout << *alpha << "-cc:" << std::endl;
00150
00151
00152
00153
00154 debug::impl::println(w.unmorph_().domain(), alpha_cc);
00155 }
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 typedef p_array<tree_t::site> sites_t;
00168 sites_t sites = data::sort_psites_decreasing(w);
00169 morpho::tree::data<w_t, sites_t> t(w, sites, world::inter_pixel::e2e());
00170
00171
00172 mln_ch_value_(w_t, accu::stat::min<int_u8>) init_min_val;
00173 initialize (init_min_val, w);
00174 mln_ch_value_(w_t, accu::stat::max<int_u8>) init_max_val;
00175 initialize (init_max_val, w);
00176
00177
00178
00179
00180
00181
00182
00183
00184 mln_piter_(w_t) e(w.domain());
00185 mln_niter_(world::inter_pixel::dbl_neighb2d)
00186 v_g(world::inter_pixel::e2v(), e);
00187 for_all(e)
00188 for_all(v_g)
00189 {
00190
00191 point2d v_g_ = v_g;
00192 point2d v_f(v_g_.row() / 2, v_g_.col() / 2);
00193 init_min_val(e).take(f_(v_f));
00194 init_max_val(e).take(f_(v_f));
00195 }
00196
00197 accu::stat::min<int_u8> min_accu;
00198 mln_ch_value_(w_t, int_u8) min_val =
00199 morpho::tree::compute_attribute_image_from(min_accu, t, init_min_val);
00200 accu::stat::max<int_u8> max_accu;
00201 mln_ch_value_(w_t, int_u8) max_val =
00202 morpho::tree::compute_attribute_image_from(max_accu, t, init_max_val);
00203
00204 mln_ch_value_(w_t, int_u8) height;
00205 initialize(height, w);
00206 for_all(e)
00207 height(e) = max_val(e) - min_val(e);
00208 debug::println(height);
00209
00210
00211 for (unsigned alpha = 0; alpha <= 6; ++alpha)
00212 {
00213 mln_VAR(alpha_alpha_cc,
00214 w | (pw::value(w) > pw::cst(alpha)
00215 || (pw::value(height) > pw::cst(alpha))));
00216 std::cout << "(" << alpha << ", " << alpha << ")-cc:" << std::endl;
00217
00218 debug::impl::println(w.unmorph_().domain(), alpha_alpha_cc);
00219 }
00220 }