00001
00002
00003
00004
00005 #include <mln/core/image/image2d.hh>
00006 #include <mln/core/image/dmorph/image_if.hh>
00007 #include <mln/core/alias/neighb2d.hh>
00008
00009 #include <mln/data/fill.hh>
00010
00011 #include <mln/labeling/blobs.hh>
00012 #include <mln/labeling/compute.hh>
00013 #include <mln/labeling/blobs.hh>
00014
00015 #include <mln/data/compare.hh>
00016
00017 #include <mln/util/array.hh>
00018
00019 #include <mln/value/label_8.hh>
00020
00021 #include <mln/accu/math/count.hh>
00022
00023 #include <mln/pw/all.hh>
00024
00025 #include <tests/data.hh>
00026 #include <doc/tools/sample_utils.hh>
00027
00028 namespace mln
00029 {
00030
00031 template <typename I, typename N>
00032 mln_concrete(I)
00033 my_algorithm(const Image<I>& ima_,
00034 const Neighborhood<N>& nbh_)
00035 {
00036 trace::entering("my_algorithm");
00037
00038 const I& ima = exact(ima_);
00039 const N& nbh = exact(nbh_);
00040 mln_precondition(ima.is_valid());
00041 mln_precondition(nbh.is_valid());
00042
00043 typedef value::label_8 V;
00044 V nlabels;
00045 mln_ch_value(I,V) lbl = labeling::blobs(ima, nbh, nlabels);
00046 util::array<unsigned>
00047 count = labeling::compute(accu::meta::math::count(),
00048 lbl,
00049 nlabels);
00050
00051 mln_concrete(I) output;
00052 initialize(output, ima);
00053 data::fill(output, literal::one);
00054
00055 for (unsigned i = 1; i <= nlabels; ++i)
00056 if (count[i] < 10u)
00057 data::fill((output | (pw::value(lbl) == pw::cst(i))).rw(),
00058 literal::zero);
00059
00060 trace::exiting("my_algorithm");
00061 return output;
00062 }
00063
00064 }
00065
00066
00067 namespace sandbox
00068 {
00069
00070 using namespace mln;
00071
00072
00073 template <typename I, typename N>
00074 mln_concrete(I)
00075 my_algorithm(const Image<I>& ima_,
00076 const Neighborhood<N>& nbh_)
00077
00078 {
00079
00080 trace::entering("my_algorithm");
00081
00082
00083
00084 const I& ima = exact(ima_);
00085 const N& nbh = exact(nbh_);
00086 mln_precondition(ima.is_valid());
00087 mln_precondition(nbh.is_valid());
00088
00089
00090
00091 typedef value::label_8 V;
00092 V nlabels;
00093 mln_ch_value(I,V) lbl = labeling::blobs(ima, nbh, nlabels);
00094 util::array<unsigned>
00095 count = labeling::compute(accu::meta::math::count(),
00096 lbl,
00097 nlabels);
00098
00099
00100
00101 mln_concrete(I) output;
00102 initialize(output, ima);
00103 data::fill(output, literal::one);
00104
00105
00106
00107 for (unsigned i = 1; i <= nlabels; ++i)
00108 if (count[i] < 10u)
00109 data::fill((output | (pw::value(lbl) == pw::cst(i))).rw(),
00110 literal::zero);
00111
00112
00113
00114 trace::exiting("my_algorithm");
00115 return output;
00116
00117 }
00118
00119 }
00120
00121 int main()
00122 {
00123 mln::image2d<bool> test(2,2);
00124 mln_assertion(sandbox::my_algorithm(test, mln::c4())
00125 == mln::my_algorithm(test, mln::c4()));
00126 }