26 #ifndef SCRIBO_ESTIM_FONT_BOLDNESS_HH
27 # define SCRIBO_ESTIM_FONT_BOLDNESS_HH
33 # include <mln/core/image/image2d.hh>
34 # include <mln/core/alias/neighb2d.hh>
36 # include <mln/labeling/blobs.hh>
37 # include <mln/accu/stat/mean.hh>
38 # include <mln/value/next.hh>
40 # include <scribo/core/macros.hh>
41 # include <scribo/core/def/lbl_type.hh>
42 # include <scribo/estim/internal/compute_skeleton.hh>
57 font_boldness(
const Image<I>& text_ima);
60 # ifndef MLN_INCLUDE_ONLY
66 template <
typename I,
typename J>
68 boldness_from_lbl(
const Image<I>& ima_lbl_,
71 mln_trace(
"scribo::estim::internal::boldness_from_lbl");
73 const I& ima_lbl =
exact(ima_lbl_);
74 const J& skel =
exact(skel_);
75 mln_precondition(ima_lbl.is_valid());
76 mln_precondition(skel.is_valid());
78 mln_piter(I) p(ima_lbl.domain());
79 int skel_p = 0, ima_p = 0;
90 float res = ima_p / (
float) skel_p;
99 template <
typename I,
typename J>
101 boldness_from_lbl(
const Image<I>& ima_lbl_,
102 const mln_value(I)& nlabels,
105 mln_trace(
"scribo::estim::internal::boldness_from_lbl");
107 const I& ima_lbl =
exact(ima_lbl_);
108 const J& skel_lbl =
exact(skel_lbl_);
109 mln_precondition(ima_lbl.is_valid());
110 mln_precondition(skel_lbl.is_valid());
112 mln_piter(I) p(ima_lbl.domain());
113 std::vector<
int> skel_p(
value::next(nlabels), 0);
114 std::vector<
int> ima_p(
value::next(nlabels), 0);
118 int val = skel_lbl(p);
130 for_all_ncomponents(i, nlabels)
131 mean.take(ima_p[i] / skel_p[i]);
139 return mean.to_result();
153 template <
typename I>
157 mln_trace(
"scribo::estim::impl::generic::font_boldness");
159 const I& ima =
exact(ima_);
160 mln_precondition(ima.is_valid());
161 mlc_is(mln_value(I),
bool)::check();
166 mln_concrete(I) skel = internal::compute_skeleton(ima);
175 output = internal::boldness_from_lbl(lbl, nlabels, slbl);
188 template <typename I>
190 font_boldness(const
Image<I>& ima)
192 mln_trace(
"scribo::estim::font_boldness");
194 mln_precondition(
exact(ima).is_valid());
195 mlc_is(mln_value(I),
bool)::check();
197 float output = impl::generic::font_boldness(ima);
202 # endif // ! MLN_INCLUDE_ONLY
208 # endif // ! SCRIBO_ESTIM_FONT_BOLDNESS_HH