Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 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 }