* core/object_links.hh,
* core/object_groups.hh: Add default constructor and is_valid
member.
* debug/save_linked_bboxes_image.hh,
* draw/bounding_box_links.hh: Update arguments type.
* draw/bounding_boxes.hh: Add a new overload.
* filter/object_groups_small.hh: Make it return an object_groups.
* filter/object_links_non_aligned.hh: Do not do anything if a box
does not have any link.
* src/table/erase.cc: Add comments.
---
scribo/ChangeLog | 20 ++++++++++
scribo/core/object_groups.hh | 15 ++++++++
scribo/core/object_links.hh | 16 ++++++++
scribo/debug/save_linked_bboxes_image.hh | 22 ++++++------
scribo/draw/bounding_box_links.hh | 56 ++++++++++++++--------------
scribo/draw/bounding_boxes.hh | 19 ++++++++++
scribo/filter/object_groups_small.hh | 28 ++++++++-------
scribo/filter/object_links_non_aligned.hh | 32 ++++++++--------
scribo/src/table/erase.cc | 2 +
9 files changed, 142 insertions(+), 68 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 5dc8c5e..1a26e66 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,25 @@
2009-08-28 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Small fixes in Scribo.
+
+ * core/object_links.hh,
+ * core/object_groups.hh: Add default constructor and is_valid
+ member.
+
+ * debug/save_linked_bboxes_image.hh,
+ * draw/bounding_box_links.hh: Update arguments type.
+
+ * draw/bounding_boxes.hh: Add a new overload.
+
+ * filter/object_groups_small.hh: Make it return an object_groups.
+
+ * filter/object_links_non_aligned.hh: Do not do anything if a box
+ does not have any link.
+
+ * src/table/erase.cc: Add comments.
+
+2009-08-28 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add Sauvola's binarization.
* binarization/sauvola.hh: New routine.
diff --git a/scribo/core/object_groups.hh b/scribo/core/object_groups.hh
index 3e49942..15e2004 100644
--- a/scribo/core/object_groups.hh
+++ b/scribo/core/object_groups.hh
@@ -52,6 +52,7 @@ namespace scribo
typedef mln::util::array<unsigned> super_t;
public:
+ object_groups();
object_groups(const object_image(L)& objects);
object_groups(const object_image(L)& objects, unsigned n);
object_groups(const object_image(L)& objects, unsigned n, unsigned value);
@@ -61,6 +62,8 @@ namespace scribo
void init_(const object_links<L>& links);
+ bool is_valid() const;
+
private:
object_image(L) objects_;
};
@@ -69,6 +72,11 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
template <typename L>
+ object_groups<L>::object_groups()
+ {
+ }
+
+ template <typename L>
object_groups<L>::object_groups(const object_image(L)& objects)
: objects_(objects)
{
@@ -115,6 +123,13 @@ namespace scribo
this->hook_std_vector_() = links.std_vector();
}
+ template <typename L>
+ bool
+ object_groups<L>::is_valid() const
+ {
+ return objects_.is_valid() && objects_.nlabels() == (this->size() - 1);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/core/object_links.hh b/scribo/core/object_links.hh
index aa70bf8..1c020dd 100644
--- a/scribo/core/object_links.hh
+++ b/scribo/core/object_links.hh
@@ -51,6 +51,7 @@ namespace scribo
typedef mln::util::array<unsigned> super_t;
public:
+ object_links();
object_links(const object_image(L)& objects);
object_links(const object_image(L)& objects, unsigned n);
object_links(const object_image(L)& objects, unsigned n, unsigned value);
@@ -59,6 +60,8 @@ namespace scribo
const void* objects_id_() const;
const object_image(L)& object_image_() const;
+ bool is_valid() const;
+
private:
object_image(L) objects_;
};
@@ -67,6 +70,11 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
template <typename L>
+ object_links<L>::object_links()
+ {
+ }
+
+ template <typename L>
object_links<L>::object_links(const object_image(L)& objects)
: objects_(objects)
{
@@ -105,6 +113,14 @@ namespace scribo
}
+ template <typename L>
+ bool
+ object_links<L>::is_valid() const
+ {
+ return objects_.is_valid() && objects_.nlabels() == (this->size() - 1);
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/debug/save_linked_bboxes_image.hh
b/scribo/debug/save_linked_bboxes_image.hh
index ed35622..6ce0ad0 100644
--- a/scribo/debug/save_linked_bboxes_image.hh
+++ b/scribo/debug/save_linked_bboxes_image.hh
@@ -65,7 +65,7 @@ namespace scribo
void
save_linked_bboxes_image(const Image<I>& input,
const object_image(L)& objects,
- const mln::util::array<unsigned>& link_array,
+ const object_links<L>& array,
const value::rgb8& box_value,
const value::rgb8& link_value,
const std::string& filename);
@@ -83,8 +83,8 @@ namespace scribo
void
save_linked_bboxes_image(const Image<I>& input,
const object_image(L)& objects,
- const mln::util::array<unsigned>& left_link,
- const mln::util::array<unsigned>& right_link,
+ 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);
@@ -106,8 +106,8 @@ namespace scribo
void
save_linked_bboxes_image(const Image<I>& input,
const object_image(L)& objects,
- const mln::util::array<unsigned>& left_link,
- const mln::util::array<unsigned>& right_link,
+ const object_links<L>& left_link,
+ const object_links<L>& right_link,
const value::rgb8& box_value,
const value::rgb8& left_link_value,
const value::rgb8& right_link_value,
@@ -141,7 +141,7 @@ namespace scribo
void
save_linked_bboxes_image(const Image<I>& input,
const object_image(L)& objects,
- const mln::util::array<unsigned>& link_array,
+ const object_links<L>& array,
const value::rgb8& box_value,
const value::rgb8& link_value,
const std::string& filename)
@@ -157,7 +157,7 @@ namespace scribo
objects.nlabels());
draw::bounding_boxes(tmp, objects.bboxes(), box_value);
- draw::bounding_box_links(tmp, mass_center, link_array, link_value);
+ draw::bounding_box_links(tmp, mass_center, array, link_value);
io::ppm::save(tmp, filename);
@@ -170,8 +170,8 @@ namespace scribo
void
save_linked_bboxes_image(const Image<I>& input,
const object_image(L)& objects,
- const mln::util::array<unsigned>& left_link,
- const mln::util::array<unsigned>& right_link,
+ const object_links<L>& left_link,
+ const object_links<L>& right_link,
const value::rgb8& box_value,
const value::rgb8& value,
const std::string& filename)
@@ -202,8 +202,8 @@ namespace scribo
void
save_linked_bboxes_image(const Image<I>& input,
const object_image(L)& objects,
- const mln::util::array<unsigned>& left_link,
- const mln::util::array<unsigned>& right_link,
+ const object_links<L>& left_link,
+ const object_links<L>& right_link,
const value::rgb8& box_value,
const value::rgb8& left_link_value,
const value::rgb8& right_link_value,
diff --git a/scribo/draw/bounding_box_links.hh b/scribo/draw/bounding_box_links.hh
index 15e7260..9a2919e 100644
--- a/scribo/draw/bounding_box_links.hh
+++ b/scribo/draw/bounding_box_links.hh
@@ -51,13 +51,13 @@ namespace scribo
///
/// \param[in,out] input_ An image where to draw.
/// \param[in] bboxes Bounding boxes.
- /// \param[in] link_array Bounding box links.
+ /// \param[in] links Bounding box links.
/// \param[in] value Value used to draw links.
- template <typename I>
+ template <typename I, typename L>
void
bounding_box_links(Image<I>& input_,
const mln::util::array< box<mln_site(I)> >& bboxes,
- const mln::util::array<unsigned>& link_array,
+ const object_links<L>& link,
const mln_value(I)& value);
@@ -65,14 +65,14 @@ namespace scribo
///
/// \param[in,out] input_ An image where to draw.
/// \param[in] mass_centers Bounding boxes mass centers.
- /// \param[in] link_array Bounding box links.
+ /// \param[in] links Bounding box links.
/// \param[in] value Value used to draw links.
- template <typename I>
+ template <typename I, typename L>
inline
void
bounding_box_links(Image<I>& input_,
const mln::util::array<mln_site(I)::vec>& mass_centers,
- const mln::util::array<unsigned>& link_array,
+ const object_links<L>& link,
const mln_value(I)& value);
@@ -86,13 +86,13 @@ namespace scribo
/// \param[in] left_link_value Value used to draw left links.
/// \param[in] right_link_value Value used to draw right links.
/// \param[in] validated_link_value Value used to draw validated links.
- template <typename I>
+ template <typename I, typename L>
inline
void
bounding_box_links(Image<I>& input_,
const mln::util::array< box<mln_site(I)> >& bboxes,
- const mln::util::array<unsigned>& left_link,
- const mln::util::array<unsigned>& right_link,
+ const object_links<L>& left_link,
+ const object_links<L>& right_link,
const mln_value(I)& left_link_value,
const mln_value(I)& right_link_value,
const mln_value(I)& validated_link_value);
@@ -108,13 +108,13 @@ namespace scribo
/// \param[in] left_link_value Value used to draw left links.
/// \param[in] right_link_value Value used to draw right links.
/// \param[in] validated_link_value Value used to draw validated links.
- template <typename I>
+ template <typename I, typename L>
inline
void
bounding_box_links(Image<I>& input_,
const mln::util::array<mln_site(I)::vec>& mass_centers,
- const mln::util::array<unsigned>& left_link,
- const mln::util::array<unsigned>& right_link,
+ const object_links<L>& left_link,
+ const object_links<L>& right_link,
const mln_value(I)& left_link_value,
const mln_value(I)& right_link_value,
const mln_value(I)& validated_link_value);
@@ -231,12 +231,12 @@ namespace scribo
} // end of namespace scribo::draw::internal
- template <typename I>
+ template <typename I, typename L>
inline
void
bounding_box_links(Image<I>& input_,
const mln::util::array< box<mln_site(I)> >& bboxes,
- const mln::util::array<unsigned>& link_array,
+ const object_links<L>& links,
const mln_value(I)& value)
{
trace::entering("scribo::draw::bounding_box_links");
@@ -245,22 +245,22 @@ namespace scribo
mln_precondition(input.is_valid());
- for_all_components(i, link_array)
- if (link_array[i] != i)
+ for_all_components(i, links)
+ if (links[i] != i)
mln::draw::line(input,
bboxes[i].center(),
- bboxes[link_array[i]].center(),
+ bboxes[links[i]].center(),
value);
trace::exiting("scribo::draw::bounding_box_links");
}
- template <typename I>
+ template <typename I, typename L>
inline
void
bounding_box_links(Image<I>& input_,
const mln::util::array<mln_site(I)::vec>& mass_centers,
- const mln::util::array<unsigned>& link_array,
+ const object_links<L>& links,
const mln_value(I)& value)
{
trace::entering("scribo::draw::bounding_box_links");
@@ -269,12 +269,12 @@ namespace scribo
mln_precondition(input.is_valid());
- for_all_components(i, link_array)
+ for_all_components(i, links)
{
- if (link_array[i] != i)
+ if (links[i] != i)
mln::draw::line(input,
mass_centers[i],
- mass_centers[link_array[i]],
+ mass_centers[links[i]],
value);
input(mass_centers[i]) = value;
}
@@ -283,13 +283,13 @@ namespace scribo
}
- template <typename I>
+ template <typename I, typename L>
inline
void
bounding_box_links(Image<I>& input_,
const mln::util::array<mln_site(I)::vec>& mass_centers,
- const mln::util::array<unsigned>& left_link,
- const mln::util::array<unsigned>& right_link,
+ const object_links<L>& left_link,
+ const object_links<L>& right_link,
const mln_value(I)& left_link_value,
const mln_value(I)& right_link_value,
const mln_value(I)& validated_link_value)
@@ -338,13 +338,13 @@ namespace scribo
trace::exiting("scribo::draw::bounding_box_links");
}
- template <typename I>
+ template <typename I, typename L>
inline
void
bounding_box_links(Image<I>& input_,
const mln::util::array< box<mln_site(I)> >& bboxes,
- const mln::util::array<unsigned>& left_link,
- const mln::util::array<unsigned>& right_link,
+ const object_links<L>& left_link,
+ const object_links<L>& right_link,
const mln_value(I)& left_link_value,
const mln_value(I)& right_link_value,
const mln_value(I)& validated_link_value)
diff --git a/scribo/draw/bounding_boxes.hh b/scribo/draw/bounding_boxes.hh
index 6cbc6d9..2fe2cd3 100644
--- a/scribo/draw/bounding_boxes.hh
+++ b/scribo/draw/bounding_boxes.hh
@@ -35,6 +35,7 @@
# include <mln/util/array.hh>
# include <scribo/core/macros.hh>
+# include <scribo/core/object_image.hh>
namespace scribo
{
@@ -52,6 +53,13 @@ namespace scribo
const mln_value(I)& value);
+ /// Draw object bounding boxes and their associated mass center.
+ template <typename I, typename L>
+ void
+ bounding_boxes(Image<I>& input_,
+ const object_image(L)& objects,
+ const mln_value(I)& value);
+
# ifndef MLN_INCLUDE_ONLY
@@ -80,6 +88,17 @@ namespace scribo
}
+ template <typename I, typename L>
+ inline
+ void
+ bounding_boxes(Image<I>& input,
+ const object_image(L)& objects,
+ const mln_value(I)& value)
+ {
+ bounding_boxes(input, objects.bboxes(), value);
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::draw
diff --git a/scribo/filter/object_groups_small.hh b/scribo/filter/object_groups_small.hh
index fdfec6a..1e6c636 100644
--- a/scribo/filter/object_groups_small.hh
+++ b/scribo/filter/object_groups_small.hh
@@ -50,12 +50,11 @@ namespace scribo
\param[in] groups Information about object groups.
\param[in] n_links The minimum number of links per group.
- \return A function mapping an object id to a bool. It is set to
- true if an object is part of a group with more than \p n_links
- links.
+ \return A copy of object group in which small groups have been
+ removed.
*/
template <typename L>
- mln::util::array<bool>
+ object_groups<L>
object_groups_small(const object_groups<L>& groups,
unsigned n_links);
@@ -65,21 +64,24 @@ namespace scribo
template <typename L>
inline
- mln::util::array<bool>
- object_groups_small(const object_groups<L>& parent_link,
+ object_groups<L>
+ object_groups_small(const object_groups<L>& groups,
unsigned n_links)
{
+ mln_precondition(groups.is_valid());
+
// Counting the number of objects per group.
- mln::util::array<unsigned> group_size(parent_link.size(), 0);
+ mln::util::array<unsigned> group_size(groups.size(), 0);
for (unsigned i = 1; i < group_size.size(); ++i)
- ++group_size[parent_link[i]];
+ ++group_size[groups[i]];
- mln::util::array<bool> f(parent_link.size());
- f(0) = true;
- for (unsigned i = 1; i < f.size(); ++i)
- f(i) = (group_size[parent_link[i]] >= n_links);
+ object_groups<L> output(groups);
+ output(0) = 0;
+ for (unsigned i = 1; i < output.size(); ++i)
+ if (group_size[groups[i]] < n_links)
+ output(i) = 0;
- return f;
+ return output;
}
diff --git a/scribo/filter/object_links_non_aligned.hh
b/scribo/filter/object_links_non_aligned.hh
index 46a425e..5d7e99a 100644
--- a/scribo/filter/object_links_non_aligned.hh
+++ b/scribo/filter/object_links_non_aligned.hh
@@ -101,25 +101,25 @@ namespace scribo
object_links<L> output(links);
for_all_components(i, objects.bboxes())
- {
-
- unsigned
- lnbh = bboxes(links[i]).pmax()[dim] - bboxes(links[i]).pmin()[dim],
- lcurrent = bboxes(i).pmax()[dim] - bboxes(i).pmin()[dim],
- hmin = i,
- hmax = links[i];
-
- if (lnbh < lcurrent)
+ if (links[i] != i)
{
- hmin = links[i];
- hmax = i;
+ unsigned
+ lnbh = bboxes(links[i]).pmax()[dim] - bboxes(links[i]).pmin()[dim],
+ lcurrent = bboxes(i).pmax()[dim] - bboxes(i).pmin()[dim],
+ hmin = i,
+ hmax = links[i];
+
+ if (lnbh < lcurrent)
+ {
+ hmin = links[i];
+ hmax = i;
+ }
+
+ if ((bboxes[hmin].pmin()[dim] - (float)bboxes[hmax].pmin()[dim]) > max_delta
+ || (bboxes[hmin].pmax()[dim] - (float) bboxes[hmax].pmax()[dim]) > max_delta)
+ output[i] = i;
}
- if ((bboxes[hmin].pmin()[dim] - (float)bboxes[hmax].pmin()[dim]) > max_delta
- || (bboxes[hmin].pmax()[dim] - (float) bboxes[hmax].pmax()[dim]) > max_delta)
- output[i] = i;
- }
-
trace::exiting("scribo::filter::object_links_non_aligned");
return output;
}
diff --git a/scribo/src/table/erase.cc b/scribo/src/table/erase.cc
index 671296a..29546bb 100644
--- a/scribo/src/table/erase.cc
+++ b/scribo/src/table/erase.cc
@@ -68,6 +68,7 @@ int main(int argc, char* argv[])
typedef image2d<label_16> lbl_t;
+ /// Extracting vertical and horizontal lines.
label_16 nhlines, nvlines;
object_image(lbl_t)
lbl_v = primitive::extract::lines_v_discontinued(input, c8(),
@@ -76,6 +77,7 @@ int main(int argc, char* argv[])
lbl_h = primitive::extract::lines_h_discontinued(input, c8(),
nhlines, 51, 6);
+ /// Reconstruct and erase tables.
image2d<bool> input_notables
= scribo::table::erase(input, lbl_h, lbl_v);
--
1.5.6.5