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/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 },
00040 { 2,2, 2,2 },
00041 { 0,0, 0,0 },
00042 { 0,0, 0,0 },
00043 { 2,0, 2,1 },
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 }
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 }