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 <mln/core/image/image2d.hh>
00027 #include <mln/core/alias/neighb2d.hh>
00028 #include <mln/labeling/blobs.hh>
00029 #include <mln/labeling/compute.hh>
00030 #include <mln/accu/math/count.hh>
00031 #include <mln/accu/math/sum.hh>
00032 #include <mln/value/int_u8.hh>
00033 #include <mln/value/label_8.hh>
00034 #include <mln/util/array.hh>
00035 
00036 int main()
00037 {
00038   using namespace mln;
00039   using value::label_8;
00040   using value::int_u8;
00041 
00042   int_u8 vals[6][5] = {
00043     {0, 1, 1, 0, 0},
00044     {0, 1, 1, 0, 0},
00045     {0, 0, 0, 0, 0},
00046     {2, 2, 0, 3, 0},
00047     {2, 0, 3, 3, 3},
00048     {2, 0, 0, 0, 0}
00049   };
00050   image2d<int_u8> ima = make::image(vals);
00051 
00052   label_8 lblvals[6][5] = {
00053     {0, 1, 1, 0, 0},
00054     {0, 1, 1, 0, 0},
00055     {0, 0, 0, 0, 0},
00056     {2, 2, 0, 3, 0},
00057     {2, 0, 3, 3, 3},
00058     {2, 0, 0, 0, 0}
00059   };
00060   image2d<label_8> lbl = make::image(lblvals);
00061   label_8 nlabels = 3;
00062 
00063   accu::math::sum<int_u8> sum;
00064   util::array<float> sums = labeling::compute(sum, ima, lbl, nlabels);
00065   mln_assertion(sums[0] == 0);
00066   mln_assertion(sums[1] == 4);
00067   mln_assertion(sums[2] == 8);
00068   mln_assertion(sums[3] == 12);
00069 
00070   sums = labeling::compute(accu::meta::math::sum(), ima, lbl, nlabels);
00071   mln_assertion(sums[0] == 0);
00072   mln_assertion(sums[1] == 4);
00073   mln_assertion(sums[2] == 8);
00074   mln_assertion(sums[3] == 12);
00075 
00076   accu::math::count<mln_site_(image2d<int_u8>)> count;
00077   util::array<unsigned int> counts = labeling::compute(count, lbl, nlabels);
00078   mln_assertion(counts[0] == 18);
00079   mln_assertion(counts[1] == 4);
00080   mln_assertion(counts[2] == 4);
00081   mln_assertion(counts[3] == 4);
00082 
00083   counts = labeling::compute(accu::meta::math::count(), lbl, nlabels);
00084   mln_assertion(counts[0] == 18);
00085   mln_assertion(counts[1] == 4);
00086   mln_assertion(counts[2] == 4);
00087   mln_assertion(counts[3] == 4);
00088 }