* debug/decision_image.hh,
* debug/save_linked_bboxes_image.hh,
* draw/bounding_boxes.hh,
* estim/object_groups_v_thickness.hh,
* filter/common/objects_photo.hh,
* filter/internal/compute.hh,
* filter/object_groups_size_ratio.hh,
* filter/object_groups_small.hh,
* filter/object_groups_v_thickness.hh,
* filter/object_links_bbox_overlap.hh,
* filter/object_links_bottom_aligned.hh,
* filter/object_links_non_aligned_simple.hh,
* filter/objects_thick.hh,
* filter/objects_thin.hh,
* filter/objects_with_holes.hh,
* primitive/group/apply.hh,
* primitive/group/from_double_link.hh,
* primitive/group/from_single_link.hh,
* primitive/link/internal/link_single_dmax_base.hh,
* primitive/link/with_single_left_link.hh,
* primitive/link/with_single_right_link.hh,
* src/afp/link.hh,
* src/afp/regroup.hh,
* text/recognition.hh: Update the use of core classes. Replace the
use of object_image with component_set.
---
scribo/ChangeLog | 30 +++
scribo/debug/decision_image.hh | 24 +-
scribo/debug/save_linked_bboxes_image.hh | 72 ++++----
scribo/draw/bounding_boxes.hh | 20 ++-
scribo/estim/object_groups_v_thickness.hh | 26 ++-
scribo/filter/common/objects_photo.hh | 42 ++--
scribo/filter/internal/compute.hh | 30 ++--
scribo/filter/object_groups_size_ratio.hh | 3 +-
scribo/filter/object_groups_small.hh | 11 +-
scribo/filter/object_groups_v_thickness.hh | 5 +-
scribo/filter/object_links_bbox_overlap.hh | 39 ++--
scribo/filter/object_links_bottom_aligned.hh | 23 +-
scribo/filter/object_links_non_aligned_simple.hh | 71 +++----
scribo/filter/objects_thick.hh | 58 +++---
scribo/filter/objects_thin.hh | 98 +++++-----
scribo/filter/objects_with_holes.hh | 217 ++++++++++----------
scribo/primitive/group/apply.hh | 2 +-
scribo/primitive/group/from_double_link.hh | 18 +-
scribo/primitive/group/from_single_link.hh | 5 +-
.../link/internal/link_single_dmax_base.hh | 14 +-
scribo/primitive/link/with_single_left_link.hh | 31 ++--
scribo/primitive/link/with_single_right_link.hh | 24 +-
scribo/src/afp/link.hh | 48 +++--
scribo/src/afp/regroup.hh | 18 +-
scribo/text/recognition.hh | 48 +++--
25 files changed, 528 insertions(+), 449 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index d65a3ef..49045c7 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,35 @@
2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Keep updating code according to last changed in core classes.
+
+ * debug/decision_image.hh,
+ * debug/save_linked_bboxes_image.hh,
+ * draw/bounding_boxes.hh,
+ * estim/object_groups_v_thickness.hh,
+ * filter/common/objects_photo.hh,
+ * filter/internal/compute.hh,
+ * filter/object_groups_size_ratio.hh,
+ * filter/object_groups_small.hh,
+ * filter/object_groups_v_thickness.hh,
+ * filter/object_links_bbox_overlap.hh,
+ * filter/object_links_bottom_aligned.hh,
+ * filter/object_links_non_aligned_simple.hh,
+ * filter/objects_thick.hh,
+ * filter/objects_thin.hh,
+ * filter/objects_with_holes.hh,
+ * primitive/group/apply.hh,
+ * primitive/group/from_double_link.hh,
+ * primitive/group/from_single_link.hh,
+ * primitive/link/internal/link_single_dmax_base.hh,
+ * primitive/link/with_single_left_link.hh,
+ * primitive/link/with_single_right_link.hh,
+ * src/afp/link.hh,
+ * src/afp/regroup.hh,
+ * text/recognition.hh: Update the use of core classes. Replace the
+ use of object_image with component_set.
+
+2010-02-19 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Improve core classes.
* scribo/core/component_info.hh,
diff --git a/scribo/debug/decision_image.hh b/scribo/debug/decision_image.hh
index 34401ba..011dbfa 100644
--- a/scribo/debug/decision_image.hh
+++ b/scribo/debug/decision_image.hh
@@ -58,7 +58,7 @@ namespace scribo
\input[in] filtered_groups A copy of \p groups which have been
filtered.
- \return A color image. Objects part of a validated group are
+ \return A color image. Components part of a validated group are
drawn in green with their bounding box. Otherwise,
they are drawn in red.
*/
@@ -98,23 +98,23 @@ namespace scribo
trace::entering("scribo::debug::decision_image");
const I& input = exact(input_);
- const object_image(L)& objects = groups.object_image_();
+ const component_set<L>& components = groups.object_image_();
mln_precondition(input.is_valid());
mln_precondition(groups.is_valid());
mln_precondition(filtered_groups.is_valid());
mln_precondition(groups.size() == filtered_groups.size());
- mln_precondition(groups.objects_id_() != filtered_groups.objects_id_());
- /// Fixme: check that objects has been computed from input.
+ mln_precondition(groups.components_id_() != filtered_groups.components_id_());
+ /// Fixme: check that components has been computed from input.
image2d<value::rgb8>
decision_image = data::convert(value::rgb8(), input);
for (unsigned i = 1; i < groups.size(); ++i)
if (groups(i) != filtered_groups(i))
- mln::draw::box(decision_image, objects.bbox(i), literal::red);
+ mln::draw::box(decision_image, components(i).bbox(), literal::red);
else
- mln::draw::box(decision_image, objects.bbox(i), literal::green);
+ mln::draw::box(decision_image, components(i).bbox(), literal::green);
trace::exiting("scribo::debug::decision_image");
return decision_image;
@@ -130,20 +130,20 @@ namespace scribo
trace::entering("scribo::debug::decision_image");
const I& input = exact(input_);
- const object_image(L)& objects = links.object_image_();
+ const component_set<L>& components = links.component_set_();
mln_precondition(input.is_valid());
mln_precondition(links.is_valid());
mln_precondition(filtered_links.is_valid());
mln_precondition(links.size() == filtered_links.size());
mln_precondition(links.object_image_() != filtered_links.object_image_());
- /// Fixme: check that objects has been computed from input.
+ /// Fixme: check that components has been computed from input.
image2d<value::rgb8>
decision_image = data::convert(value::rgb8(), input);
- for_all_components(i, objects.bboxes())
- mln::draw::box(decision_image, objects.bbox(i), literal::blue);
+ for_all_components(i, components)
+ mln::draw::box(decision_image, components(i).bbox(), literal::blue);
for (unsigned i = 1; i < links.size(); ++i)
{
@@ -154,8 +154,8 @@ namespace scribo
if (links[i] != filtered_links[i])
value = literal::red;
mln::draw::line(decision_image,
- objects.bbox(i).center(),
- objects.bbox(links[i]).center(),
+ components(i).bbox().pcenter(),
+ components(links[i]).bbox().pcenter(),
value);
}
}
diff --git a/scribo/debug/save_linked_bboxes_image.hh
b/scribo/debug/save_linked_bboxes_image.hh
index c4e3cd1..1e328f8 100644
--- a/scribo/debug/save_linked_bboxes_image.hh
+++ b/scribo/debug/save_linked_bboxes_image.hh
@@ -40,7 +40,7 @@
# include <mln/io/ppm/save.hh>
# include <scribo/core/object_links.hh>
-# include <scribo/core/object_image.hh>
+# include <scribo/core/component_set.hh>
# include <scribo/draw/bounding_boxes.hh>
# include <scribo/draw/bounding_box_links.hh>
@@ -54,11 +54,11 @@ namespace scribo
using namespace mln;
- /// Save the line of objects links image.
+ /// Save the line of components links image.
///
- /// \param[in,out] input The binary from where the objects are extracted.
- /// \param[in] objects An object image.
- /// \param[in] link_array Lines of objects links.
+ /// \param[in,out] input The binary from where the components are extracted.
+ /// \param[in] components An object image.
+ /// \param[in] link_array Lines of components links.
/// \param[in] box_value Value used to draw line bounding boxes.
/// \param[in] link_value Value used to draw line links.
/// \param[in] filename The target file name.
@@ -67,7 +67,7 @@ namespace scribo
template <typename I, typename L>
void
save_linked_bboxes_image(const Image<I>& input,
- const object_image(L)& objects,
+ const component_set<L>& components,
const object_links<L>& array,
const value::rgb8& box_value,
const value::rgb8& link_value,
@@ -80,38 +80,38 @@ namespace scribo
template <typename I, typename L>
void
save_linked_bboxes_image(const Image<I>& input,
- const object_image(L)& objects,
+ const component_set<L>& components,
const object_links<L>& array,
const value::rgb8& box_value,
const value::rgb8& link_value,
const std::string& filename);
- /// Save the line of objects left and right links image.
+ /// Save the line of components left and right links image.
///
- /// \param[in,out] input The binary from where the objects are extracted.
- /// \param[in] objects An object image.
- /// \param[in] left_link Lines of objects left links.
- /// \param[in] right_link Lines of objects right links.
+ /// \param[in,out] input The binary from where the components are extracted.
+ /// \param[in] components An object image.
+ /// \param[in] left_link Lines of components left links.
+ /// \param[in] right_link Lines of components right links.
/// \param[in] box_value Value used to draw line bounding boxes.
/// \param[in] link_value Value used to draw line links.
/// \param[in] filename The target file name.
template <typename I, typename L>
void
save_linked_bboxes_image(const Image<I>& input,
- const object_image(L)& objects,
+ const component_set<L>& components,
const object_links<L>& left_link,
const object_links<L>& right_link,
const value::rgb8& box_value,
const value::rgb8& link_value,
const std::string& filename);
- /// Save the line of objects left and right links image.
+ /// Save the line of components left and right links image.
/// Draw also validated links.
///
- /// \param[in,out] input The binary from where the objects are extracted.
- /// \param[in] objects An object image.
- /// \param[in] left_link Lines of objects left links.
- /// \param[in] right_link Lines of objects right links.
+ /// \param[in,out] input The binary from where the components are extracted.
+ /// \param[in] components An object image.
+ /// \param[in] left_link Lines of components left links.
+ /// \param[in] right_link Lines of components right links.
/// \param[in] box_value Value used to draw line bounding boxes.
/// \param[in] left_link_value Value used to draw line left links.
/// \param[in] right_link_value Value used to draw line left links.
@@ -121,7 +121,7 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
- const object_image(L)& objects,
+ const component_set<L>& components,
const object_links<L>& left_link,
const object_links<L>& right_link,
const value::rgb8& box_value,
@@ -133,8 +133,8 @@ namespace scribo
/// Save the line link graph image.
///
- /// \param[in,out] input The binary from where the objects are extracted.
- /// \param[in] objects An object image.
+ /// \param[in,out] input The binary from where the components are extracted.
+ /// \param[in] components An object image.
/// \param[in] g The link graph.
/// \param[in] box_value Value used to draw line bounding boxes.
/// \param[in] link_value Value used to draw line links.
@@ -142,7 +142,7 @@ namespace scribo
template <typename I, typename L, typename G>
void
save_linked_bboxes_image(const Image<I>& input,
- const object_image(L)& objects,
+ const component_set<L>& components,
const Graph<G>& g,
const value::rgb8& box_value,
const value::rgb8& link_value,
@@ -156,7 +156,7 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
- const object_image(L)& objects,
+ const component_set<L>& components,
const object_links<L>& array,
const value::rgb8& box_value,
const value::rgb8& link_value,
@@ -168,7 +168,7 @@ namespace scribo
mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
- draw::bounding_boxes(tmp, objects.bboxes(), box_value);
+ draw::bounding_boxes(tmp, components, box_value);
draw::bounding_box_links(tmp, array, link_value, anchor);
io::ppm::save(tmp, filename);
@@ -181,13 +181,13 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
- const object_image(L)& objects,
+ const component_set<L>& components,
const object_links<L>& array,
const value::rgb8& box_value,
const value::rgb8& link_value,
const std::string& filename)
{
- save_linked_bboxes_image(input, objects, array, box_value,
+ save_linked_bboxes_image(input, components, array, box_value,
link_value, filename, anchor::Center);
}
@@ -197,7 +197,7 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
- const object_image(L)& objects,
+ const component_set<L>& components,
const object_links<L>& left_link,
const object_links<L>& right_link,
const value::rgb8& box_value,
@@ -209,8 +209,8 @@ namespace scribo
mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
- draw::bounding_boxes(tmp, objects.bboxes(), box_value);
- draw::bounding_box_links(tmp, objects.mass_centers(),
+ draw::bounding_boxes(tmp, components, box_value);
+ draw::bounding_box_links(tmp, components.mass_centers(),
left_link, right_link,
value);
@@ -224,7 +224,7 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
- const object_image(L)& objects,
+ const component_set<L>& components,
const object_links<L>& left_link,
const object_links<L>& right_link,
const value::rgb8& box_value,
@@ -240,10 +240,10 @@ namespace scribo
mln::util::array<mln_result(accu::center<mln_psite(L)>)>
mass_center = labeling::compute(accu::meta::center(),
- objects,
- objects.nlabels());
+ components.labeled_image(),
+ components.nelements());
- draw::bounding_boxes(tmp, objects.bboxes(), box_value);
+ draw::bounding_boxes(tmp, components, box_value);
draw::bounding_box_links(tmp, mass_center,
left_link, right_link,
left_link_value, right_link_value,
@@ -260,7 +260,7 @@ namespace scribo
inline
void
save_linked_bboxes_image(const Image<I>& input,
- const object_image(L)& objects,
+ const component_set<L>& components,
const Graph<G>& g,
const value::rgb8& box_value,
const value::rgb8& link_value,
@@ -272,8 +272,8 @@ namespace scribo
mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
- draw::bounding_boxes(tmp, objects.bboxes(), box_value);
- draw::bounding_box_links(tmp, objects.bboxes(), g, link_value);
+ draw::bounding_boxes(tmp, components, box_value);
+ draw::bounding_box_links(tmp, components, g, link_value);
io::ppm::save(tmp, filename);
diff --git a/scribo/draw/bounding_boxes.hh b/scribo/draw/bounding_boxes.hh
index 0d4ab9b..3dce077 100644
--- a/scribo/draw/bounding_boxes.hh
+++ b/scribo/draw/bounding_boxes.hh
@@ -35,7 +35,7 @@
# include <mln/util/array.hh>
# include <scribo/core/macros.hh>
-# include <scribo/core/object_image.hh>
+# include <scribo/core/component_set.hh>
namespace scribo
{
@@ -57,7 +57,7 @@ namespace scribo
template <typename I, typename L>
void
bounding_boxes(Image<I>& input_,
- const object_image(L)& objects,
+ const component_set<L>& components,
const mln_value(I)& value);
@@ -88,11 +88,21 @@ namespace scribo
template <typename I, typename L>
inline
void
- bounding_boxes(Image<I>& input,
- const object_image(L)& objects,
+ bounding_boxes(Image<I>& input_,
+ const component_set<L>& components,
const mln_value(I)& value)
{
- bounding_boxes(input, objects.bboxes(), value);
+ trace::entering("scribo::draw::bounding_boxes");
+
+ I& input = exact(input_);
+
+ mln_precondition(input.is_valid());
+
+ for_all_comps(i, components)
+ if (components(i).bbox().is_valid())
+ mln::draw::box(input, components(i).bbox(), value);
+
+ trace::exiting("scribo::draw::bounding_boxes");
}
diff --git a/scribo/estim/object_groups_v_thickness.hh
b/scribo/estim/object_groups_v_thickness.hh
index 6453a1a..6d74f2c 100644
--- a/scribo/estim/object_groups_v_thickness.hh
+++ b/scribo/estim/object_groups_v_thickness.hh
@@ -69,23 +69,27 @@ namespace scribo
mln_precondition(groups.is_valid());
- const object_image(L)& objects = groups.object_image_();
+ const component_set<L>& components = groups.component_set_();
//FIXME: remove when object_groups will store the number of
//elements per group.
- mln::util::array<unsigned> group_card(groups.size(), 0.0);
+ mln::util::array<unsigned> group_card(groups.nelements(), 0.0);
- mln::util::array<float> output(groups.size(), 0.0);
- for_all_components(i, objects.bboxes())
- {
- output[groups[i]] += objects.bbox(i).pmax().row()
- - objects.bbox(i).pmin().row();
- ++group_card[groups[i]];
- }
+ mln::util::array<float> output(groups.nelements(), 0.0);
+ for_all_comps(i, components)
+ if (components(i).is_valid())
+ {
+ output(groups(i)) += components(i).bbox().pmax().row()
+ - components(i).bbox().pmin().row();
+ ++group_card(groups(i));
+ }
output(0) = 0;
- for_all_components(i, output)
- output(i) /= static_cast<float>(group_card[i]);
+ for_all_groups(i, output)
+ if (components(i).is_valid())
+ output(i) /= static_cast<float>(group_card(i));
+ else
+ output(i) = 0;
trace::exiting("scribo::estim::object_groups_v_thickness");
return output;
diff --git a/scribo/filter/common/objects_photo.hh
b/scribo/filter/common/objects_photo.hh
index 53da0a8..2d8d581 100644
--- a/scribo/filter/common/objects_photo.hh
+++ b/scribo/filter/common/objects_photo.hh
@@ -23,15 +23,15 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_FILTER_COMMON_OBJECTS_PHOTO_HH
-# define SCRIBO_FILTER_COMMON_OBJECTS_PHOTO_HH
+#ifndef SCRIBO_FILTER_COMMON_COMPONENTS_PHOTO_HH
+# define SCRIBO_FILTER_COMMON_COMPONENTS_PHOTO_HH
/// \file
///
-/// \brief Common objects filters to use in photos.
+/// \brief Common components filters to use in photos.
-# include <scribo/core/object_image.hh>
+# include <scribo/core/component_set.hh>
# include <scribo/filter/objects_small.hh>
# include <scribo/filter/objects_thin.hh>
@@ -48,41 +48,41 @@ namespace scribo
{
- /*! \brief Common objects filters to use in photos.
+ /*! \brief Common components filters to use in photos.
- \param[in] objects An object image.
+ \param[in] components An object image.
\return A filtered object image.
*/
template <typename L>
- object_image(L)
- objects_photo(const object_image(L)& objects);
+ component_set<L>
+ components_photo(const component_set<L>& components);
# ifndef MLN_INCLUDE_ONLY
template <typename L>
- object_image(L)
- objects_photo(const object_image(L)& objects)
+ component_set<L>
+ components_photo(const component_set<L>& components)
{
- trace::entering("scribo::filter::common::objects_photo");
+ trace::entering("scribo::filter::common::components_photo");
- mln_precondition(objects.is_valid());
+ mln_precondition(components.is_valid());
- object_image(L) filtered_objects
- = scribo::filter::objects_small(objects, 6);
+ component_set<L> filtered_components
+ = scribo::filter::components_small(components, 6);
- filtered_objects
- = scribo::filter::objects_thin(filtered_objects, 1);
+ filtered_components
+ = scribo::filter::components_thin(filtered_components, 1);
-// filtered_objects
-// = scribo::filter::objects_thick(filtered_objects,
+// filtered_components
+// = scribo::filter::components_thick(filtered_components,
// math::min(input.ncols(),
// input.nrows()) / 5);
- trace::exiting("scribo::filter::common::objects_photo");
- return filtered_objects;
+ trace::exiting("scribo::filter::common::components_photo");
+ return filtered_components;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -95,4 +95,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_FILTER_COMMON_OBJECTS_PHOTO_HH
+#endif // ! SCRIBO_FILTER_COMMON_COMPONENTS_PHOTO_HH
diff --git a/scribo/filter/internal/compute.hh b/scribo/filter/internal/compute.hh
index 346cee8..bd00eb6 100644
--- a/scribo/filter/internal/compute.hh
+++ b/scribo/filter/internal/compute.hh
@@ -35,8 +35,8 @@
# include <mln/util/array.hh>
-# include <scribo/core/object_image.hh>
-# include <scribo/primitive/extract/objects.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/primitive/extract/components.hh>
@@ -71,14 +71,14 @@ namespace scribo
/// Filter an object image.
///
- /// \param[in] objects An object image.
+ /// \param[in] components A component set.
/// \param[in] filter A filter functor.
///
/// \result A filtered object image.
//
template <typename L, typename F>
- object_image(L)
- compute(const object_image(L)& objects,
+ component_set<L>
+ compute(const component_set<L>& components,
const Function_v2b<F>& filter);
@@ -103,14 +103,14 @@ namespace scribo
V nlabels;
typedef mln_ch_value(I,V) lbl_t;
- object_image(lbl_t) objects
- = primitive::extract::objects(input, nbh, nlabels);
+ component_set<lbl_t> components
+ = primitive::extract::components(input, nbh, nlabels);
- filter.update_objects(objects);
- objects.relabel(filter);
+ filter.update_components(components);
+ components.relabel(filter);
mln_concrete(I) output = duplicate(input);
- data::fill((output | pw::value(objects) == literal::zero).rw(), false);
+ data::fill((output | pw::value(components) == literal::zero).rw(), false);
trace::exiting("scribo::filter::internal::compute");
return output;
@@ -119,16 +119,16 @@ namespace scribo
template <typename L, typename F>
inline
- object_image(L)
- compute(const object_image(L)& objects,
+ component_set<L>
+ compute(const component_set<L>& components,
const Function_v2b<F>& filter)
{
trace::entering("scribo::filter::internal::compute");
- mln_precondition(objects.is_valid());
+ mln_precondition(components.is_valid());
- object_image(L) output;
- output.init_from_(objects);
+ component_set<L> output;
+ output.init_from_(components);
output.relabel(filter);
trace::exiting("scribo::filter::internal::compute");
diff --git a/scribo/filter/object_groups_size_ratio.hh
b/scribo/filter/object_groups_size_ratio.hh
index b52c30d..1c05560 100644
--- a/scribo/filter/object_groups_size_ratio.hh
+++ b/scribo/filter/object_groups_size_ratio.hh
@@ -85,7 +85,8 @@ namespace scribo
object_groups<L> output(groups);
output(0) = 0;
for (unsigned i = 1; i < output.size(); ++i)
- if ((invalid_object_in_group[groups[i]] /
static_cast<float>(group_size[groups[i]])) >= max_invalid_ratio_per_group)
+ if ((invalid_object_in_group[groups[i]] /
static_cast<float>(group_size[groups[i]])) >= max_invalid_ratio_per_group
+ || !components(i).is_valid())
output(i) = 0;
trace::exiting("scribo::filter::object_groups_size_ratio");
diff --git a/scribo/filter/object_groups_small.hh b/scribo/filter/object_groups_small.hh
index 6a50aba..b2662c0 100644
--- a/scribo/filter/object_groups_small.hh
+++ b/scribo/filter/object_groups_small.hh
@@ -73,14 +73,15 @@ namespace scribo
mln_precondition(groups.is_valid());
// Counting the number of objects per group.
- mln::util::array<unsigned> group_size(groups.size(), 0);
- for (unsigned i = 1; i < group_size.size(); ++i)
- ++group_size[groups[i]];
+ mln::util::array<unsigned> group_size(groups.nelements(), 0);
+ for_all_groups(i, group_size)
+ ++group_size[groups(i)];
object_groups<L> output(groups);
output(0) = 0;
- for (unsigned i = 1; i < output.size(); ++i)
- if (group_size[groups[i]] < n_links)
+ for_all_groups(i, output)
+ if (group_size[groups(i)] < n_links
+ || !groups.component_set_()(i).is_valid())
output(i) = 0;
trace::exiting("scribo::filter::object_groups_small");
diff --git a/scribo/filter/object_groups_v_thickness.hh
b/scribo/filter/object_groups_v_thickness.hh
index f16f1db..a4c5277 100644
--- a/scribo/filter/object_groups_v_thickness.hh
+++ b/scribo/filter/object_groups_v_thickness.hh
@@ -77,8 +77,9 @@ namespace scribo
object_groups<L> output(groups);
output(0) = 0;
- for (unsigned i = 1; i < output.size(); ++i)
- if (group_thickness[groups[i]] < thickness)
+ for (unsigned i = 1; i < output.nelements(); ++i)
+ if (groups.component_set_()(i).is_valid()
+ && group_thickness[groups(i)] < thickness)
output(i) = 0;
trace::exiting("scribo::filter::object_groups_v_thickness");
diff --git a/scribo/filter/object_links_bbox_overlap.hh
b/scribo/filter/object_links_bbox_overlap.hh
index 83b5dfc..d2d9376 100644
--- a/scribo/filter/object_links_bbox_overlap.hh
+++ b/scribo/filter/object_links_bbox_overlap.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -28,7 +29,7 @@
/// \file
///
-/// Invalidate links between two objects having their bounding box
+/// Invalidate links between two components having their bounding box
/// overlapping too much.
@@ -38,7 +39,7 @@
# include <scribo/core/macros.hh>
# include <scribo/core/object_links.hh>
-# include <scribo/core/object_image.hh>
+# include <scribo/core/component_set.hh>
# include <scribo/filter/object_links_bbox_ratio.hh>
namespace scribo
@@ -49,11 +50,11 @@ namespace scribo
using namespace mln;
- /*! \brief Invalidate links between two objects having their bounding box
+ /*! \brief Invalidate links between two components having their bounding box
overlapping too much.
- \param[in] objects An object image.
- \param[in] links Link objects information.
+ \param[in] components A component set.
+ \param[in] links Link components information.
\param[in] max_overlap_ratio The maximum ratio of the overlapping
areas.
@@ -61,7 +62,7 @@ namespace scribo
*/
template <typename L>
object_links<L>
- object_links_bbox_overlap(const object_image(L)& objects,
+ object_links_bbox_overlap(const component_set<L>& components,
const object_links<L>& links,
float max_overlap_ratio);
@@ -71,31 +72,29 @@ namespace scribo
template <typename L>
object_links<L>
- object_links_bbox_overlap(const object_image(L)& objects,
+ object_links_bbox_overlap(const component_set<L>& components,
const object_links<L>& links,
float max_overlap_ratio)
{
trace::entering("scribo::filter::object_links_bbox_overlap");
- mln_precondition(objects.is_valid());
+ mln_precondition(components.is_valid());
mln_precondition(links.is_valid());
- mln_precondition(objects.id_() == links.objects_id_());
+ mln_precondition(components.id_() == links.components_id_());
- typedef typename object_image(L)::bbox_t bbox_t;
- const mln::util::array<bbox_t>& bboxes = objects.bboxes();
object_links<L> output(links);
- for_all_components(i, objects.bboxes())
- if (links(i) != i)
+ for_all_components(i, components)
+ if (components(i).is_valid() && links(i) != i)
{
bool has_intersection = true;
mln_site(L) pmin, pmax;
for (unsigned dim = 0; dim < mln_site_(L)::dim; ++dim)
{
- pmin[dim] = math::max(bboxes(i).pmin()[dim],
- bboxes(links[i]).pmin()[dim]);
- pmax[dim] = math::min(bboxes(i).pmax()[dim],
- bboxes(links[i]).pmax()[dim]);
+ pmin[dim] = math::max(components(i).bbox().pmin()[dim],
+ components(links[i]).bbox().pmin()[dim]);
+ pmax[dim] = math::min(components(i).bbox().pmax()[dim],
+ components(links[i]).bbox().pmax()[dim]);
if (pmin[dim] > pmax[dim])
{
@@ -109,8 +108,8 @@ namespace scribo
mln_box(L) interbbox(pmin, pmax);
float
- ratio_i = interbbox.nsites() /(float)bboxes(i).nsites(),
- ratio_link_i = interbbox.nsites() /(float)bboxes(links(i)).nsites();
+ ratio_i = interbbox.nsites() /(float)components(i).bbox().nsites(),
+ ratio_link_i = interbbox.nsites() /(float)components(links(i)).bbox().nsites();
if (ratio_i >= max_overlap_ratio
|| ratio_link_i >= max_overlap_ratio)
diff --git a/scribo/filter/object_links_bottom_aligned.hh
b/scribo/filter/object_links_bottom_aligned.hh
index 1afebf7..ce6f6af 100644
--- a/scribo/filter/object_links_bottom_aligned.hh
+++ b/scribo/filter/object_links_bottom_aligned.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -28,7 +29,7 @@
/// \file
///
-/// Invalidate links between two objects if their bottom are not
+/// Invalidate links between two components if their bottom are not
/// aligned.
@@ -36,7 +37,7 @@
# include <scribo/core/macros.hh>
# include <scribo/core/object_links.hh>
-# include <scribo/core/object_image.hh>
+# include <scribo/core/component_set.hh>
# include <scribo/filter/object_links_non_aligned_simple.hh>
@@ -48,12 +49,12 @@ namespace scribo
using namespace mln;
- /*! \brief Invalidate links between two objects if their bottom are not
+ /*! \brief Invalidate links between two components if their bottom are not
aligned.
- \param[in] objects An object image.
- \param[in] links Object links information.
- \param[in] max_alpha Maximum angle value (degrees).
+ \param[in] components A component set.
+ \param[in] links Object links information.
+ \param[in] max_alpha Maximum angle value (degrees).
\verbatim
@@ -81,7 +82,7 @@ namespace scribo
*/
template <typename L>
object_links<L>
- object_links_bottom_aligned(const object_image(L)& objects,
+ object_links_bottom_aligned(const component_set<L>& components,
const object_links<L>& links,
float max_alpha);
@@ -91,17 +92,17 @@ namespace scribo
template <typename L>
object_links<L>
- object_links_bottom_aligned(const object_image(L)& objects,
+ object_links_bottom_aligned(const component_set<L>& components,
const object_links<L>& links,
float max_alpha)
{
trace::entering("scribo::filter::object_links_bottom_aligned");
- mln_precondition(objects.is_valid());
+ mln_precondition(components.is_valid());
mln_precondition(links.is_valid());
object_links<L>
- output = object_links_non_aligned_simple(objects, links,
+ output = object_links_non_aligned_simple(components, links,
2, max_alpha);
trace::exiting("scribo::filter::object_links_bottom_aligned");
diff --git a/scribo/filter/object_links_non_aligned_simple.hh
b/scribo/filter/object_links_non_aligned_simple.hh
index 15be8e9..c27bea5 100644
--- a/scribo/filter/object_links_non_aligned_simple.hh
+++ b/scribo/filter/object_links_non_aligned_simple.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -28,7 +29,7 @@
/// \file
///
-/// Invalidate links between two non aligned objects.
+/// Invalidate links between two non aligned components.
# include <mln/util/array.hh>
@@ -47,12 +48,12 @@ namespace scribo
using namespace mln;
- /*! \brief Invalidate links between two non aligned objects.
+ /*! \brief Invalidate links between two non aligned components.
Alignment is based on a given edge of object bounding boxes.
- \param[in] objects An object image.
- \param[in] links Object links information.
- \param[in] max_alpha Maximum angle value (degrees).
+ \param[in] components A component set.
+ \param[in] links Object links information.
+ \param[in] max_alpha Maximum angle value (degrees).
Exemple with dim == 1 and edge == 1 (bottom
@@ -90,7 +91,7 @@ namespace scribo
*/
template <typename L>
object_links<L>
- object_links_non_aligned_simple(const object_image(L)& objects,
+ object_links_non_aligned_simple(const component_set<L>& components,
const object_links<L>& links,
unsigned edge,
float max_alpha);
@@ -101,18 +102,16 @@ namespace scribo
template <typename L>
object_links<L>
- object_links_non_aligned_simple(const object_image(L)& objects,
+ object_links_non_aligned_simple(const component_set<L>& comps,
const object_links<L>& links,
unsigned edge,
float max_alpha)
{
trace::entering("scribo::filter::object_links_non_aligned_simple");
- mln_precondition(objects.is_valid());
+ mln_precondition(comps.is_valid());
mln_precondition(links.is_valid());
- typedef typename object_image(L)::bbox_t bbox_t;
- const mln::util::array<bbox_t>& bboxes = objects.bboxes();
object_links<L> output(links);
float dr, dc;
@@ -122,14 +121,14 @@ namespace scribo
// Center
if (edge == 0)
{
- for_all_components(i, objects.bboxes())
+ for_all_comps(i, comps)
{
if (links[i] != i)
{
- dr = math::abs(bboxes[i].center().row()
- - bboxes[links[i]].center().row());
- dc = math::abs(bboxes[i].center().col()
- - bboxes[links[i]].center().col());
+ dr = math::abs(comps(i).bbox().pcenter().row()
+ - comps(links[i]).bbox().pcenter().row());
+ dc = math::abs(comps(i).bbox().pcenter().col()
+ - comps(links[i]).bbox().pcenter().col());
if (std::atan(dr / dc) > max_alpha_rad)
output[i] = i;
@@ -139,13 +138,13 @@ namespace scribo
// Top
else if (edge == 1)
{
- for_all_components(i, objects.bboxes())
+ for_all_comps(i, comps.bboxes())
if (links[i] != i)
{
- dr = math::abs(bboxes[i].pmin().row()
- - bboxes[links[i]].pmin().row());
- dc = math::abs(bboxes[i].center().col()
- - bboxes[links[i]].center().col());
+ dr = math::abs(comps(i).bbox().pmin().row()
+ - comps(links[i]).bbox().pmin().row());
+ dc = math::abs(comps(i).bbox().pcenter().col()
+ - comps(links[i]).bbox().pcenter().col());
if (std::atan(dr / dc) > max_alpha_rad)
output[i] = i;
@@ -154,14 +153,14 @@ namespace scribo
// Bottom
else if (edge == 2)
{
- for_all_components(i, objects.bboxes())
+ for_all_comps(i, comps.bboxes())
{
if (links[i] != i)
{
- dr = math::abs(bboxes[i].pmax().row()
- - bboxes[links[i]].pmax().row());
- dc = math::abs(bboxes[i].center().col()
- - bboxes[links[i]].center().col());
+ dr = math::abs(comps(i).bbox().pmax().row()
+ - comps(links[i]).bbox().pmax().row());
+ dc = math::abs(comps(i).bbox().pcenter().col()
+ - comps(links[i]).bbox().pcenter().col());
if (std::atan(dr / dc) > max_alpha_rad)
output[i] = i;
@@ -171,14 +170,14 @@ namespace scribo
// Left
else if (edge == 3)
{
- for_all_components(i, objects.bboxes())
+ for_all_comps(i, comps.bboxes())
{
if (links[i] != i)
{
- dr = math::abs(bboxes[i].center().row()
- - bboxes[links[i]].center().row());
- dc = math::abs(bboxes[i].pmin().col()
- - bboxes[links[i]].pmin().col());
+ dr = math::abs(comps(i).bbox().pcenter().row()
+ - comps(links[i]).bbox().pcenter().row());
+ dc = math::abs(comps(i).bbox().pmin().col()
+ - comps(links[i]).bbox().pmin().col());
if (std::atan(dc / dr) > max_alpha_rad)
output[i] = i;
@@ -188,14 +187,14 @@ namespace scribo
// Right
else if (edge == 4)
{
- for_all_components(i, objects.bboxes())
+ for_all_comps(i, comps.bboxes())
{
if (links[i] != i)
{
- dr = math::abs(bboxes[i].center().row()
- - bboxes[links[i]].center().row());
- dc = math::abs(bboxes[i].pmax().col()
- - bboxes[links[i]].pmax().col());
+ dr = math::abs(comps(i).bbox().pcenter().row()
+ - comps(links[i]).bbox().pcenter().row());
+ dc = math::abs(comps(i).bbox().pmax().col()
+ - comps(links[i]).bbox().pmax().col());
if (std::atan(dc / dr) > max_alpha_rad)
output[i] = i;
diff --git a/scribo/filter/objects_thick.hh b/scribo/filter/objects_thick.hh
index 5fe884e..c933532 100644
--- a/scribo/filter/objects_thick.hh
+++ b/scribo/filter/objects_thick.hh
@@ -28,15 +28,15 @@
/// \file
///
-/// Remove too thick objects.
+/// Remove too thick components.
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/util/array.hh>
-# include <scribo/core/object_image.hh>
-# include <scribo/primitive/extract/objects.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/primitive/extract/components.hh>
@@ -48,14 +48,14 @@ namespace scribo
using namespace mln;
- /// Remove objects thicker or equal to \p max_thickness.
+ /// Remove components thicker or equal to \p max_thickness.
///
/// \param[in] input_ A binary image.
/// \param[in] nbh_ A neighborhood used in labeling algorithms.
/// \param[in] label_type The label type used for labeling.
/// \param[in] max_thickness The maximum thickness value.
///
- /// \result A binary image without thick objects.
+ /// \result A binary image without thick components.
//
template <typename I, typename N, typename V>
inline
@@ -66,17 +66,17 @@ namespace scribo
unsigned max_thickness);
- /// Remove objects thicker or equal to \p max_thickness.
+ /// Remove components thicker or equal to \p max_thickness.
///
- /// \param[in] objects An object image.
+ /// \param[in] components An object image.
/// \param[in] max_thickness The maximum thickness value.
///
- /// \result An object image without too thick objects.
+ /// \result An object image without too thick components.
//
template <typename L>
inline
- object_image(L)
- objects_thick(const object_image(L)& objects,
+ component_set<L>
+ objects_thick(const component_set<L>& components,
unsigned max_thickness);
@@ -85,7 +85,7 @@ namespace scribo
namespace internal
{
- /// Filter Functor. Return false for all objects which are too
+ /// Filter Functor. Return false for all components which are too
/// large.
template <typename L>
struct thick_object_filter
@@ -94,16 +94,16 @@ namespace scribo
/// Constructor
///
- /// \param[in] objects An object image.
+ /// \param[in] components An object image.
/// \param[in] max_thickness the maximum thickness allowed.
- thick_object_filter(const object_image(L)& objects,
+ thick_object_filter(const component_set<L>& components,
unsigned max_thickness)
- : objects_(objects), max_thickness_(max_thickness)
+ : components_(components), max_thickness_(max_thickness)
{
}
- /// Return false if the objects is thicker than
+ /// Return false if the components is thicker than
/// \p max_thickness_.
///
/// \param[in] l An image value.
@@ -111,13 +111,13 @@ namespace scribo
{
if (l == literal::zero)
return true;
- return objects_.bbox(l).nrows() < max_thickness_
- && objects_.bbox(l).ncols() < max_thickness_;
+ return components_.bbox(l).nrows() < max_thickness_
+ && components_.bbox(l).ncols() < max_thickness_;
}
/// An object image.
- object_image(L) objects_;
+ component_set<L> components_;
/// The maximum thickness.
unsigned max_thickness_;
@@ -145,15 +145,15 @@ namespace scribo
V nlabels;
typedef mln_ch_value(I,V) lbl_t;
- object_image(lbl_t) objects
- = primitive::extract::objects(input, nbh, nlabels);
+ component_set<lbl_t> components
+ = primitive::extract::components(input, nbh, nlabels);
typedef internal::thick_object_filter<lbl_t> func_t;
- func_t fv2b(objects, max_thickness);
- objects.relabel(fv2b);
+ func_t fv2b(components, max_thickness);
+ components.relabel(fv2b);
mln_concrete(I) output = duplicate(input);
- data::fill((output | pw::value(objects) == literal::zero).rw(), false);
+ data::fill((output | pw::value(components) == literal::zero).rw(), false);
trace::exiting("scribo::filter::objects_thick");
return output;
@@ -162,19 +162,19 @@ namespace scribo
template <typename L>
inline
- object_image(L)
- objects_thick(const object_image(L)& objects,
+ component_set<L>
+ objects_thick(const component_set<L>& components,
unsigned max_thickness)
{
trace::entering("scribo::filter::objects_thick");
- mln_precondition(objects.is_valid());
+ mln_precondition(components.is_valid());
typedef internal::thick_object_filter<L> func_t;
- func_t is_not_too_thick(objects, max_thickness);
+ func_t is_not_too_thick(components, max_thickness);
- object_image(L) output;
- output.init_from_(objects);
+ component_set<L> output;
+ output.init_from_(components);
output.relabel(is_not_too_thick);
trace::exiting("scribo::filter::objects_thick");
diff --git a/scribo/filter/objects_thin.hh b/scribo/filter/objects_thin.hh
index ea8a5af..c821b74 100644
--- a/scribo/filter/objects_thin.hh
+++ b/scribo/filter/objects_thin.hh
@@ -23,12 +23,12 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_FILTER_OBJECTS_THIN_HH
-# define SCRIBO_FILTER_OBJECTS_THIN_HH
+#ifndef SCRIBO_FILTER_COMPONENTS_THIN_HH
+# define SCRIBO_FILTER_COMPONENTS_THIN_HH
/// \file
///
-/// Remove too thin objects.
+/// Remove too thin components.
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
@@ -37,8 +37,8 @@
# include <mln/util/array.hh>
-# include <scribo/core/object_image.hh>
-# include <scribo/primitive/extract/objects.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/primitive/extract/components.hh>
# include <scribo/filter/internal/compute.hh>
namespace scribo
@@ -49,35 +49,35 @@ namespace scribo
using namespace mln;
- /// Remove objects thinner or equal to \p min_thickness.
+ /// Remove components thinner or equal to \p min_thickness.
///
/// \param[in] input_ a binary image.
/// \param[in] nbh_ a neighborhood used in labeling algorithms.
/// \param[in] label_type the label type used for labeling.
/// \param[in] min_thickness the minimum thickness value.
///
- /// \result A binary image without thin objects.
+ /// \result A binary image without thin components.
//
template <typename I, typename N, typename V>
inline
mln_concrete(I)
- objects_thin(const Image<I>& input_,
- const Neighborhood<N>& nbh_,
- const V& label_type,
- unsigned min_thickness);
+ components_thin(const Image<I>& input_,
+ const Neighborhood<N>& nbh_,
+ const V& label_type,
+ unsigned min_thickness);
/// Remove lines of text thinner or equal to \p min_thickness.
///
- /// \param[in] objects An object image.
+ /// \param[in] components An object image.
/// \param[in] min_thickness the minimum thickness value.
///
- /// \result An object image without too thin objects.
+ /// \result An object image without too thin components.
//
template <typename L>
inline
- object_image(L)
- objects_thin(const object_image(L)& text,
- unsigned min_thickness);
+ component_set<L>
+ components_thin(const component_set<L>& text,
+ unsigned min_thickness);
# ifndef MLN_INCLUDE_ONLY
@@ -87,23 +87,23 @@ namespace scribo
/// Filter Functor.
- /// Return false for all objects which are too large.
+ /// Return false for all components which are too large.
template <typename L>
- struct objects_thin_filter
- : Function_v2b< objects_thin_filter<L> >
+ struct components_thin_filter
+ : Function_v2b< components_thin_filter<L> >
{
/// Constructor
///
- /// \param[in] objects object bounding boxes.
+ /// \param[in] components object bounding boxes.
/// \param[in] min_thickness the minimum thickness allowed.
- objects_thin_filter(const object_image(L)& objects,
- unsigned min_thickness)
- : objects_(objects), min_thickness_(min_thickness)
+ components_thin_filter(const component_set<L>& components,
+ unsigned min_thickness)
+ : components_(components), min_thickness_(min_thickness)
{
}
- /// Return false if the objects is thinner than
+ /// Return false if the components is thinner than
/// \p min_thickness_.
///
/// \param[in] l An image value.
@@ -111,12 +111,12 @@ namespace scribo
{
if (l == literal::zero)
return true;
- return objects_.bbox(l).nrows() > min_thickness_
- && objects_.bbox(l).ncols() > min_thickness_;
+ return components_.bbox(l).nrows() > min_thickness_
+ && components_.bbox(l).ncols() > min_thickness_;
}
/// Component bounding boxes.
- object_image(L) objects_;
+ component_set<L> components_;
/// The minimum thickness.
unsigned min_thickness_;
@@ -129,12 +129,12 @@ namespace scribo
template <typename I, typename N, typename V>
inline
mln_concrete(I)
- objects_thin(const Image<I>& input_,
- const Neighborhood<N>& nbh_,
- const V& label_type,
- unsigned min_thickness)
+ components_thin(const Image<I>& input_,
+ const Neighborhood<N>& nbh_,
+ const V& label_type,
+ unsigned min_thickness)
{
- trace::entering("scribo::filter::objects_thin");
+ trace::entering("scribo::filter::components_thin");
const I& input = exact(input_);
const N& nbh = exact(nbh_);
@@ -145,38 +145,38 @@ namespace scribo
V nlabels;
typedef mln_ch_value(I,V) lbl_t;
- object_image(lbl_t) objects
- = primitive::extract::objects(input, nbh, nlabels);
+ component_set<lbl_t> components
+ = primitive::extract::components(input, nbh, nlabels);
- typedef internal::objects_thin_filter<lbl_t> func_t;
- func_t fv2b(objects, min_thickness);
- objects.relabel(fv2b);
+ typedef internal::components_thin_filter<lbl_t> func_t;
+ func_t fv2b(components, min_thickness);
+ components.relabel(fv2b);
mln_concrete(I) output = duplicate(input);
- data::fill((output | (pw::value(objects) == pw::cst(literal::zero))).rw(),
+ data::fill((output | (pw::value(components) == pw::cst(literal::zero))).rw(),
false);
- trace::exiting("scribo::filter::objects_thin");
+ trace::exiting("scribo::filter::components_thin");
return output;
}
template <typename L>
inline
- object_image(L)
- objects_thin(const object_image(L)& objects,
- unsigned min_thickness)
+ component_set<L>
+ components_thin(const component_set<L>& components,
+ unsigned min_thickness)
{
- trace::entering("scribo::filter::objects_thin");
+ trace::entering("scribo::filter::components_thin");
- mln_precondition(objects.is_valid());
+ mln_precondition(components.is_valid());
- typedef internal::objects_thin_filter<L> func_t;
- func_t is_not_too_thin(objects, min_thickness);
+ typedef internal::components_thin_filter<L> func_t;
+ func_t is_not_too_thin(components, min_thickness);
- object_image(L) output = internal::compute(objects, is_not_too_thin);
+ component_set<L> output = internal::compute(components, is_not_too_thin);
- trace::exiting("scribo::filter::objects_thin");
+ trace::exiting("scribo::filter::components_thin");
return output;
}
@@ -187,4 +187,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_FILTER_OBJECTS_THIN_HH
+#endif // ! SCRIBO_FILTER_COMPONENTS_THIN_HH
diff --git a/scribo/filter/objects_with_holes.hh b/scribo/filter/objects_with_holes.hh
index c448e58..dc72383 100644
--- a/scribo/filter/objects_with_holes.hh
+++ b/scribo/filter/objects_with_holes.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -28,7 +29,7 @@
/// \file
///
-/// \brief Remove objects having a minimum number of holes.
+/// \brief Remove components having a minimum number of holes.
# include <sstream>
@@ -56,7 +57,7 @@
# include <mln/labeling/background.hh>
# include <scribo/core/macros.hh>
-# include <scribo/core/object_image.hh>
+# include <scribo/core/component_set.hh>
# include <scribo/filter/internal/compute.hh>
# include <mln/data/fill.hh>
@@ -78,22 +79,22 @@ namespace scribo
using namespace mln;
- /*! \brief Remove objects having a minimum number of holes.
+ /*! \brief Remove components having a minimum number of holes.
*/
template <typename L>
- object_image(L)
- objects_with_holes(const object_image(L)& objects,
+ component_set<L>
+ objects_with_holes(const component_set<L>& components,
unsigned min_holes_count,
unsigned min_size);
template <typename L>
inline
- object_image(L)
- objects_with_two_holes(const object_image(L)& objects,
+ component_set<L>
+ components_with_two_holes(const component_set<L>& components,
unsigned min_size);
@@ -113,32 +114,36 @@ namespace scribo
template <typename L>
mln_concrete(L)
- compute_bboxes_image(const object_image(L)& objects)
+ compute_bboxes_image(const component_set<L>& components)
{
typedef mln_psite(L) P;
typedef mln_dpsite(P) D;
- extension::adjust_fill(objects, 1, 0);
+ const L& lbl = components.labeled_image();
+ extension::adjust_fill(lbl, 1, 0);
mln_concrete(L) output;
- initialize(output, objects);
+ initialize(output, lbl);
data::fill(output, 0);
- for_all_components(i, objects.bboxes())
- {
- mln_box(L) b = objects.bbox(i);
- b.enlarge(1);
-
- unsigned
- nrows = b.pmax().row() - b.pmin().row() + 1,
- ncols = b.pmax().col() - b.pmin().col() + 1,
- row_offset = objects.labeled_image_().delta_index(D(+1, -ncols));
-
- mln_value(L) *ptr = &output(b.pmin());
- for (unsigned row = 0; row < nrows; ++row, ptr += row_offset)
- for (unsigned col = 0; col < ncols; ++col)
- *ptr++ = i;
- }
+ for_all_comps(i, components)
+ if (components(i).is_valid())
+ {
+ std::cout << components(i).bbox() << std::endl;
+ std::cout << components(i).tag() << std::endl;
+ mln_box(L) b = components(i).bbox();
+ b.enlarge(1);
+
+ unsigned
+ nrows = b.pmax().row() - b.pmin().row() + 1,
+ ncols = b.pmax().col() - b.pmin().col() + 1,
+ row_offset = lbl.delta_index(D(+1, -ncols));
+
+ mln_value(L) *ptr = &output(b.pmin());
+ for (unsigned row = 0; row < nrows; ++row, ptr += row_offset)
+ for (unsigned col = 0; col < ncols; ++col)
+ *ptr++ = i;
+ }
extension::duplicate(output);
@@ -156,47 +161,47 @@ namespace scribo
*/
template <typename L>
inline
- object_image(L)
- objects_with_holes(const object_image(L)& objects,
+ component_set<L>
+ objects_with_holes(const component_set<L>& components,
unsigned min_holes_count,
unsigned min_size)
{
trace::entering("scribo::filter::objects_with_holes");
- typedef object_image(L) O;
+ typedef component_set<L> O;
neighb2d nbh = c4();
image2d<unsigned> parent, card;
L bboxes_ima;
util::array<util::set<unsigned> > bg_comps(
- static_cast<unsigned>(objects.nlabels()) + 1);
+ static_cast<unsigned>(components.nelements()) + 1);
fun::i2v::array<bool>
- to_keep(static_cast<unsigned>(objects.nlabels()) + 1,
+ to_keep(static_cast<unsigned>(components.nelements()) + 1,
false);
- const L& lbl = objects.labeled_image_();
+ const L& lbl = components.labeled_image();
- std::cout << "objects.nlabels = " << objects.nlabels()
<< std::endl;
+ std::cout << "components.nlabels = " <<
components.nelements() << std::endl;
util::timer timer_;
timer_.start();
// init
{
- extension::adjust_fill(objects, nbh, mln_max(mln_value(L)));
- initialize(parent, objects);
+ extension::adjust_fill(lbl, nbh, mln_max(mln_value(L)));
+ initialize(parent, lbl);
data::fill(parent, 0u);
- initialize(card, objects);
+ initialize(card, lbl);
data::fill(card, 1);
// FIXME: Improve.
util::timer t2;
t2.start();
- bboxes_ima = internal::compute_bboxes_image(objects);
+ bboxes_ima = internal::compute_bboxes_image(components);
float t2_ = t2;
std::cout << "compute bboxes image " << t2_ << std::endl;
@@ -297,16 +302,15 @@ namespace scribo
// std::cout << to_keep << std::endl;
timer_.restart();
- object_image(L) output;
- if (kept == objects.nlabels())
+ if (kept == components.nelements())
{
trace::exiting("scribo::filter::objects_with_holes");
- return objects;
+ return components;
}
- output.init_from_(objects);
- output.relabel(to_keep);
+ component_set<L> output = components.duplicate();
+ output.update_tags(to_keep, component::Ignored);
t_ = timer_;
std::cout << "init output = " << t_ << std::endl;
@@ -320,43 +324,43 @@ namespace scribo
template <typename L>
inline
- object_image(L)
- objects_with_two_holes(const object_image(L)& objects,
- unsigned min_size)
+ component_set<L>
+ components_with_two_holes(const component_set<L>& components,
+ unsigned min_size)
{
trace::entering("scribo::filter::objects_with_holes");
- std::cout << objects.nlabels() << std::endl;
+ std::cout << components.nelements() << std::endl;
- typedef object_image(L) O;
+ typedef component_set<L> O;
neighb2d nbh = c8();
image2d<unsigned> parent, card;
L bboxes_ima;
util::array<unsigned> bg_comps(
- static_cast<unsigned>(objects.nlabels()) + 1, 0);
+ static_cast<unsigned>(components.nelements()) + 1, 0);
util::array<bool> bg_comps_done(
- static_cast<unsigned>(objects.nlabels()) + 1, false);
+ static_cast<unsigned>(components.nelements()) + 1, false);
fun::i2v::array<bool>
- to_keep(static_cast<unsigned>(objects.nlabels()) + 1,
+ to_keep(static_cast<unsigned>(components.nelements()) + 1,
false);
- const L& lbl = objects.labeled_image_();
+ const L& lbl = components.labeled_image();
// init
{
- extension::fill(objects, mln_max(mln_value(L)));
-// extension::adjust_fill(objects, nbh, mln_max(mln_value(L)));
- initialize(parent, objects);
+ extension::fill(lbl, mln_max(mln_value(L)));
+// extension::adjust_fill(components, nbh, mln_max(mln_value(L)));
+ initialize(parent, lbl);
data::fill(parent, 0u);
- initialize(card, objects);
+ initialize(card, lbl);
data::fill(card, 1);
border::fill(card, 1);
- bboxes_ima = internal::compute_bboxes_image(objects);
+ bboxes_ima = internal::compute_bboxes_image(components);
to_keep(0) = true;
}
@@ -421,7 +425,7 @@ namespace scribo
&& bboxes_ima.element(p) != literal::zero)
{
mln_value(L) object_id = bboxes_ima.element(p);
- if (!bg_comps_done(object_id))
+ if (!bg_comps_done(object_id) && components(object_id).is_valid())
{
if (bg_comps(object_id) == 0)
{
@@ -437,15 +441,15 @@ namespace scribo
}
}
- object_image(L) output;
- if (kept == objects.nlabels())
+ component_set<L> output;
+ if (kept == components.nelements())
{
trace::exiting("scribo::filter::objects_with_holes");
- return objects;
+ return components;
}
- output.init_from_(objects);
- output.relabel(to_keep);
+ output = components.duplicate();
+ output.update_tags(to_keep, component::Ignored);
trace::exiting("scribo::filter::objects_with_holes");
return output;
@@ -457,32 +461,32 @@ namespace scribo
// template <typename L>
// inline
-// object_image(L)
-// objects_with_holes(const object_image(L)& objects,
+// component_set<L>
+// objects_with_holes(const component_set<L>& components,
// unsigned min_holes_count)
// {
// trace::entering("scribo::filter::objects_with_holes");
-// mln_precondition(objects.is_valid());
+// mln_precondition(components.is_valid());
// L bboxes_ima;
-// initialize(bboxes_ima, objects);
+// initialize(bboxes_ima, components);
// data::fill(bboxes_ima, literal::zero);
-// for_all_components(i, objects.bboxes())
-// mln::draw::box(bboxes_ima, objects.bbox(i), i);
+// for_all_components(i, components.bboxes())
+// mln::draw::box(bboxes_ima, components.bbox(i), i);
// util::array<util::set<mln_value(L)> > first_bg_comp(
-// static_cast<unsigned>(objects.nlabels()) + 1);
+// static_cast<unsigned>(components.nlabels()) + 1);
// fun::i2v::array<bool>
-// to_keep(static_cast<unsigned>(objects.nlabels()) + 1,
+// to_keep(static_cast<unsigned>(components.nlabels()) + 1,
// false);
// to_keep(0) = true;
// mln_value(L) nbglabels;
-// L bg_lbl = labeling::background(objects, c8(), nbglabels);
+// L bg_lbl = labeling::background(components, c8(), nbglabels);
// unsigned kept;
// mln_piter(L) p(bboxes_ima.domain());
@@ -502,11 +506,11 @@ namespace scribo
// }
// }
-// object_image(L) output;
-// if (kept == objects.nlabels())
-// output = objects;
+// component_set<L> output;
+// if (kept == components.nlabels())
+// output = components;
// else
-// output = internal::compute(objects, to_keep);
+// output = internal::compute(components, to_keep);
// trace::exiting("scribo::filter::objects_with_holes");
// return output;
@@ -515,51 +519,52 @@ namespace scribo
template <typename L>
inline
- object_image(L)
- objects_with_holes_slow(const object_image(L)& objects,
+ component_set<L>
+ objects_with_holes_slow(const component_set<L>& components,
unsigned min_holes_count)
{
trace::entering("scribo::filter::objects_with_holes");
- mln_precondition(objects.is_valid());
+ mln_precondition(components.is_valid());
fun::i2v::array<bool>
- to_keep(static_cast<unsigned>(objects.nlabels()) + 1,
+ to_keep(static_cast<unsigned>(components.nlabels()) + 1,
true);
bool to_remove = false;
- for_all_components(i, objects.bboxes())
- {
- mln_domain(L) b = objects.bbox(i);
- b.enlarge(1);
-
- mln_ch_value(L, bool) tmp(b);
- data::fill(tmp, true);
- data::fill((tmp | ((objects | objects.bbox(i)) | (pw::value(objects) ==
pw::cst(i))).domain()).rw(), false);
-
- typedef accu::math::count<mln_value(L)> accu_t;
- mln_value(L) nlabels;
- util::array<unsigned> counts
- = labeling::blobs_and_compute(tmp,
- c8(), nlabels,
- accu_t()).second();
- unsigned nholes = 0;
- for_all_components(j, counts)
- if (counts(j) > 4u)
- ++nholes;
-
- if (nholes < min_holes_count)
+ for_all_components(i, components)
+ if (components(i).tag() != component::Ignored)
{
- to_keep(i) = false;
- to_remove = true;
+ mln_domain(L) b = components(i).bbox();
+ b.enlarge(1);
+
+ mln_ch_value(L, bool) tmp(b);
+ data::fill(tmp, true);
+ data::fill((tmp | ((components | components.bbox(i)) | (pw::value(components) ==
pw::cst(i))).domain()).rw(), false);
+
+ typedef accu::math::count<mln_value(L)> accu_t;
+ mln_value(L) nlabels;
+ util::array<unsigned> counts
+ = labeling::blobs_and_compute(tmp,
+ c8(), nlabels,
+ accu_t()).second();
+ unsigned nholes = 0;
+ for_all_components(j, counts)
+ if (counts(j) > 4u)
+ ++nholes;
+
+ if (nholes < min_holes_count)
+ {
+ to_keep(i) = false;
+ to_remove = true;
+ }
}
- }
- object_image(L) output;
+ component_set<L> output;
if (! to_remove)
- output = objects;
+ output = components;
else
- output = internal::compute(objects, to_keep);
+ output = internal::compute(components, to_keep);
trace::exiting("scribo::filter::objects_with_holes");
return output;
diff --git a/scribo/primitive/group/apply.hh b/scribo/primitive/group/apply.hh
index b074b82..26903fe 100644
--- a/scribo/primitive/group/apply.hh
+++ b/scribo/primitive/group/apply.hh
@@ -91,7 +91,7 @@ namespace scribo
mln_value(L) new_nlabels;
fun::i2v::array<mln_value(L)>
- packed_relabel_fun = mln::make::relabelfun(groups,
+ packed_relabel_fun = mln::make::relabelfun(groups.comp_to_group(),
components.nelements(),
new_nlabels);
new_nlabels = components.nelements();
diff --git a/scribo/primitive/group/from_double_link.hh
b/scribo/primitive/group/from_double_link.hh
index 8c15dc3..a1e8479 100644
--- a/scribo/primitive/group/from_double_link.hh
+++ b/scribo/primitive/group/from_double_link.hh
@@ -43,7 +43,7 @@
# include <scribo/core/macros.hh>
# include <scribo/core/object_groups.hh>
-# include <scribo/core/object_image.hh>
+# include <scribo/core/component_set.hh>
# include <scribo/primitive/internal/find_root.hh>
# include <scribo/primitive/internal/is_link_valid.hh>
# include <scribo/primitive/internal/init_link_array.hh>
@@ -58,11 +58,11 @@ namespace scribo
namespace group
{
- /*! Group objects from left and right links information and
+ /*! Group components from left and right links information and
validate These links. A link must exist in both ways to be
validated.
- \param[in] objects The Lines of text.
+ \param[in] components A component set.
\param[in] left_link The left neighbor of each line of text.
\param[in] right_link The right neighbor of each line of text.
\param[in] parent_link The function used to group components.
@@ -71,7 +71,7 @@ namespace scribo
*/
template <typename L>
object_groups<L>
- from_double_link(const object_image(L)& objects,
+ from_double_link(const component_set<L>& components,
const object_links<L>& left_link,
const object_links<L>& right_link);
@@ -83,19 +83,19 @@ namespace scribo
template <typename L>
inline
object_groups<L>
- from_double_link(const object_image(L)& objects,
+ from_double_link(const component_set<L>& components,
const object_links<L>& left_link,
const object_links<L>& right_link)
{
trace::entering("scribo::primitive::group::from_double_link");
mln_precondition(left_link.nelements() == right_link.nelements());
- mln_precondition(left_link.objects_id_() == objects.id_());
- mln_precondition(right_link.objects_id_() == objects.id_());
+ mln_precondition(left_link.components_id_() == components.id_());
+ mln_precondition(right_link.components_id_() == components.id_());
- object_groups<L> parent(objects, left_link.nelements());
+ object_groups<L> parent(components, left_link.nelements());
internal::init_link_array(parent);
- for_all_ncomponents(i, objects.nlabels())
+ for_all_ncomponents(i, components.nlabels())
{
mln::util::couple<bool, unsigned>
nbh = internal::is_link_valid(left_link, right_link, i);
diff --git a/scribo/primitive/group/from_single_link.hh
b/scribo/primitive/group/from_single_link.hh
index c369edb..128af6c 100644
--- a/scribo/primitive/group/from_single_link.hh
+++ b/scribo/primitive/group/from_single_link.hh
@@ -90,7 +90,10 @@ namespace scribo
parent_array.init_(link_array);
for_all_components(i, parent_array)
- primitive::internal::find_root(parent_array, i);
+ if (!components(i).is_valid())
+ parent_array(i) = 0;
+ else
+ primitive::internal::find_root(parent_array, i);
trace::exiting("scribo::primitive::group::from_single_link");
return parent_array;
diff --git a/scribo/primitive/link/internal/link_single_dmax_base.hh
b/scribo/primitive/link/internal/link_single_dmax_base.hh
index d4d9d29..b94da8e 100644
--- a/scribo/primitive/link/internal/link_single_dmax_base.hh
+++ b/scribo/primitive/link/internal/link_single_dmax_base.hh
@@ -39,7 +39,7 @@
# include <scribo/core/macros.hh>
# include <scribo/core/tag/anchor.hh>
-# include <scribo/core/object_image.hh>
+# include <scribo/core/component_set.hh>
# include <scribo/core/object_links.hh>
# include <scribo/primitive/link/internal/find_link.hh>
@@ -75,7 +75,7 @@ namespace scribo
typedef mln_site(L) P;
- link_single_dmax_base(const object_image(L)& objects,
+ link_single_dmax_base(const component_set<L>& components,
unsigned neighb_max_distance,
anchor::Direction direction);
@@ -101,11 +101,11 @@ namespace scribo
template <typename L, typename E>
inline
link_single_dmax_base<L, E>::link_single_dmax_base(
- const object_image(L)& objects,
+ const component_set<L>& components,
unsigned neighb_max_distance,
anchor::Direction direction)
- : super_(objects),
+ : super_(components),
dmax_(0),
neighb_max_distance_(neighb_max_distance),
direction_(direction)
@@ -134,7 +134,7 @@ namespace scribo
link_single_dmax_base<L, E>::start_point_(unsigned current_object,
anchor::Type anchor)
{
- return internal::compute_anchor(this->objects_,
+ return internal::compute_anchor(this->components_,
current_object, anchor);
}
@@ -146,8 +146,8 @@ namespace scribo
unsigned current_object)
{
float
- midcol = (this->objects_.bbox(current_object).pmax()[direction_]
- - this->objects_.bbox(current_object).pmin()[direction_]) / 2;
+ midcol = (this->components_.bbox(current_object).pmax()[direction_]
+ - this->components_.bbox(current_object).pmin()[direction_]) / 2;
dmax_ = midcol + neighb_max_distance_;
}
diff --git a/scribo/primitive/link/with_single_left_link.hh
b/scribo/primitive/link/with_single_left_link.hh
index 651f1f6..cc94f93 100644
--- a/scribo/primitive/link/with_single_left_link.hh
+++ b/scribo/primitive/link/with_single_left_link.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -28,7 +29,7 @@
/// \file
///
-/// Link text objects with their left neighbor.
+/// Link text components with their left neighbor.
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
@@ -43,7 +44,7 @@
# include <scribo/core/macros.hh>
-# include <scribo/core/object_image.hh>
+# include <scribo/core/component_set.hh>
# include <scribo/core/object_links.hh>
# include <scribo/primitive/link/internal/find_link.hh>
@@ -61,9 +62,9 @@ namespace scribo
namespace link
{
- /// \brief Link objects with their left neighbor if exists.
+ /// \brief Link components with their left neighbor if exists.
///
- /// \param[in] objects An object image.
+ /// \param[in] components A component set.
/// \param[in] The maximum distance allowed to seach a neighbor object.
///
/// \return Object links data.
@@ -71,7 +72,7 @@ namespace scribo
template <typename L>
inline
object_links<L>
- with_single_left_link(const object_image(L)& objects,
+ with_single_left_link(const component_set<L>& components,
unsigned neighb_max_distance);
@@ -80,7 +81,7 @@ namespace scribo
template <typename L>
inline
object_links<L>
- with_single_left_link(const object_image(L)& objects);
+ with_single_left_link(const component_set<L>& components);
# ifndef MLN_INCLUDE_ONLY
@@ -101,8 +102,8 @@ namespace scribo
public:
typedef mln_site(L) P;
- single_left_functor(const object_image(L)& objects, unsigned dmax)
- : super_(objects, dmax, anchor::Horizontal)
+ single_left_functor(const component_set<L>& components, unsigned dmax)
+ : super_(components, dmax, anchor::Horizontal)
{
}
@@ -122,15 +123,15 @@ namespace scribo
template <typename L>
inline
object_links<L>
- with_single_left_link(const object_image(L)& objects,
- unsigned neighb_max_distance)
+ with_single_left_link(const component_set<L>& components,
+ unsigned neighb_max_distance)
{
trace::entering("scribo::primitive::link::with_single_left_link");
- mln_precondition(objects.is_valid());
+ mln_precondition(components.is_valid());
internal::single_left_functor<L>
- functor(objects, neighb_max_distance);
+ functor(components, neighb_max_distance);
object_links<L> output = compute(functor);
@@ -142,9 +143,9 @@ namespace scribo
template <typename L>
inline
object_links<L>
- with_single_left_link(const object_image(L)& objects)
+ with_single_left_link(const component_set<L>& components)
{
- return with_single_left_link(objects, mln_max(unsigned));
+ return with_single_left_link(components, mln_max(unsigned));
}
diff --git a/scribo/primitive/link/with_single_right_link.hh
b/scribo/primitive/link/with_single_right_link.hh
index 22380ab..e1abdcf 100644
--- a/scribo/primitive/link/with_single_right_link.hh
+++ b/scribo/primitive/link/with_single_right_link.hh
@@ -41,7 +41,7 @@
# include <scribo/core/macros.hh>
# include <scribo/core/tag/anchor.hh>
-# include <scribo/core/object_image.hh>
+# include <scribo/core/component_set.hh>
# include <scribo/core/object_links.hh>
# include <scribo/primitive/link/internal/find_link.hh>
@@ -59,10 +59,10 @@ namespace scribo
namespace link
{
- /// \brief Link objects with their right neighbor if exists.
+ /// \brief Link components with their right neighbor if exists.
/// Lookup startup point is the object mass center.
///
- /// \param[in] objects An object image.
+ /// \param[in] components An object image.
/// \param[in] The maximum distance allowed to seach a neighbor object.
///
/// \return Object links data.
@@ -70,7 +70,7 @@ namespace scribo
template <typename L>
inline
object_links<L>
- with_single_right_link(const object_image(L)& objects,
+ with_single_right_link(const component_set<L>& components,
unsigned neighb_max_distance);
@@ -79,7 +79,7 @@ namespace scribo
template <typename L>
inline
object_links<L>
- with_single_right_link(const object_image(L)& objects);
+ with_single_right_link(const component_set<L>& components);
@@ -101,8 +101,8 @@ namespace scribo
public:
typedef mln_site(L) P;
- single_right_functor(const object_image(L)& objects, unsigned dmax)
- : super_(objects, dmax, anchor::Horizontal)
+ single_right_functor(const component_set<L>& components, unsigned dmax)
+ : super_(components, dmax, anchor::Horizontal)
{
}
@@ -122,15 +122,15 @@ namespace scribo
template <typename L>
inline
object_links<L>
- with_single_right_link(const object_image(L)& objects,
+ with_single_right_link(const component_set<L>& components,
unsigned neighb_max_distance)
{
trace::entering("scribo::primitive::link::with_single_right_link");
- mln_precondition(objects.is_valid());
+ mln_precondition(components.is_valid());
internal::single_right_functor<L>
- functor(objects, neighb_max_distance);
+ functor(components, neighb_max_distance);
object_links<L> output = compute(functor, anchor::MassCenter);
@@ -142,9 +142,9 @@ namespace scribo
template <typename L>
inline
object_links<L>
- with_single_right_link(const object_image(L)& objects)
+ with_single_right_link(const component_set<L>& components)
{
- return with_single_right_link(objects, mln_max(unsigned));
+ return with_single_right_link(components, mln_max(unsigned));
}
diff --git a/scribo/src/afp/link.hh b/scribo/src/afp/link.hh
index b899957..66115d0 100644
--- a/scribo/src/afp/link.hh
+++ b/scribo/src/afp/link.hh
@@ -1,7 +1,7 @@
#include <mln/geom/ncols.hh>
#include <mln/geom/nrows.hh>
#include <mln/util/couple.hh>
-#include <scribo/core/object_image.hh>
+#include <scribo/core/component_set.hh>
#include <scribo/core/macros.hh>
#include <scribo/primitive/internal/init_link_array.hh>
@@ -17,33 +17,35 @@ namespace scribo
template <typename L>
util::couple<object_links<L>, object_links<L> >
- left_right(const object_image(L)& objects)
+ left_right(const component_set<L>& components)
{
object_links<L>
- right(objects, static_cast<unsigned>(objects.nlabels()) + 1);
+ right(components, static_cast<unsigned>(components.nelements()) + 1);
primitive::internal::init_link_array(right);
object_links<L>
- left(objects, static_cast<unsigned>(objects.nlabels()) + 1);
+ left(components, static_cast<unsigned>(components.nelements()) + 1);
primitive::internal::init_link_array(left);
- for_all_components(i, objects.bboxes())
+ const L& lbl_ima = components.labeled_image();
+
+ for_all_comps(i, components)
{
float
- w = (objects.bbox(i).pmax().col()
- - objects.bbox(i).pmin().col()),
- h = (objects.bbox(i).pmax().row()
- - objects.bbox(i).pmin().row());
+ w = (components(i).bbox().pmax().col()
+ - components(i).bbox().pmin().col()),
+ h = (components(i).bbox().pmax().row()
+ - components(i).bbox().pmin().row());
unsigned dmax = (w / 2.0f) + (3 * math::max(w, h));
- const mln_site(L) c = objects.mass_center(i);
+ const mln_site(L) c = components(i).mass_center();
int
- midcol = (objects.bbox(i).pmax().col()
- - objects.bbox(i).pmin().col()) / 2;
+ midcol = (components(i).bbox().pmax().col()
+ - components(i).bbox().pmin().col()) / 2;
int
- nrightima = geom::ncols(objects) - c.col(),
+ nrightima = geom::ncols(lbl_ima) - c.col(),
nleftima = c.col(),
nright = std::min(static_cast<unsigned>(nrightima), midcol + dmax),
nleft = std::min(static_cast<unsigned>(nleftima), midcol + dmax);
@@ -51,7 +53,7 @@ namespace scribo
// Right
{
const mln_value(L)
- *p = &objects(c),
+ *p = &lbl_ima(c),
*pstop = p + nright + 1;
for (; p != pstop; ++p)
@@ -70,7 +72,7 @@ namespace scribo
// Left
{
const mln_value(L)
- *p = &objects(c),
+ *p = &lbl_ima(c),
*pstop = p - nleft - 1;
for (; p != pstop; --p)
@@ -92,19 +94,21 @@ namespace scribo
template <typename L>
object_links<L>
- left(const object_image(L)& objects, unsigned dmax)
+ left(const component_set<L>& components, unsigned dmax)
{
object_links<L>
- left(objects, static_cast<unsigned>(objects.nlabels()) + 1);
+ left(components, static_cast<unsigned>(components.nelements()) + 1);
primitive::internal::init_link_array(left);
- for_all_components(i, objects.bboxes())
+ const L& lbl_ima = components.labeled_image();
+
+ for_all_comps(i, components)
{
- const mln_site(L) c = objects.mass_center(i);
+ const mln_site(L) c = components(i).mass_center();
int
- midcol = (objects.bbox(i).pmax().col()
- - objects.bbox(i).pmin().col()) / 2;
+ midcol = (components(i).bbox().pmax().col()
+ - components(i).bbox().pmin().col()) / 2;
int
nleftima = c.col(),
nleft = std::min(static_cast<unsigned>(nleftima), midcol + dmax);
@@ -112,7 +116,7 @@ namespace scribo
// Left
{
const mln_value(L)
- *p = &objects(c),
+ *p = &lbl_ima(c),
*pstop = p - nleft - 1;
for (; p != pstop; --p)
diff --git a/scribo/src/afp/regroup.hh b/scribo/src/afp/regroup.hh
index c24880b..2de36b9 100644
--- a/scribo/src/afp/regroup.hh
+++ b/scribo/src/afp/regroup.hh
@@ -1,7 +1,7 @@
#include <mln/geom/ncols.hh>
#include <mln/geom/nrows.hh>
#include <mln/util/couple.hh>
-#include <scribo/core/object_image.hh>
+#include <scribo/core/component_set.hh>
#include <scribo/core/macros.hh>
#include <scribo/primitive/internal/init_link_array.hh>
@@ -16,7 +16,7 @@ namespace scribo
template <typename L>
object_groups<L>
- regroup_left(const object_image(L)& objects,
+ regroup_left(const component_set<L>& components,
const object_groups<L>& groups,
unsigned dmax)
{
@@ -25,10 +25,10 @@ namespace scribo
mln_precondition(groups.is_valid());
object_groups<L>
- new_groups(objects, static_cast<unsigned>(objects.nlabels()) + 1, 0);
+ new_groups(components, static_cast<unsigned>(components.nlabels()) + 1, 0);
unsigned ngroups = 0;
- for_all_components(i, objects.bboxes())
+ for_all_components(i, components.bboxes())
{
if (groups[i] == 0)
continue;
@@ -38,19 +38,19 @@ namespace scribo
if (new_groups[i] == 0)
new_groups[i] = ++ngroups;
- const mln_site(L) c = objects.mass_center(i);
+ const mln_site(L) c = components.mass_center(i);
int
- midcol = (objects.bbox(i).pmax().col()
- - objects.bbox(i).pmin().col()) / 2;
+ midcol = (components.bbox(i).pmax().col()
+ - components.bbox(i).pmin().col()) / 2;
int
- nleftima = geom::ncols(objects),
+ nleftima = geom::ncols(components),
nleft = std::min(static_cast<unsigned>(nleftima), midcol + dmax);
// Left
{
const mln_value(L)
- *p = &objects(c),
+ *p = &components(c),
*pstop = p - nleft - 1;
for (; p != pstop; --p)
diff --git a/scribo/text/recognition.hh b/scribo/text/recognition.hh
index 9b81e53..c4dd6e2 100644
--- a/scribo/text/recognition.hh
+++ b/scribo/text/recognition.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -70,6 +71,11 @@
#include <mln/labeling/colorize.hh>
+
+#include <mln/debug/filename.hh>
+#include <mln/io/pbm/save.hh>
+
+
namespace scribo
{
@@ -80,7 +86,7 @@ namespace scribo
/// Passes the text bboxes to Tesseract (OCR).
///
- /// \param[in] text The lines of text.
+ /// \param[in] lines The lines of text.
/// \param[in] language The language which should be recognized by
/// Tesseract. (fra, en, ...)
/// \param[in] output_file If set, store the recognized text in
@@ -88,7 +94,7 @@ namespace scribo
//
template <typename L>
void
- recognition(const object_image(L)& objects,
+ recognition(const line_set<L>& lines,
const char *language,
const char *output_file);
@@ -96,16 +102,18 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
+ unsigned debug_id = 0;
+
template <typename L>
void
- recognition(const object_image(L)& objects,
+ recognition(const line_set<L>& lines,
const char *language,
const char *output_file)
{
trace::entering("scribo::text::recognition");
- mln_precondition(objects.is_valid());
+ mln_precondition(lines.is_valid());
// Initialize Tesseract.
TessBaseAPI::InitWithLanguage(NULL, NULL, language, NULL, false, 0, NULL);
@@ -123,12 +131,15 @@ namespace scribo
file.open(output_file);
/// Use text bboxes with Tesseract
- for_all_ncomponents(i, objects.nlabels())
+ for_all_lines(i, lines)
{
+ if (! lines(i).is_valid())
+ continue;
+
std::cout << "Text recognition... ("
- << i << "/" << objects.nlabels() << ")"
<< std::endl;
+ << i << "/" << lines.nelements() << ")"
<< std::endl;
- mln_domain(I) box = objects.bbox(i);
+ mln_domain(I) box = lines(i).bbox();
// Make sure characters are isolated from the borders.
// Help Tesseract.
box.enlarge(2);
@@ -137,13 +148,22 @@ namespace scribo
data::fill(text_ima, true);
// Careful : background is set to 'False'
- data::fill((text_ima | (pw::value(objects) == pw::cst(i))).rw(),
- false);
+ const component_set<L>& comp_set = lines.component_set_();
+ const L& lbl = comp_set.labeled_image();
+
+ const mln::util::array<component_id_t>& comps = lines(i).components();
+ for_all_elements(e, lines(i).components())
+ {
+ unsigned comp_id = comps(e);
+ data::fill(((text_ima | comp_set(comp_id).bbox()).rw() | (pw::value(lbl) ==
pw::cst(comp_id))).rw(),
+ false);
+ }
/// Improve text quality.
/// text_ima_cleaned domain is larger than text_ima's.
I text_ima_cleaned = text::clean(text_ima, dmap_win);
+ mln::io::pbm::save(text_ima_cleaned, mln::debug::filename("line.pbm",
debug_id++));
// Setting objects to 'True'
logical::not_inplace(text_ima_cleaned);
@@ -163,14 +183,14 @@ namespace scribo
- mln_site(L) p = objects.bbox(i).center();
- p.col() -= (objects.bbox(i).pmax().col()
- - objects.bbox(i).pmin().col()) / 2;
+ mln_site(L) p = lines(i).bbox().pcenter();
+ p.col() -= (lines(i).bbox().pmax().col()
+ - lines(i).bbox().pmin().col()) / 2;
if (s != 0)
{
std::cerr << s << std::endl;
if (output_file != 0)
- file << s << std::endl;
+ file << lines(i).bbox() << " " << s << std::endl;
}
// The string has been allocated by Tesseract. We must free it.
--
1.5.6.5