Commit f97abc33 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Small fixes in Scribo.

	* debug/decision_image.hh: Fix precondition.

	* filter/object_links_bbox_h_ratio.hh,
	* filter/objects_thick.hh,
	* primitive/internal/have_link_valid.hh,
	* primitive/internal/is_link_valid.hh: Fix doc.

	* filter/object_links_bbox_ratio.hh: Fix doc and invert ratio.

	* filter/object_links_bottom_aligned.hh: Fix doc and use a float
	angle value.

	* filter/object_links_non_aligned.hh: Use absolute values.

	* filter/object_links_non_aligned_simple.hh: Add special cases.

	* filter/object_links_non_h_aligned.hh: Fix call to an underlying
	routine.

	* filter/objects_small.hh,
	* filter/objects_thin.hh,
	* filter/objects_v_thin.hh,
	* primitive/extract/lines_discontinued.hh,
	* primitive/extract/lines_h_single.hh,
	* primitive/extract/lines_h_thick_and_single.hh,
	* primitive/extract/lines_thick.hh,
	* primitive/extract/lines_v_discontinued.hh,
	* primitive/extract/lines_v_single.hh,
	* primitive/extract/lines_v_thick_and_single.hh,
	* primitive/internal/is_invalid_link.hh,
	* src/multi_scale/find_lines.cc,
	* src/primitive/group/group_from_rag.cc,
	* src/table/rebuild_opening.cc,
	* src/table/rebuild_rank.cc,
	* text/clean.hh: Avoid warnings.

	* primitive/internal/find_left_link.hh,
	* primitive/internal/find_right_link.hh,
	* primitive/internal/update_link_array.hh: Make the routine return
	a value.

	* src/binarization/sauvola.cc,
	* src/binarization/sauvola_pgm.cc: Fix call to Sauvola's algorithm.

	* src/primitive/group/group_from_graph.cc,
	* src/primitive/group/group_from_several_graph.cc: Change
	arguments values while calling with_several_graphes.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@4704 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 52c28129
......@@ -104,7 +104,7 @@ namespace scribo
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());
mln_precondition(groups.objects_id_() != filtered_groups.objects_id_());
/// Fixme: check that objects has been computed from input.
image2d<value::rgb8>
......
......@@ -28,8 +28,10 @@
/// \file
///
/// Invalidate links between two objects with too different height or
/// width.
/// Invalidate links between two objects with too different height.
///
/// \todo rename to object_links_bbox_v_ratio (v for vertical) to be
/// consistent with other routine names.
# include <mln/util/array.hh>
......@@ -52,7 +54,7 @@ namespace scribo
\param[in] objects An object image.
\param[in] links Link objects information.
\param[in] min_h_ratio The minimum height ratio of two linked
\param[in] max_h_ratio The maximum height ratio of two linked
bounding boxes.
\result A filtered object link information.
......@@ -61,7 +63,7 @@ namespace scribo
object_links<L>
object_links_bbox_h_ratio(const object_image(L)& objects,
const object_links<L>& links,
float min_h_ratio);
float max_h_ratio);
# ifndef MLN_INCLUDE_ONLY
......@@ -71,7 +73,7 @@ namespace scribo
object_links<L>
object_links_bbox_h_ratio(const object_image(L)& objects,
const object_links<L>& links,
float min_h_ratio)
float max_h_ratio)
{
trace::entering("scribo::filter::object_links_bbox_h_ratio");
......@@ -79,7 +81,7 @@ namespace scribo
mln_precondition(links.is_valid());
object_links<L>
output = object_links_bbox_ratio(objects, links, 0, min_h_ratio);
output = object_links_bbox_ratio(objects, links, 0, max_h_ratio);
trace::exiting("scribo::filter::object_links_bbox_h_ratio");
return output;
......
......@@ -52,7 +52,7 @@ namespace scribo
\param[in] objects An object image.
\param[in] links Link objects information.
\param[in] dim The dimension to use to compare bbox length.
\param[in] min_ratio The minimum length ratio of two linked
\param[in] max_ratio The maximum length ratio of two linked
bounding boxes.
\result A filtered object link information.
......@@ -62,7 +62,7 @@ namespace scribo
object_links_bbox_ratio(const object_image(L)& objects,
const object_links<L>& links,
unsigned dim,
float min_ratio);
float max_ratio);
# ifndef MLN_INCLUDE_ONLY
......@@ -73,7 +73,7 @@ namespace scribo
object_links_bbox_ratio(const object_image(L)& objects,
const object_links<L>& links,
unsigned dim,
float min_ratio)
float max_ratio)
{
trace::entering("scribo::filter::object_links_bbox_ratio");
......@@ -82,18 +82,19 @@ namespace scribo
object_links<L> output(links);
for (unsigned i = 1; i < links.size(); ++i)
{
float
lmin = objects.bbox(i).pmax()[dim] - objects.bbox(i).pmin()[dim],
lmax = objects.bbox(links(i)).pmax()[dim]
- objects.bbox(links(i)).pmin()[dim];
if (lmin > lmax)
std::swap(lmin, lmax);
if (lmin / lmax < min_ratio)
output(i) = i;
}
if (links[i] != i)
{
float
lmin = objects.bbox(i).pmax()[dim] - objects.bbox(i).pmin()[dim],
lmax = objects.bbox(links(i)).pmax()[dim]
- objects.bbox(links(i)).pmin()[dim];
if (lmin > lmax)
std::swap(lmin, lmax);
if ((lmax/ lmin) > max_ratio)
output(i) = i;
}
trace::exiting("scribo::filter::object_links_bbox_ratio");
return output;
......
......@@ -53,31 +53,37 @@ namespace scribo
\param[in] objects An object image.
\param[in] links Object links information.
\param[in] dim Choose the dimension on which applying the
filter.
\param[in] max_delta Maximum delta.
\param[in] max_alpha Maximum angle value (degrees).
\verbatim
------
| |
------ | |
| | | |
| x------------x |
| | | | v
------ ~ ~ ~ |~ ~ | ~ ~ ~
object1 | | | => delta, must be < to max_delta
------ ~ ~ ~
object2 ^
| | | |
------~ ~ ~ ~| ~ ~| ~ ~
object1 ~ | | ^
~ | | |
~------ |
object2 | Alpha
~ |
~ |
~ |
~ v
~
\endverbatim
The angle between the two bottoms must be lower than \p max_alpha.
*/
template <typename L>
object_links<L>
object_links_bottom_aligned(const object_image(L)& objects,
const object_links<L>& links,
unsigned max_delta);
float max_alpha);
# ifndef MLN_INCLUDE_ONLY
......@@ -87,7 +93,7 @@ namespace scribo
object_links<L>
object_links_bottom_aligned(const object_image(L)& objects,
const object_links<L>& links,
unsigned max_delta)
float max_alpha)
{
trace::entering("scribo::filter::object_links_bottom_aligned");
......@@ -96,8 +102,7 @@ namespace scribo
object_links<L>
output = object_links_non_aligned_simple(objects, links,
1, 1,
max_delta);
1, max_alpha);
trace::exiting("scribo::filter::object_links_bottom_aligned");
return output;
......@@ -112,4 +117,4 @@ namespace scribo
} // end of namespace scribo
#endif // ! SCRIBO_FILTER_OBJECT_LINKS_NON_ALIGNED_SIMPLE_HH
#endif // ! SCRIBO_FILTER_OBJECT_LINKS_BOTTOM_ALIGNED_HH
......@@ -31,6 +31,7 @@
/// Invalidate links between two non aligned objects.
# include <mln/math/abs.hh>
# include <mln/util/array.hh>
# include <scribo/core/macros.hh>
......@@ -115,9 +116,10 @@ namespace scribo
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)
if (static_cast<unsigned>(math::abs((bboxes[hmin].pmin()[dim] - bboxes[hmax].pmin()[dim]))) > max_delta
|| static_cast<unsigned>(math::abs((bboxes[hmin].pmax()[dim] - bboxes[hmax].pmax()[dim]))) > max_delta)
output[i] = i;
}
trace::exiting("scribo::filter::object_links_non_aligned");
......
......@@ -32,6 +32,8 @@
# include <mln/util/array.hh>
# include <mln/math/abs.hh>
# include <mln/math/pi.hh>
# include <scribo/core/macros.hh>
# include <scribo/core/object_links.hh>
......@@ -50,9 +52,7 @@ namespace scribo
\param[in] objects An object image.
\param[in] links Object links information.
\param[in] dim Choose the dimension on which applying the
filter.
\param[in] max_delta Maximum delta.
\param[in] max_alpha Maximum angle value (degrees).
Exemple with dim == 1 and edge == 1 (bottom
......@@ -65,22 +65,33 @@ namespace scribo
------ | |
| | | |
| x------------x |
| | | | v
------ ~ ~ ~ |~ ~ | ~ ~ ~
object1 | | | => delta, must be < to max_delta
------ ~ ~ ~
object2 ^
| | | |
------~ ~ ~ ~| ~ ~| ~ ~
object1 ~ | | ^
~ | | |
~------ |
object2 | Alpha
~ |
~ |
~ |
~ v
~
\endverbatim
The angle between the two bottoms must be lower than \p alpha.
edge values :
0 = top
1 = bottom
2 = center
*/
template <typename L>
object_links<L>
object_links_non_aligned_simple(const object_image(L)& objects,
const object_links<L>& links,
unsigned dim,
unsigned edge,
unsigned max_delta);
float max_alpha);
# ifndef MLN_INCLUDE_ONLY
......@@ -90,9 +101,8 @@ namespace scribo
object_links<L>
object_links_non_aligned_simple(const object_image(L)& objects,
const object_links<L>& links,
unsigned dim,
unsigned edge,
unsigned max_delta)
float max_alpha)
{
trace::entering("scribo::filter::object_links_non_aligned_simple");
......@@ -102,34 +112,59 @@ namespace scribo
typedef typename object_image(L)::bbox_t bbox_t;
const mln::util::array<bbox_t>& bboxes = objects.bboxes();
object_links<L> output(links);
unsigned delta;
float dr, dc;
float max_alpha_rad = (max_alpha / 180.0f) * math::pi;
// Top
if (edge == 0)
{
for_all_components(i, objects.bboxes())
if (links[i] != i)
{
delta = bboxes[i].pmin()[dim] - bboxes[i].pmin()[dim];
dr = math::abs(bboxes[i].pmin().row()
- bboxes[links[i]].pmin().row());
dc = math::abs(bboxes[i].center().col()
- bboxes[links[i]].center().col());
if (delta > max_delta)
if (std::atan(dr / dc) > max_alpha_rad)
output[i] = i;
}
}
// Bottom
else if (edge == 1)
for_all_components(i, objects.bboxes())
{
if (links[i] != i)
{
delta = bboxes[i].pmax()[dim] - bboxes[i].pmax()[dim];
dr = math::abs(bboxes[i].pmax().row()
- bboxes[links[i]].pmax().row());
dc = math::abs(bboxes[i].center().col()
- bboxes[links[i]].center().col());
if (std::atan(dr / dc) > max_alpha_rad)
output[i] = i;
}
}
// Center
else if (edge == 2)
for_all_components(i, objects.bboxes())
{
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());
if (delta > max_delta)
if (std::atan(dr / dc) > max_alpha_rad)
output[i] = i;
}
}
else
{
trace::warning("Invalid edge value...");
trace::warning("Invalid edge value... Aborting computation.");
trace::exiting("scribo::filter::object_links_non_aligned_simple");
return output;
}
......
......@@ -76,7 +76,7 @@ namespace scribo
object_links<L>
object_links_non_h_aligned(const object_image(L)& objects,
const object_links<L>& links,
float ratio);
float max_delta);
# ifndef MLN_INCLUDE_ONLY
......@@ -85,14 +85,14 @@ namespace scribo
object_links<L>
object_links_non_h_aligned(const object_image(L)& objects,
const object_links<L>& links,
float ratio)
float max_delta)
{
trace::entering("scribo::filter::object_links_non_h_aligned");
mln_precondition(objects.is_valid());
object_links<L>
output = object_links_non_aligned(objects, links, 1, ratio);
output = object_links_non_aligned(objects, links, 0, max_delta);
trace::exiting("scribo::filter::object_links_non_h_aligned");
return output;
......
......@@ -34,6 +34,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/concept/function.hh>
# include <mln/core/image/dmorph/image_if.hh>
# include <mln/labeling/blobs.hh>
# include <mln/labeling/relabel.hh>
......@@ -110,6 +111,7 @@ namespace scribo
mln_precondition(input.is_valid());
mln_precondition(nbh.is_valid());
(void) label_type;
V nlabels;
typedef mln_ch_value(I,V) lbl_t;
......@@ -120,7 +122,7 @@ namespace scribo
lbl.relabel(fv2b);
mln_concrete(I) output = duplicate(input);
data::fill((output | pw::value(lbl) == pw::cst(literal::zero)).rw(),
data::fill((output | (pw::value(lbl) == pw::cst(literal::zero))).rw(),
false);
trace::exiting("scribo::filter::objects_small");
......
......@@ -66,7 +66,7 @@ namespace scribo
unsigned max_thickness);
/// Remove lines of text thicker or equal to \p max_thickness.
/// Remove objects thicker or equal to \p max_thickness.
///
/// \param[in] objects An object image.
/// \param[in] max_thickness The maximum thickness value.
......
......@@ -32,6 +32,8 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/image/dmorph/image_if.hh>
# include <mln/pw/all.hh>
# include <mln/util/array.hh>
......@@ -140,6 +142,7 @@ namespace scribo
mln_precondition(input.is_valid());
mln_precondition(nbh.is_valid());
(void) label_type;
V nlabels;
typedef mln_ch_value(I,V) lbl_t;
......@@ -151,7 +154,7 @@ namespace scribo
objects.relabel(fv2b);
mln_concrete(I) output = duplicate(input);
data::fill((output | pw::value(objects) == pw::cst(literal::zero)).rw(),
data::fill((output | (pw::value(objects) == pw::cst(literal::zero))).rw(),
false);
trace::exiting("scribo::filter::objects_thin");
......
......@@ -137,6 +137,7 @@ namespace scribo
{
trace::entering("scribo::filter::objects_v_thin");
(void) label_type;
const I& input = exact(input_);
const N& nbh = exact(nbh_);
......@@ -153,7 +154,7 @@ namespace scribo
objects.relabel(fv2b);
mln_concrete(I) output = duplicate(input);
data::fill((output | pw::value(objects) == pw::cst(literal::zero)).rw(),
data::fill((output | (pw::value(objects) == pw::cst(literal::zero))).rw(),
false);
trace::exiting("scribo::filter::objects_v_thin");
......
......@@ -98,6 +98,9 @@ namespace scribo
mln_precondition(exact(nbh).is_valid());
mln_precondition(exact(win).is_valid());
(void) input;
(void) nbh;
(void) win;
(void) nlines;
(void) rank_k;
}
......
......@@ -108,8 +108,8 @@ namespace scribo
is_line_h_single(const object_image(L)& objects,
float w_h_ratio, unsigned min_line_length)
: objects_(objects),
w_h_ratio_(w_h_ratio), min_line_length_(min_line_length)
: w_h_ratio_(w_h_ratio), min_line_length_(min_line_length),
objects_(objects)
{
}
......
......@@ -104,6 +104,10 @@ namespace scribo
mln_precondition(exact(input).is_valid());
mln_precondition(exact(nbh).is_valid());
(void) input;
(void) nbh;
(void) min_line_length;
(void) h_w_ratio;
(void) nlines;
}
......
......@@ -93,6 +93,9 @@ namespace scribo
mln_precondition(exact(nbh).is_valid());
mln_precondition(exact(win).is_valid());
(void) input;
(void) nbh;
(void) win;
(void) nlines;
}
......
......@@ -87,6 +87,9 @@ namespace scribo
mln_precondition(exact(nbh).is_valid());
mln_precondition(line_length % 2);
(void) input;
(void) nbh;
(void) line_length;
(void) nlines;
(void) rank_k;
}
......
......@@ -107,8 +107,8 @@ namespace scribo
is_line_v_single(const object_image(L)& objects,
float h_w_ratio, unsigned min_line_length)
: objects_(objects),
h_w_ratio_(h_w_ratio), min_line_length_(min_line_length)
: h_w_ratio_(h_w_ratio), min_line_length_(min_line_length),
objects_(objects)
{
}
......
......@@ -103,6 +103,10 @@ namespace scribo
mln_precondition(exact(input).is_valid());
mln_precondition(exact(nbh).is_valid());
(void) input;
(void) nbh;
(void) min_line_length;
(void) h_w_ratio;
(void) nlines;
}
......
......@@ -29,12 +29,15 @@
/// \file
///
/// Find the left neighbor of a line of text if exists.
///
/// \todo To be deleted.
# include <mln/core/concept/image.hh>
# include <mln/math/abs.hh>
# include <mln/util/array.hh>
# include <mln/util/couple.hh>
# include <scribo/core/object_image.hh>
# include <scribo/primitive/internal/update_link_array.hh>
......@@ -61,22 +64,22 @@ namespace scribo
/// \param c The lookup start point.
//
template <typename L>
void
mln::util::couple<bool, mln_site(L)>
find_left_link(const object_image(L)& objects,
mln::util::array<unsigned>& left_link,
unsigned current_comp,
int dmax,
float dmax,
const mln_site(L)& c);
# ifndef MLN_INCLUDE_ONLY
template <typename L>
void
mln::util::couple<bool, mln_site(L)>
find_left_link(const object_image(L)& objects,
mln::util::array<unsigned>& left_link,
unsigned current_comp,
int dmax,
float dmax,
const mln_site(L)& c)
{
///FIXME: the following code is not generic...
......@@ -87,7 +90,10 @@ namespace scribo
current_comp, c, dmax))
--p.col();
update_link_array(objects, left_link, p, c, current_comp, dmax);
bool
b = update_link_array(objects, left_link, p, c, current_comp, dmax);
return mln::make::couple(b, p);
}
# endif // MLN_INCLUDE_ONLY
......
......@@ -29,12 +29,15 @@
/// \file
///
/// Find the right neighbor of a line of text if exists.
///
/// \todo To be deleted.
# include <mln/core/concept/image.hh>
# include <mln/math/abs.hh>
# include <mln/util/array.hh>
# include <mln/util/couple.hh>
# include <scribo/core/object_image.hh>
# include <scribo/primitive/internal/update_link_array.hh>
......@@ -61,25 +64,25 @@ namespace scribo
/// \param c The lookup start point.
//
template <typename L>
void
mln::util::couple<bool, mln_site(L)>