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

Replace the use of object_image with component_set.

	* core/erase_objects.hh,
	* debug/several_links_decision_image.hh,
	* filter/object_groups_size_ratio.hh,
	* filter/object_links_bbox_w_ratio.hh,
	* filter/object_links_center_aligned.hh,
	* filter/object_links_left_aligned.hh,
	* filter/object_links_right_aligned.hh,
	* filter/objects_h_thick.hh,
	* filter/objects_h_thin.hh,
	* filter/objects_size_ratio.hh,
	* filter/objects_v_thick.hh,
	* filter/objects_v_thin.hh,
	* primitive/extract/lines_h_thick_and_single.hh,
	* primitive/extract/lines_v_thick_and_single.hh,
	* primitive/group/from_graph.hh,
	* primitive/internal/find_graph_link.hh,
	* primitive/link/with_graph.hh,
	* primitive/link/with_rag.hh,
	* primitive/link/with_several_graphes.hh,
	* primitive/link/with_several_left_links.hh,
	* primitive/link/with_several_right_closest_links.hh,
	* primitive/link/with_several_right_links.hh,
	* primitive/link/with_single_down_link.hh,
	* primitive/link/with_single_up_link.hh: Replace the use of
	object_image with component_set.
parent 8283ce59
2010-08-09 Guillaume Lazzara <z@lrde.epita.fr>
Replace the use of object_image with component_set.
* core/erase_objects.hh,
* debug/several_links_decision_image.hh,
* filter/object_groups_size_ratio.hh,
* filter/object_links_bbox_w_ratio.hh,
* filter/object_links_center_aligned.hh,
* filter/object_links_left_aligned.hh,
* filter/object_links_right_aligned.hh,
* filter/objects_h_thick.hh,
* filter/objects_h_thin.hh,
* filter/objects_size_ratio.hh,
* filter/objects_v_thick.hh,
* filter/objects_v_thin.hh,
* primitive/extract/lines_h_thick_and_single.hh,
* primitive/extract/lines_v_thick_and_single.hh,
* primitive/group/from_graph.hh,
* primitive/internal/find_graph_link.hh,
* primitive/link/with_graph.hh,
* primitive/link/with_rag.hh,
* primitive/link/with_several_graphes.hh,
* primitive/link/with_several_left_links.hh,
* primitive/link/with_several_right_closest_links.hh,
* primitive/link/with_several_right_links.hh,
* primitive/link/with_single_down_link.hh,
* primitive/link/with_single_up_link.hh: Replace the use of
object_image with component_set.
2010-08-09 Guillaume Lazzara <z@lrde.epita.fr>
Small fixes in Scribo.
......
// 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
///
/// Remove the content of bounding boxes from an image.
/// Erase components in an image.
# include <mln/core/concept/image.hh>
# include <mln/core/site_set/box.hh>
......@@ -36,6 +37,7 @@
# include <mln/pw/all.hh>
# include <mln/util/array.hh>
# include <scribo/core/component_set.hh>
# include <scribo/core/macros.hh>
namespace scribo
......@@ -46,13 +48,12 @@ namespace scribo
/// Remove labeled components from a binary image.
///
/// \param[in,out] input_ A binary image.
/// \param[in] objects An image of objects (object value must be
/// different from 0).
/// \param[in] comps A set of components to be erased.
///
//
template <typename I, typename L>
void
erase_objects(Image<I>& input, const Image<L>& objects);
erase_objects(Image<I>& input, const component_set<L>& comps);
# ifndef MLN_INCLUDE_ONLY
......@@ -61,18 +62,17 @@ namespace scribo
template <typename I, typename L>
void
erase_objects(Image<I>& input_,
const Image<L>& objects_)
const component_set<L>& comps)
{
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());
data::fill((input | (pw::value(objects) != pw::cst(literal::zero))).rw(),
data::fill((input | (pw::value(comps.labeled_image())
!= pw::cst(literal::zero))).rw(),
false);
trace::exiting("scribo::erase_objects");
......
......@@ -94,10 +94,9 @@ namespace scribo
trace::entering("scribo::debug::several_links_decision_image");
const I& input = exact(input_);
const object_image(L)& objects = links.object_image_();
const component_set<L>& comps = links.components();
mln_precondition(input.is_valid());
mln_precondition(objects.is_valid());
mln_precondition(links.is_valid());
mln_precondition(filtered_links.is_valid());
......@@ -106,60 +105,56 @@ namespace scribo
image2d<value::rgb8>
links_decision_image = data::convert(value::rgb8(), input);
for_all_components(i, objects.bboxes())
mln::draw::box(links_decision_image, objects.bbox(i), literal::blue);
for_all_comps(c, comps)
mln::draw::box(links_decision_image, comps(c).bbox(), literal::blue);
// Computing mass centers.
mln::util::array<mln_result(accu::center<mln_psite(I)>)>
mass_centers = labeling::compute(accu::meta::center(),
objects, objects.nlabels());
for (unsigned i = 1; i < links.size(); ++i)
for_all_links(l, links)
{
if (links[i] != i)
if (links(l) != l)
{
value::rgb8 value = literal::green;
if (links[i] != filtered_links[i])
if (links(l) != filtered_links(l))
value = literal::red;
mln_site(L) c = objects.bbox(i).center();
mln_site(L) c = comps(l).bbox().pcenter();
// Right link from the top anchor.
mln_site(L) a1 = c;
a1.row() = objects.bbox(i).pmin().row()
+ (c.row() - objects.bbox(i).pmin().row()) / 4;
a1.row() = comps(l).bbox().pmin().row()
+ (c.row() - comps(l).bbox().pmin().row()) / 4;
// Right link from the central site
mln_site(I) p1 = mass_centers[i];
mln_site(I) p1 = comps(l).mass_center();
// Right link from the bottom anchor.
mln_site(L) a2 = c;
a2.row() = objects.bbox(i).pmax().row()
- (c.row() - objects.bbox(i).pmin().row()) / 4;
a2.row() = comps(l).bbox().pmax().row()
- (c.row() - comps(l).bbox().pmin().row()) / 4;
mln_site(L)
a1_bak = a1,
a2_bak = a2;
const L& lbl_ima = comps.labeled_image();
mln_site(L) tmp;
while(objects.domain().has(a1)
|| objects.domain().has(a2)
|| objects.domain().has(p1))
while(lbl_ima.domain().has(a1)
|| lbl_ima.domain().has(a2)
|| lbl_ima.domain().has(p1))
{
if (internal::draw_line(objects, links_decision_image, links[i],
if (internal::draw_line(lbl_ima, links_decision_image, links(l),
a1_bak, a1, value))
break;
else
++a1.col();
if (internal::draw_line(objects, links_decision_image, links[i],
mass_centers[i], p1, value))
if (internal::draw_line(lbl_ima, links_decision_image, links(l),
comps(l).mass_center(), p1, value))
break;
else
++p1.col();
if (internal::draw_line(objects, links_decision_image, links[i],
if (internal::draw_line(lbl_ima, links_decision_image, links(l),
a2_bak, a2, value))
break;
else
......
// 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.
//
......@@ -63,7 +64,7 @@ namespace scribo
mln_precondition(groups.is_valid());
const object_image(L)& objects = groups.object_image_();
const component_set<L>& comps = groups.components();
// FIXME: estimating the group size should be removed once
// available in the object_group structure.
......@@ -73,9 +74,9 @@ namespace scribo
group_size(groups.size(), 0),
invalid_object_in_group(groups.size(), 0);
for_all_ncomponents(i, objects.nlabels())
for_all_comps(i, comps)
{
if ((objects.bbox(i).nrows() / objects.bbox(i).ncols())
if ((comps(i).bbox().nrows() / comps(i).bbox().ncols())
>= max_size_ratio)
++invalid_object_in_group[groups[i]];
......@@ -86,7 +87,7 @@ namespace scribo
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
|| !components(i).is_valid())
|| !comps(i).is_valid())
output(i) = 0;
trace::exiting("scribo::filter::object_groups_size_ratio");
......
// 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,8 +29,10 @@
/// \file
///
/// Invalidate links between two objects with too different height or
/// width.
/// Invalidate links between two objects with too different width.
///
/// \todo rename to object_links_bbox_h_ratio (h for horizontal) to be
/// consistent with other routine names.
# include <mln/util/array.hh>
......@@ -50,7 +53,6 @@ namespace scribo
/*! \brief Invalidate links between two objects with too different
width.
\param[in] objects An object image.
\param[in] links Link objects information.
\param[in] min_w_ratio The minimum width ratio of two linked
bounding boxes.
......@@ -59,8 +61,7 @@ namespace scribo
*/
template <typename L>
object_links<L>
object_links_bbox_w_ratio(const object_image(L)& objects,
const object_links<L>& links,
object_links_bbox_w_ratio(const object_links<L>& links,
float min_w_ratio);
......@@ -69,17 +70,15 @@ namespace scribo
template <typename L>
object_links<L>
object_links_bbox_w_ratio(const object_image(L)& objects,
const object_links<L>& links,
object_links_bbox_w_ratio(const object_links<L>& links,
float min_w_ratio)
{
trace::entering("scribo::filter::object_links_bbox_w_ratio");
mln_precondition(objects.is_valid());
mln_precondition(links.is_valid());
object_links<L>
output = object_links_bbox_ratio(objects, links, 1, min_w_ratio);
output = object_links_bbox_ratio(links, 1, min_w_ratio);
trace::exiting("scribo::filter::object_links_bbox_w_ratio");
return output;
......
......@@ -36,7 +36,6 @@
# include <scribo/core/macros.hh>
# include <scribo/core/object_links.hh>
# include <scribo/core/object_image.hh>
# include <scribo/filter/object_links_non_aligned_simple.hh>
......@@ -74,8 +73,7 @@ namespace scribo
*/
template <typename L>
object_links<L>
object_links_center_aligned(const object_image(L)& objects,
const object_links<L>& links,
object_links_center_aligned(const object_links<L>& links,
float max_alpha);
......@@ -84,17 +82,15 @@ namespace scribo
template <typename L>
object_links<L>
object_links_center_aligned(const object_image(L)& objects,
const object_links<L>& links,
object_links_center_aligned(const object_links<L>& links,
float max_alpha)
{
trace::entering("scribo::filter::object_links_center_aligned");
mln_precondition(objects.is_valid());
mln_precondition(links.is_valid());
object_links<L>
output = object_links_non_aligned_simple(objects, links,
output = object_links_non_aligned_simple(links,
anchor::Center, max_alpha);
trace::exiting("scribo::filter::object_links_center_aligned");
......
// 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.
//
......@@ -52,7 +53,6 @@ namespace scribo
/*! \brief Invalidate links between two objects if their left are not
aligned.
\param[in] objects An object image.
\param[in] links Object links information.
\param[in] max_alpha Maximum angle value (degrees).
......@@ -82,8 +82,7 @@ namespace scribo
*/
template <typename L>
object_links<L>
object_links_left_aligned(const object_image(L)& objects,
const object_links<L>& links,
object_links_left_aligned(const object_links<L>& links,
float max_alpha);
......@@ -92,17 +91,15 @@ namespace scribo
template <typename L>
object_links<L>
object_links_left_aligned(const object_image(L)& objects,
const object_links<L>& links,
object_links_left_aligned(const object_links<L>& links,
float max_alpha)
{
trace::entering("scribo::filter::object_links_left_aligned");
mln_precondition(objects.is_valid());
mln_precondition(links.is_valid());
object_links<L>
output = object_links_non_aligned_simple(objects, links,
output = object_links_non_aligned_simple(links,
anchor::Left,
max_alpha);
......
// 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.
//
......@@ -81,9 +82,8 @@ namespace scribo
*/
template <typename L>
object_links<L>
object_links_right_aligned(const object_image(L)& objects,
const object_links<L>& links,
float max_alpha);
object_links_right_aligned(const object_links<L>& links,
float max_alpha);
# ifndef MLN_INCLUDE_ONLY
......@@ -91,17 +91,15 @@ namespace scribo
template <typename L>
object_links<L>
object_links_right_aligned(const object_image(L)& objects,
const object_links<L>& links,
float max_alpha)
object_links_right_aligned(const object_links<L>& links,
float max_alpha)
{
trace::entering("scribo::filter::object_links_right_aligned");
mln_precondition(objects.is_valid());
mln_precondition(links.is_valid());
object_links<L>
output = object_links_non_aligned_simple(objects, links,
output = object_links_non_aligned_simple(links,
anchor::Right,
max_alpha);
......
// 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.
//
......@@ -33,10 +34,7 @@
# 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/filter/internal/compute.hh>
......@@ -48,12 +46,12 @@ namespace scribo
using namespace mln;
/// Remove objects horizontaly thicker or equal to \p max_thickness.
/// Remove objects horizontaly thicker 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] max_thickness The maximum thickness value.
/// \param[in] min_thickness The maximum thickness value.
///
/// \result A binary image without thick objects.
//
......@@ -63,21 +61,21 @@ namespace scribo
objects_h_thick(const Image<I>& input_,
const Neighborhood<N>& nbh_,
const V& label_type,
unsigned max_thickness);
unsigned min_thickness);
/// Remove objects horizontaly thicker or equal to \p max_thickness.
/// Remove objects horizontaly thicker or equal to \p min_thickness.
///
/// \param[in] objects An object image.
/// \param[in] max_thickness The maximum thickness value.
/// \param[in] comps Component data.
/// \param[in] min_thickness The minimum thickness value.
///
/// \result An object image without too thick objects.
/// \result A component data set without too thick components.
//
template <typename L>
inline
object_image(L)
objects_h_thick(const object_image(L)& objects,
unsigned max_thickness);
component_set<L>
objects_h_thick(const component_set<L>& comps,
unsigned min_thickness);
......@@ -87,8 +85,8 @@ namespace scribo
namespace internal
{
/// Filter Functor. Return false for all objects which are too
/// large.
/// Filter Functor. Return false for all components which are
/// thick.
template <typename L>
struct h_thick_object_filter
: Function_v2b< h_thick_object_filter<L> >
......@@ -96,48 +94,48 @@ namespace scribo
/// Constructor
///
/// \param[in] objects An object image.
/// \param[in] max_thickness the maximum thickness allowed.
/// \param[in] comps Component data.
/// \param[in] min_thickness the minimum thickness allowed.
//
h_thick_object_filter(const object_image(L)& objects,
unsigned max_thickness)
: objects_(objects), max_thickness_(max_thickness)
h_thick_object_filter(const component_set<L>& comps,
unsigned min_thickness)
: comps_(comps), min_thickness_(min_thickness)
{
}
/// Constructor
///
/// \param[in] max_thickness the maximum thickness allowed.
/// \param[in] min_thickness the minimum thickness allowed.
//
h_thick_object_filter(unsigned max_thickness)
: max_thickness_(max_thickness)
h_thick_object_filter(unsigned min_thickness)
: min_thickness_(min_thickness)
{
}
/// Set the underlying object image.
//
void update_objects(const object_image(L)& objects)
void update_objects(const component_set<L>& comps)
{
objects_ = objects;
comps_ = comps;
}
/// Return false if the objects is thicker than
/// \p max_thickness_.
/// Return false if the component is thicker than
/// \p min_thickness_.
///
/// \param[in] l An image value.
bool operator()(const mln_value(L)& l) const
{
if (l == literal::zero)
return true;
return objects_.bbox(l).nrows() < max_thickness_;
return comps_(l).bbox().height() > min_thickness_;
}
/// An object image.
object_image(L) objects_;
/// Components data.
component_set<L> comps_;
/// The maximum thickness.
unsigned max_thickness_;
/// The minimum thickness.
unsigned min_thickness_;
};
......@@ -150,7 +148,7 @@ namespace scribo
objects_thick(const Image<I>& input_,
const Neighborhood<N>& nbh_,
const V& label_type,
unsigned max_thickness)
unsigned min_thickness)
{
trace::entering("scribo::filter::objects_h_thick");
......@@ -160,7 +158,7 @@ namespace scribo
mln_precondition(input.is_valid());
mln_precondition(nbh.is_valid());
internal::h_thick_object_filter<V> functor(max_thickness);
internal::h_thick_object_filter<V> functor(min_thickness);
mln_concrete(I)
output = internal::compute(input, nbh, label_type, functor);
......@@ -171,16 +169,14 @@ namespace scribo
template <typename L>
inline
object_image(L)
objects_h_thick(const object_image(L)& objects,
unsigned max_thickness)
component_set<L>
objects_h_thick(const component_set<L>& comps,
unsigned min_thickness)
{
trace::entering("scribo::filter::objects_h_thick");
mln_precondition(objects.is_valid());
internal::h_thick_object_filter<L> functor(objects, max_thickness);
object_image(L) output = internal::compute(objects, functor);
internal::h_thick_object_filter<L> functor(comps, min_thickness);
component_set<L> output = internal::compute(comps, functor);
trace::exiting("scribo::filter::objects_h_thick");
return output;
......
// 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,15 +29,13 @@
/// \file
///
/// Remove too thin objects.
/// Remove too thin 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/filter/internal/compute.hh>
namespace scribo
{
......@@ -46,14 +45,14 @@ namespace scribo
using namespace mln;
/// Remove objects thinner or equal to \p min_thickness.
/// Remove components thinner or equal to \p min_thinness.
///
/// \param[in] input_ a binary image.
/// \param[in] nbh_ a neighborhood used in labeling algorithms.