33 #ifndef SCRIBO_PRIMITIVE_EXTRACT_NON_TEXT_KMEAN_HH
34 # define SCRIBO_PRIMITIVE_EXTRACT_NON_TEXT_KMEAN_HH
36 # include <mln/core/image/image2d.hh>
37 # include <mln/core/alias/neighb2d.hh>
38 # include <mln/data/fill.hh>
39 # include <mln/util/array.hh>
40 # include <mln/labeling/compute.hh>
41 # include <mln/labeling/relabel.hh>
42 # include <mln/accu/math/count.hh>
43 # include <mln/pw/all.hh>
45 # include <mln/draw/box_plain.hh>
47 # include <mln/value/label_8.hh>
48 # include <mln/value/rgb.hh>
49 # include <mln/value/rgb8.hh>
51 # include <scribo/core/macros.hh>
52 # include <scribo/core/component_set.hh>
53 # include <scribo/core/document.hh>
54 # include <scribo/core/line_set.hh>
55 # include <scribo/core/def/lbl_type.hh>
56 # include <scribo/filter/objects_small.hh>
58 # include <mln/clustering/kmean_rgb.hh>
59 # include <mln/fun/v2v/rgb8_to_rgbn.hh>
73 template <
typename L,
typename I>
75 non_text_kmean(
const document<L>& doc,
const Image<I>& input);
78 # ifndef MLN_INCLUDE_ONLY
92 bool operator()(
const unsigned& c1,
const unsigned&
c2)
const
96 return comps_(c1).bbox().nsites() > comps_(c2).bbox().nsites();
108 template <
typename L,
typename I>
110 non_text_kmean(
const document<L>& doc,
const Image<I>& input_)
112 mln_trace(
"scribo::primitive::extract::non_text_kmean");
114 const I& input =
exact(input_);
115 mln_precondition(doc.is_valid());
116 mln_precondition(input.is_valid());
118 const line_set<L>& lines = doc.lines();
128 for_all_lines(l, lines)
129 if (lines(l).type() ==
line::Text)
132 typedef mln::
value::rgb<5> t_rgb5;
133 typedef mln::fun::v2v::rgb8_to_rgbn<5> t_rgb8_to_rgb5;
136 img_rgb5 = mln::
data::
transform(doc.image(), t_rgb8_to_rgb5());
139 mln::clustering::kmean_rgb<
double,5>(
140 (img_rgb5 | pw::
value(content)), 3, 10, 10).unmorph_();
143 mln::util::array<
unsigned>
145 img_lbl8, img_lbl8, 3);
147 unsigned max = 0, bg_id = 0;
148 for_all_ncomponents(c, 3)
162 component_set<L> output;
179 internal::order_bbox<L> func(output);
180 util::array<unsigned> box_ordered_comps;
181 for (
unsigned i = 1; i < output.nelements(); ++i)
182 box_ordered_comps.append(i);
183 std::sort(box_ordered_comps.hook_std_vector_().begin(),
184 box_ordered_comps.hook_std_vector_().end(), func);
189 for (
unsigned i = 0; i < box_ordered_comps.nelements(); ++i)
191 unsigned c = box_ordered_comps(i);
193 pminright = output(c).bbox().pmin(),
194 pmaxleft = output(c).bbox().pmax();
195 pminright.
col() = output(c).bbox().pmax().col();
196 pmaxleft.col() = output(c).bbox().pmin().col();
198 if (merged_elts(output(c).
bbox().pmin())
199 && merged_elts(output(c).
bbox().pmax())
200 && merged_elts(pminright)
201 && merged_elts(pmaxleft))
211 # endif // ! MLN_INCLUDE_ONLY
220 #endif // ! SCRIBO_PRIMITIVE_EXTRACT_NON_TEXT_KMEAN_HH