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

Small fixes in Scribo.

	* binarization/sauvola_ms.hh,
	* binarization/sauvola_threshold_image_debug.hh: Update prototypes.

	* primitive/internal/rd.hh,
	* primitive/group/apply.hh,
	* debug/save_bboxes_image.hh: Add missing mln:: namespace prefix.

	* filter/objects_large.hh: Split into a routine and a functor.

	* fun/v2b/objects_large_filter.hh: New.

	* io/xml/save_text_lines.hh: Save line type.

	* table/internal/repair_lines.hh,
	* table/internal/align_lines.hh,
	* make/text.hh: Update macro name.

	* core/erase_objects.hh,
	* primitive/extract/lines_discontinued.hh,
	* primitive/extract/lines_h_discontinued.hh,
	* primitive/extract/lines_h_pattern.hh,
	* primitive/extract/lines_h_single.hh,
	* primitive/extract/lines_h_thick.hh,
	* primitive/extract/lines_thick.hh,
	* primitive/extract/lines_v_discontinued.hh,
	* primitive/extract/lines_v_single.hh,
	* primitive/extract/lines_v_thick.hh,
	* primitive/group/from_graph.hh,
	* primitive/internal/find_graph_link.hh,
	* primitive/link/with_graph.hh,
	* primitive/link/with_several_graphes.hh,
	* primitive/link/with_several_left_links.hh,
	* primitive/link/with_several_right_links.hh,
	* table/erase.hh,
	* table/extract.hh: Remove any references to object_image.

	* table/internal/connect_lines.hh: use
	influence_zone_geodesic_saturated

	* filter/objects_small.hh: Duplicate component set.

	* primitive/internal/all.hh,
	* primitive/extract/all.hh,
	* filter/all.hh,
	* core/all.hh: Remove non existing includes.

	* core/macros.hh: New macro.

	* core/line_info.hh: Fix stats.

	* filter/object_links_non_aligned.hh,
	* filter/object_links_non_h_aligned.hh,
	* filter/object_links_non_v_aligned.hh: Removed.
parent b826d415
2010-04-30 Guillaume Lazzara <z@lrde.epita.fr>
Small fixes in Scribo.
* binarization/sauvola_ms.hh,
* binarization/sauvola_threshold_image_debug.hh: Update prototypes.
* primitive/internal/rd.hh,
* primitive/group/apply.hh,
* debug/save_bboxes_image.hh: Add missing mln:: namespace prefix.
* filter/objects_large.hh: Split into a routine and a functor.
* fun/v2b/objects_large_filter.hh: New.
* io/xml/save_text_lines.hh: Save line type.
* table/internal/repair_lines.hh,
* table/internal/align_lines.hh,
* make/text.hh: Update macro name.
* core/erase_objects.hh,
* primitive/extract/lines_discontinued.hh,
* primitive/extract/lines_h_discontinued.hh,
* primitive/extract/lines_h_pattern.hh,
* primitive/extract/lines_h_single.hh,
* primitive/extract/lines_h_thick.hh,
* primitive/extract/lines_thick.hh,
* primitive/extract/lines_v_discontinued.hh,
* primitive/extract/lines_v_single.hh,
* primitive/extract/lines_v_thick.hh,
* primitive/group/from_graph.hh,
* primitive/internal/find_graph_link.hh,
* primitive/link/with_graph.hh,
* primitive/link/with_several_graphes.hh,
* primitive/link/with_several_left_links.hh,
* primitive/link/with_several_right_links.hh,
* table/erase.hh,
* table/extract.hh: Remove any references to object_image.
* table/internal/connect_lines.hh: use
influence_zone_geodesic_saturated
* filter/objects_small.hh: Duplicate component set.
* primitive/internal/all.hh,
* primitive/extract/all.hh,
* filter/all.hh,
* core/all.hh: Remove non existing includes.
* core/macros.hh: New macro.
* core/line_info.hh: Fix stats.
* filter/object_links_non_aligned.hh,
* filter/object_links_non_h_aligned.hh,
* filter/object_links_non_v_aligned.hh: Removed.
2010-03-19 Guillaume Lazzara <z@lrde.epita.fr>
Improve dematerialization wizard.
......
......@@ -94,16 +94,14 @@ namespace scribo
*/
template <typename I>
mln_ch_value(I,bool)
sauvola_ms(const Image<I>& input_1_, unsigned w_1,
unsigned s, unsigned lambda_min_1, double K);
sauvola_ms(const Image<I>& input_1_, unsigned w_1, unsigned s, double K);
/// \overload
/// K is set to 0.34.
//
template <typename I>
mln_ch_value(I,bool)
sauvola_ms(const Image<I>& input_1, unsigned w_1,
unsigned s, unsigned lambda_min_1);
sauvola_ms(const Image<I>& input_1, unsigned w_1, unsigned s);
......
......@@ -123,10 +123,10 @@ namespace scribo
\return A threshold.
*/
template <typename P, typename I, typename J>
template <typename P, typename M, typename J>
double
compute_sauvola_threshold(const P& p,
I& mean, I& stddev,
M& mean, M& stddev,
const J& simple,
const J& squared,
int win_width, double K, double R)
......@@ -156,7 +156,7 @@ namespace scribo
double m_x_y = m_x_y_tmp / wh;
mean(p) = m_x_y * mean_debug_factor;
mean(p) = m_x_y;// * mean_debug_factor;
// Standard deviation.
double s_x_y_tmp = (squared.at_(row_max, col_max)
......@@ -166,7 +166,7 @@ namespace scribo
double s_x_y = std::sqrt((s_x_y_tmp - (m_x_y_tmp * m_x_y_tmp) / wh) / (wh - 1.f));
stddev(p) = s_x_y * stddev_debug_factor;
stddev(p) = s_x_y;// * stddev_debug_factor;
// Thresholding.
double t_x_y = sauvola_threshold_formula(m_x_y, s_x_y, K, R);
......@@ -198,21 +198,21 @@ namespace scribo
namespace generic
{
template <typename I, typename J>
template <typename I, typename M, typename J>
inline
mln_concrete(I)
sauvola_threshold_image_debug(const Image<I>& input_,
unsigned window_size,
double K,
Image<I>& mean_, Image<I>& stddev_,
Image<M>& mean_, Image<M>& stddev_,
Image<J>& simple_,
Image<J>& squared_)
{
trace::entering("scribo::binarization::impl::generic::sauvola_threshold_image_debug");
const I& input = exact(input_);
I& mean = exact(mean_);
I& stddev = exact(stddev_);
M& mean = exact(mean_);
M& stddev = exact(stddev_);
J& simple = exact(simple_);
J& squared = exact(squared_);
......@@ -248,13 +248,13 @@ namespace scribo
template <typename I, typename J>
template <typename I, typename M, typename J>
inline
mln_concrete(I)
sauvola_threshold_image_debug_gl(const Image<I>& input,
unsigned window_size,
double K,
Image<I>& mean, Image<I>& stddev,
Image<M>& mean, Image<M>& stddev,
Image<J>& simple,
Image<J>& squared)
{
......@@ -265,13 +265,13 @@ namespace scribo
}
template <typename I, typename J>
template <typename I, typename M, typename J>
inline
mln_ch_value(I, value::int_u8)
sauvola_threshold_image_debug_rgb8(const Image<I>& input,
unsigned window_size,
double K,
Image<I>& mean, Image<I>& stddev,
Image<M>& mean, Image<M>& stddev,
Image<J>& simple,
Image<J>& squared)
{
......@@ -302,14 +302,14 @@ namespace scribo
namespace internal
{
template <unsigned n, typename I, typename J>
template <unsigned n, typename I, typename M, typename J>
inline
mln_ch_value(I, value::int_u<n>)
sauvola_threshold_image_debug_dispatch(const value::int_u<n>&,
const I& input,
unsigned window_size,
double K,
I& mean, I& stddev,
M& mean, M& stddev,
J& simple,
J& squared)
{
......@@ -318,13 +318,13 @@ namespace scribo
simple, squared);
}
template <typename I, typename J>
template <typename I, typename M, typename J>
inline
mln_ch_value(I, value::int_u8)
sauvola_threshold_image_debug_dispatch(const value::rgb8&, const I& input,
unsigned window_size,
double K,
I& mean, I& stddev,
M& mean, M& stddev,
J& simple,
J& squared)
{
......@@ -333,11 +333,11 @@ namespace scribo
simple, squared);
}
template <typename I, typename J>
template <typename I, typename M, typename J>
inline
mln_ch_value(I, value::int_u8)
sauvola_threshold_image_debug_dispatch(const mln_value(I)&, const I& input,
I& mean, I& stddev,
M& mean, M& stddev,
unsigned window_size,
double K,
J& simple,
......@@ -355,11 +355,11 @@ namespace scribo
template <typename I, typename J>
template <typename I, typename M, typename J>
mln_ch_value(I, value::int_u8)
sauvola_threshold_image_debug(const Image<I>& input, unsigned window_size,
double K,
Image<I>& mean, Image<I>& stddev,
Image<M>& mean, Image<M>& stddev,
Image<J>& simple,
Image<J>& squared)
{
......@@ -384,12 +384,12 @@ namespace scribo
}
template <typename I>
template <typename I, typename M>
inline
mln_ch_value(I, value::int_u8)
sauvola_threshold_image_debug(const Image<I>& input, unsigned window_size,
double K,
Image<I>& mean, Image<I>& stddev)
Image<M>& mean, Image<M>& stddev)
{
mln_ch_value(I, double)
simple = init_integral_image(input, scribo::internal::identity_),
......
// 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.
//
......@@ -44,6 +45,5 @@ namespace scribo
#include <scribo/core/central_sites.hh>
#include <scribo/core/erase_objects.hh>
#include <scribo/core/macros.hh>
#include <scribo/core/object_image.hh>
#endif // ! SCRIBO_CORE_ALL_HH
......@@ -32,12 +32,11 @@
# include <mln/core/concept/image.hh>
# include <mln/core/site_set/box.hh>
# include <mln/data/paste.hh>
# include <mln/data/fill.hh>
# include <mln/pw/all.hh>
# include <mln/util/array.hh>
# include <scribo/core/macros.hh>
# include <scribo/core/object_image.hh>
namespace scribo
{
......@@ -47,14 +46,13 @@ namespace scribo
/// Remove labeled components from a binary image.
///
/// \param[in,out] input_ A binary image.
/// \param[in] objects An object image. Objects will be set to
/// false in \p input_.
/// \param[in] objects An image of objects (object value must be
/// different from 0).
///
//
template <typename I, typename L>
void
erase_objects(Image<I>& input_,
const object_image(L)& objects);
erase_objects(Image<I>& input, const Image<L>& objects);
# ifndef MLN_INCLUDE_ONLY
......@@ -63,13 +61,14 @@ namespace scribo
template <typename I, typename L>
void
erase_objects(Image<I>& input_,
const object_image(L)& objects)
const Image<L>& objects_)
{
trace::entering("scribo::erase_objects");
mlc_equal(mln_value(I),bool)::check();
I& input = exact(input_);
I& objects = exact(objects_);
mln_precondition(input.is_valid());
mln_precondition(objects.is_valid());
......
......@@ -795,7 +795,7 @@ namespace scribo
// Space between characters.
int space = bb.pmin().col()
- comp_set(holder_.links()(c)).bbox().pmax().col();
- comp_set(holder_.links()(c)).bbox().pmax().col() + 1;
// -- Ignore overlapped characters.
if (space > 0)
......
......@@ -52,6 +52,9 @@
# define for_all_lines(E, S) \
for_all_comps(E, S)
# define for_all_line_comps(E, S) \
for_all_elements(E, S)
# define for_all_lines_info(E, S) \
for_all_comp_data(E, S)
......
......@@ -35,6 +35,7 @@
# include <mln/value/rgb8.hh>
# include <mln/util/array.hh>
# include <mln/io/ppm/save.hh>
# include <mln/literal/colors.hh>
# include <scribo/core/line_set.hh>
# include <scribo/draw/bounding_boxes.hh>
......@@ -108,13 +109,14 @@ namespace scribo
trace::entering("scribo::debug::save_bboxes_image");
mln_precondition(exact(input).is_valid());
image2d<value::rgb8> output = data::convert(value::rgb8(), input);
mln_ch_value(I, value::rgb8)
output = data::convert(value::rgb8(), input);
for_all_lines(l, lines)
if (! lines(l).hidden())
mln::draw::box(output, lines(l).bbox(), value);
io::ppm::save(output, filename);
mln::io::ppm::save(output, filename);
trace::exiting("scribo::debug::save_bboxes_image");
}
......
......@@ -42,9 +42,6 @@ namespace scribo
} // end of namespace scribo
# include <scribo/filter/object_groups_small.hh>
# include <scribo/filter/object_links_non_aligned.hh>
# include <scribo/filter/object_links_non_h_aligned.hh>
# include <scribo/filter/object_links_non_v_aligned.hh>
# include <scribo/filter/objects_large.hh>
# include <scribo/filter/objects_small.hh>
# include <scribo/filter/objects_thick.hh>
......
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
#ifndef SCRIBO_FILTER_OBJECT_LINKS_NON_ALIGNED_HH
# define SCRIBO_FILTER_OBJECT_LINKS_NON_ALIGNED_HH
/// \file
///
/// Invalidate links between two non aligned objects.
# include <mln/math/abs.hh>
# include <mln/util/array.hh>
# include <scribo/core/macros.hh>
# include <scribo/core/object_links.hh>
# include <scribo/core/object_image.hh>
namespace scribo
{
namespace filter
{
using namespace mln;
/*! \brief Invalidate links between two non aligned objects.
Alignment is based on object bounding boxes.
\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.
Exemple with dim == 1 (horizontal filter):
\verbatim
v
------ ~ ~ ~
| | |\
------ ~ ~ ~ |~ ~ | ~ ~ ~ \
| | | | ^ \
| x------------x | => delta, must be < to max_delta
| | | | v /
------ ~ ~ ~ |~ ~ | ~ ~ ~ /
object1 | | |/
------ ~ ~ ~
object2 ^
\endverbatim
*/
template <typename L>
object_links<L>
object_links_non_aligned(const object_image(L)& objects,
const object_links<L>& links,
unsigned dim,
unsigned max_delta);
# ifndef MLN_INCLUDE_ONLY
template <typename L>
object_links<L>
object_links_non_aligned(const object_image(L)& objects,
const object_links<L>& links,
unsigned dim,
unsigned max_delta)
{
trace::entering("scribo::filter::object_links_non_aligned");
mln_precondition(objects.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);
for_all_components(i, objects.bboxes())
if (links[i] != 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 (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");
return output;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::filter
} // end of namespace scribo
#endif // ! SCRIBO_FILTER_OBJECT_LINKS_NON_ALIGNED_HH
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
#ifndef SCRIBO_FILTER_OBJECT_LINKS_NON_H_ALIGNED_HH
# define SCRIBO_FILTER_OBJECT_LINKS_NON_H_ALIGNED_HH
/// \file
///
/// Invalidate links between two non horizontaly aligned objects.
# include <mln/util/array.hh>
# include <scribo/core/object_links.hh>
# include <scribo/core/object_image.hh>
# include <scribo/filter/object_links_non_aligned.hh>
namespace scribo
{
namespace filter
{
using namespace mln;
/*! \brief Invalidate links between two non horizontaly aligned objects.
Alignment is based on object bounding boxes.
\param[in] objects An object image.
\param[in] links Object links information.
\param[in] max_delta Maximum delta.
\result Filtered object links data.
\verbatim
v
------ ~ ~ ~
| | |\
------ ~ ~ ~ |~ ~ | ~ ~ ~ \
| | | | ^ \
| x- - - - - --x | => delta, must be < to max_delta
| | | | v /
------ ~ ~ ~ |~ ~ | ~ ~ ~ /
object1 | | |/
------ ~ ~ ~
object2 ^
\endverbatim
*/
template <typename L>
object_links<L>
object_links_non_h_aligned(const object_image(L)& objects,
const object_links<L>& links,
float max_delta);
# ifndef MLN_INCLUDE_ONLY
template <typename L>
object_links<L>
object_links_non_h_aligned(const object_image(L)& objects,
const object_links<L>& links,
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, 0, max_delta);
trace::exiting("scribo::filter::object_links_non_h_aligned");
return output;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::filter
} // end of namespace scribo
#endif // ! SCRIBO_FILTER_OBJECT_LINKS_NON_H_ALIGNED_HH
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
// (LRDE)
//