Commit 6b43c063 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Add new routines in Scribo.

	* debug/highlight_text_area.hh,
	* debug/save_bboxes_image.hh: Add a new overload.

	* debug/save_comp_diff.hh,
	* debug/text_areas_image.hh,
	* primitive/regroup/from_single_left_link_wrt_h_ratio.hh: New.
parent 52112930
2010-08-09 Guillaume Lazzara <z@lrde.epita.fr>
Add new routines in Scribo.
* debug/highlight_text_area.hh,
* debug/save_bboxes_image.hh: Add a new overload.
* debug/save_comp_diff.hh,
* debug/text_areas_image.hh,
* primitive/regroup/from_single_left_link_wrt_h_ratio.hh: New.
2010-08-09 Guillaume Lazzara <z@lrde.epita.fr> 2010-08-09 Guillaume Lazzara <z@lrde.epita.fr>
Remove deprecated files. Remove deprecated files.
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
# include <scribo/core/component_set.hh> # include <scribo/core/component_set.hh>
# include <scribo/core/line_set.hh> # include <scribo/core/line_set.hh>
# include <mln/geom/rotate.hh>
namespace scribo namespace scribo
{ {
...@@ -244,6 +245,55 @@ namespace scribo ...@@ -244,6 +245,55 @@ namespace scribo
} }
template <typename I, typename L>
mln_ch_value(I, value::rgb8)
highlight_text_area_rotated(const Image<I>& input_,
const scribo::component_set<L>& components,
double angle, box2d rb)
{
trace::entering("scribo::debug::highlight_text_area");
const I& input = exact(input_);
mln_precondition(input.is_valid());
mlc_is(mln_value(I), value::rgb8)::check();
typedef mln_ch_value(I, bool) mask_t;
mask_t mask;
initialize(mask, input);
data::fill(mask, false);
mln::util::array<mln_box(I)> bbox(unsigned(components.nelements()) + 1);
for_all_comps(i, components)
if (components(i).is_valid())
{
bbox(i) = components(i).bbox();
bbox(i).pmin().row() += rb.pmin().row();
bbox(i).pmin().col() += rb.pmin().col();
bbox(i).pmax().row() += rb.pmin().row();
bbox(i).pmax().col() += rb.pmin().col();
bbox(i) = mln::geom::rotate(bbox(i), - angle,
input.domain().pcenter());
}
for_all_comps(i, components)
if (components(i).is_valid())
data::fill((mask | bbox(i)).rw(), true);
internal::mask_non_text<mask_t, mln_value(I)> f(mask);
mln_ch_value(I, value::rgb8) output = data::transform(input, f);
for_all_comps(i, components)
if (components(i).is_valid())
mln::draw::box(output, bbox(i), literal::red);
trace::exiting("scribo::debug::highlight_text_area");
return output;
}
# endif // ! MLN_INCLUDE_ONLY # endif // ! MLN_INCLUDE_ONLY
......
// 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. // This file is part of Olena.
// //
...@@ -76,6 +77,14 @@ namespace scribo ...@@ -76,6 +77,14 @@ namespace scribo
const line_set<L>& lines, const line_set<L>& lines,
const std::string& filename); const std::string& filename);
/// \overload.
template <typename I, typename L>
inline
void
save_bboxes_image(const Image<I>& input,
const component_set<L>& comps,
const std::string& filename,
const value::rgb8& value);
# ifndef MLN_INCLUDE_ONLY # ifndef MLN_INCLUDE_ONLY
...@@ -132,6 +141,29 @@ namespace scribo ...@@ -132,6 +141,29 @@ namespace scribo
} }
template <typename I, typename L>
inline
void
save_bboxes_image(const Image<I>& input,
const component_set<L>& comps,
const std::string& filename,
const value::rgb8& value)
{
trace::entering("scribo::debug::save_bboxes_image");
mln_precondition(exact(input).is_valid());
mln_ch_value(I, value::rgb8)
output = data::convert(value::rgb8(), input);
for_all_comps(c, comps)
if (comps(c).is_valid())
mln::draw::box(output, comps(c).bbox(), value);
mln::io::ppm::save(output, filename);
trace::exiting("scribo::debug::save_bboxes_image");
}
# endif // ! MLN_INCLUDE_ONLY # endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::debug } // end of namespace scribo::debug
......
// Copyright (C) 2009, 2010 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_DEBUG_SAVE_COMP_DIFF_HH
# define SCRIBO_DEBUG_SAVE_COMP_DIFF_HH
/// \file
///
/// Show the difference between two object images.
# include <mln/core/image/image2d.hh>
# include <mln/core/concept/image.hh>
# include <mln/data/fill.hh>
# include <mln/labeling/colorize.hh>
# include <mln/value/rgb8.hh>
# include <mln/io/ppm/save.hh>
# include <mln/literal/black.hh>
# include <mln/literal/colors.hh>
# include <mln/pw/all.hh>
# include <mln/core/image/dmorph/image_if.hh>
# include <scribo/core/macros.hh>
# include <scribo/core/component_set.hh>
namespace scribo
{
namespace debug
{
using namespace mln;
/*! \brief Show the difference between two object images.
\param[in] lbl A component set.
\param[in] lbl_2 Another component set.
\param[in] filename The output filename.
*/
template <typename L, typename L2>
void
save_comp_diff(const component_set<L>& cset_1,
const component_set<L2>& cset_2,
const std::string& filename);
# ifndef MLN_INCLUDE_ONLY
template <typename L, typename L2>
void
save_comp_diff(const component_set<L>& cset_1,
const component_set<L2>& cset_2,
const std::string& filename)
{
trace::entering("scribo::debug::save_comp_diff");
image2d<value::rgb8> output;
initialize(output, cset_1.labeled_image());
data::fill(output, literal::black);
for_all_comps(i, cset_1)
data::fill(((output | cset_1(i).bbox()).rw() | (pw::value(cset_1.labeled_image()) == i)).rw(), literal::red);
for_all_comps(i, cset_2)
data::fill(((output | cset_2(i).bbox()).rw() | (pw::value(cset_2.labeled_image()) == i)).rw(), literal::green);
io::ppm::save(output, filename);
trace::exiting("scribo::debug::save_comp_diff");
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::debug
} // end of namespace scribo
#endif // ! SCRIBO_DEBUG_SAVE_COMP_DIFF_HH
// Copyright (C) 2010 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_DEBUG_TEXT_AREAS_IMAGE_HH
# define SCRIBO_DEBUG_TEXT_AREAS_IMAGE_HH
/// \file
///
/// \brief Compute an image including detected text areas only.
# include <mln/core/concept/image.hh>
# include <mln/core/image/imorph/tr_image.hh>
# include <mln/core/var.hh>
# include <mln/core/routine/duplicate.hh>
# include <mln/data/paste.hh>
# include <mln/data/fill.hh>
# include <mln/fun/x2x/translation.hh>
# include <mln/math/max.hh>
# include <scribo/core/component_set.hh>
namespace scribo
{
namespace debug
{
using namespace mln;
/*! \brief Compute an image including detected text areas only.
*/
template <typename I, typename L>
mln_concrete(I)
text_areas_image(const Image<I>& input_rgb,
const scribo::component_set<L>& comps);
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename L>
mln_concrete(I)
text_areas_image(const Image<I>& input_rgb_,
const scribo::component_set<L>& comps)
{
trace::entering("scribo::debug::text_areas_image");
const I& input_rgb = exact(input_rgb_);
mln_precondition(input_rgb.is_valid());
typedef mln_site(I) P;
unsigned shift = 5;
float height = 1, width = 0;
for_all_comps(i, comps)
if (comps(i).is_valid())
{
height += comps(i).bbox().nrows() + shift;
width = math::max(static_cast<float>(comps(i).bbox().ncols()),
width);
}
if (width == 0)
width = 1;
I output(height, width);
data::fill(output, literal::black);
algebra::vec<2, float> dv;
dv[0] = 0;
dv[1] = 0;
for_all_comps(i, comps)
if (comps(i).is_valid())
{
mln_VAR(tmp, duplicate(input_rgb | comps(i).bbox()));
typedef mln::fun::x2x::translation<P::dim, float> trans_t;
trans_t trans(dv - comps(i).bbox().pmin().to_vec());
mln_domain(I)
tr_box(comps(i).bbox().pmin().to_vec() + trans.t(),
comps(i).bbox().pmax().to_vec() + trans.t());
tr_image<mln_domain(I), tmp_t, trans_t> tr_ima(tr_box, tmp, trans);
data::paste(tr_ima, output);
dv[0] += comps(i).bbox().nrows() + shift;
}
trace::exiting("scribo::debug::text_areas_image");
return output;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::debug
} // end of namespace scribo
#endif // ! SCRIBO_DEBUG_TEXT_AREAS_IMAGE_HH
// Copyright (C) 2010 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_PRIMITIVE_REGROUP_FROM_SINGLE_LEFT_LINK_WRT_H_RATIO_HH
# define SCRIBO_PRIMITIVE_REGROUP_FROM_SINGLE_LEFT_LINK_WRT_H_RATIO_HH
/// \file
///
/// \brief Regroup groups with their left neighbor w.r.t. their height
/// ratio.
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/accu/center.hh>
# include <mln/labeling/compute.hh>
# include <mln/math/abs.hh>
# include <mln/util/array.hh>
# include <scribo/core/macros.hh>
# include <scribo/core/component_set.hh>
# include <scribo/core/object_links.hh>
# include <scribo/filter/object_links_bbox_h_ratio.hh>
# include <scribo/primitive/link/internal/find_link.hh>
# include <scribo/primitive/link/internal/link_single_dmax_base.hh>
# include <scribo/primitive/link/compute.hh>
namespace scribo
{
namespace primitive
{
namespace regroup
{
/// \brief Regroup groups with their left neighbor w.r.t. their
/// height ratio.
///
/// \param[in] groups Groups data.
/// \param[in] The maximum distance allowed to seach a neighbor object.
///
/// \return Object groups data.
//
template <typename L>
inline
object_groups<L>
from_single_left_link_wrt_h_ratio(const object_groups<L>& groups,
unsigned neighb_max_distance,
double hratio);
/// \overload
/// Max distance is set to mln_max(unsigned).
/// hratio is set to 1.60f.
template <typename L>
inline
object_groups<L>
from_single_left_link_wrt_h_ratio(const object_groups<L>& groups);
# ifndef MLN_INCLUDE_ONLY
// Facades
template <typename L>
inline
object_groups<L>
from_single_left_link_wrt_h_ratio(const object_groups<L>& groups,
unsigned neighb_max_distance,
double hratio)
{
trace::entering("scribo::primitive::regroup::from_single_left_link_wrt_h_ratio");
mln_precondition(groups.is_valid());
object_groups<L> output = groups.duplicate();
fun::i2v::array<mln_value(L)> relabel_fun;
component_set<L>
components = primitive::group::apply(groups, relabel_fun);
object_links<L>
links = primitive::link::with_single_left_link(components,
neighb_max_distance);
links = filter::object_links_bbox_h_ratio(links, hratio);
object_groups<L>
new_groups = primitive::group::from_single_link(links);
for_all_groups(g, groups)
output(g) = new_groups(relabel_fun(g));
trace::exiting("scribo::primitive::regroup::from_single_left_link_wrt_h_ratio");
return output;
}
template <typename L>
inline
object_groups<L>
from_single_left_link_wrt_h_ratio(const object_groups<L>& groups)
{
return from_single_left_link_wrt_h_ratio(groups,
mln_max(unsigned), 1.60f);
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::primitive::regroup
} // end of namespace scribo::primitive
} // end of namespace scribo
#endif // ! SCRIBO_PRIMITIVE_REGROUP_FROM_SINGLE_LEFT_LINK_WRT_H_RATIO_HH
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment