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/labeling/relabel.hh>
00028 #include <mln/value/label_16.hh>
00029 #include <mln/debug/println.hh>
00030
00031
00032 struct not_to_remove : public mln::Function_v2b< not_to_remove >
00033 {
00034 bool operator()(const mln::value::label_16& l) const
00035 {
00036 return l < mln::value::label_16(3);
00037 }
00038 };
00039
00040
00041 bool is_valid(const mln::value::label_16& l)
00042 {
00043 return l == 0u|| l == 1u || l == 2u;
00044 }
00045
00046
00047
00048 int main()
00049 {
00050 using namespace mln;
00051 using value::label_16;
00052
00053 label_16 vals[6][5] = {
00054 {0, 1, 1, 0, 0},
00055 {0, 1, 1, 4, 0},
00056 {0, 0, 0, 0, 0},
00057 {2, 2, 0, 3, 0},
00058 {2, 5, 3, 3, 3},
00059 {2, 5, 5, 0, 0}
00060 };
00061
00062 image2d<label_16> lbl = make::image(vals);
00063 label_16 nlabels = 5;
00064
00065
00066 {
00067 label_16 new_nlabels;
00068 image2d<label_16> lbl2 = labeling::relabel(lbl,
00069 nlabels,
00070 new_nlabels,
00071 not_to_remove());
00072 mln_assertion(new_nlabels == 2u);
00073 mln_piter_(image2d<label_16>) p(lbl2.domain());
00074 for_all(p)
00075 mln_assertion(is_valid(lbl2(p)));
00076 }
00077
00078 {
00079 label_16 new_nlabels;
00080 labeling::relabel_inplace(lbl,
00081 nlabels,
00082 not_to_remove());
00083 mln_assertion(nlabels == 2u);
00084 mln_piter_(image2d<label_16>) p(lbl.domain());
00085 for_all(p)
00086 mln_assertion(is_valid(lbl(p)));
00087 }
00088 }