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 #ifndef MLN_LABELING_SUPERPOSE_HH
00027 # define MLN_LABELING_SUPERPOSE_HH
00028
00032
00033
00034 # include <mln/core/concept/image.hh>
00035 # include <mln/util/array.hh>
00036 # include <mln/labeling/relabel.hh>
00037 # include <mln/data/paste.hh>
00038 # include <mln/pw/all.hh>
00039
00040 namespace mln
00041 {
00042
00043 namespace labeling
00044 {
00045
00046
00066 template <typename I, typename J>
00067 mln_concrete(I)
00068 superpose(const Image<I>& lhs, const mln_value(I)& lhs_nlabels,
00069 const Image<J>& rhs, const mln_value(J)& rhs_nlabels,
00070 mln_value(I)& new_nlabels);
00071
00072
00073
00074
00075 # ifndef MLN_INCLUDE_ONLY
00076
00077 template <typename I, typename J>
00078 mln_concrete(I)
00079 superpose(const Image<I>& lhs_, const mln_value(I)& lhs_nlabels,
00080 const Image<J>& rhs_, const mln_value(J)& rhs_nlabels,
00081 mln_value(I)& new_nlabels)
00082 {
00083 trace::entering("mln::labeling::superpose");
00084
00085 const I& lhs = exact(lhs_);
00086 const J& rhs = exact(rhs_);
00087
00088 mlc_converts_to(mln_value(I), mln_value(J))::check();
00089 mln_precondition(lhs.is_valid());
00090 mln_precondition(rhs.is_valid());
00091 mln_precondition(lhs.domain() == rhs.domain());
00093
00094 mln_concrete(I) output = duplicate(lhs);
00095
00096 util::array<mln_value(J)>
00097 rebase_lbl(static_cast<unsigned>(rhs_nlabels) + 1);
00098
00099 rebase_lbl(0) = 0;
00100 for (unsigned i = 1; i <= rhs_nlabels; ++i)
00101 rebase_lbl(i) = i + static_cast<unsigned>(lhs_nlabels);
00102
00103 data::paste(labeling::relabel(rhs, rhs_nlabels, rebase_lbl)
00104 | (pw::value(rhs) != pw::cst(literal::zero)),
00105 output);
00106
00107 new_nlabels = static_cast<unsigned>(lhs_nlabels)
00108 + static_cast<unsigned>(rhs_nlabels) + 1;
00109
00110 trace::exiting("mln::labeling::superpose");
00111 return output;
00112 }
00113
00114
00115 # endif // ! MLN_INCLUDE_ONLY
00116
00117 }
00118
00119 }
00120
00121
00122 #endif // ! MLN_LABELING_SUPERPOSE_HH