Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 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/image/imorph/labeled_image.hh> 00028 #include <mln/core/routine/duplicate.hh> 00029 #include <mln/make/image.hh> 00030 #include <mln/make/box2d.hh> 00031 #include <mln/value/label_8.hh> 00032 #include <mln/accu/pair.hh> 00033 #include <mln/accu/center.hh> 00034 #include <mln/accu/shape/bbox.hh> 00035 00036 00037 # include <mln/debug/println.hh> 00038 00039 static const unsigned bboxes_1[][9] = { { 1,1, 1,1 }, // 1 00040 { 2,2, 2,2 }, // 2 00041 { 0,0, 0,0 }, 00042 { 0,0, 0,0 }, 00043 { 2,0, 2,1 }, // 5 00044 { 0,0, 0,0 }, 00045 { 0,0, 0,0 }, 00046 { 0,0, 0,0 }, 00047 { 0,0, 0,1 } }; 00048 00049 00050 static const unsigned bboxes_2[][4] = { { 1,1, 1,1 }, 00051 { 2,2, 2,2 }, 00052 { 2,0, 2,1 }, 00053 { 0,0, 0,1 } }; 00054 00055 00056 00057 namespace mln 00058 { 00059 00060 template <typename I, unsigned n> 00061 void test_image(const labeled_image<I>& lbl_i, 00062 const unsigned bboxes[][n]) 00063 { 00064 unsigned 00065 j = 0, 00066 k = 0; 00067 for (unsigned i = 1; i <= lbl_i.nlabels(); ++i, ++j) 00068 if (lbl_i.bbox(i).is_valid()) 00069 { 00070 mln_assertion(lbl_i.bbox(i) == make::box2d(bboxes[j][0], bboxes[j][1], 00071 bboxes[j][2], bboxes[j][3])); 00072 ++k; 00073 } 00074 00075 mln_assertion(k == 4); 00076 } 00077 00078 } // end of namespace mln 00079 00080 00081 00082 00083 int main() 00084 { 00085 using namespace mln; 00086 using value::label_8; 00087 00088 00089 label_8 lbl_values[][3] = { { 9, 9, 0 }, 00090 { 0, 1, 0 }, 00091 { 5, 5, 2 } }; 00092 00093 typedef image2d<label_8> lbl_t; 00094 lbl_t lbl = make::image(lbl_values); 00095 00096 labeled_image<lbl_t> lbl_i(lbl, 9); 00097 mln_assertion(lbl_i.nlabels() == 9); 00098 test_image(lbl_i, bboxes_1); 00099 00100 fun::i2v::array<label_8> f(10, 0); 00101 f(0) = 0; 00102 f(1) = 1; 00103 f(5) = 2; 00104 f(9) = 5; 00105 f(2) = 4; 00106 00107 lbl_i.relabel(f); 00108 00109 mln_assertion(lbl_i.nlabels() == 4); 00110 test_image(lbl_i, bboxes_2); 00111 }