* filter/object_groups_size_ratio.hh,
* filter/objects_size_ratio.hh: New filters.
---
scribo/ChangeLog | 7 ++
scribo/filter/object_groups_size_ratio.hh | 104 +++++++++++++++++++++++++
scribo/filter/objects_size_ratio.hh | 120 +++++++++++++++++++++++++++++
3 files changed, 231 insertions(+), 0 deletions(-)
create mode 100644 scribo/filter/object_groups_size_ratio.hh
create mode 100644 scribo/filter/objects_size_ratio.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 0a7f625..fd7af50 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,12 @@
2009-09-25 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add new filters in Scribo.
+
+ * filter/object_groups_size_ratio.hh,
+ * filter/objects_size_ratio.hh: New filters.
+
+2009-09-25 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Small fixes in Scribo.
* demo/src/mainwindow.cc: Do not always resize pics.
diff --git a/scribo/filter/object_groups_size_ratio.hh
b/scribo/filter/object_groups_size_ratio.hh
new file mode 100644
index 0000000..b52c30d
--- /dev/null
+++ b/scribo/filter/object_groups_size_ratio.hh
@@ -0,0 +1,104 @@
+// 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_GROUPS_SIZE_RATIO_HH
+# define SCRIBO_FILTER_OBJECT_GROUPS_SIZE_RATIO_HH
+
+/// \file
+///
+
+
+# include <mln/util/array.hh>
+
+# include <scribo/core/macros.hh>
+# include <scribo/core/object_groups.hh>
+# include <scribo/core/object_image.hh>
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+ using namespace mln;
+
+ template <typename L>
+ object_groups<L>
+ object_groups_size_ratio(const object_groups<L>& groups,
+ float max_size_ratio,
+ float max_invalid_ratio_per_group);
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename L>
+ object_groups<L>
+ object_groups_size_ratio(const object_groups<L>& groups,
+ float max_size_ratio,
+ float max_invalid_ratio_per_group)
+ {
+ trace::entering("scribo::filter::object_groups_size_ratio");
+
+ mln_precondition(groups.is_valid());
+
+ const object_image(L)& objects = groups.object_image_();
+
+ // FIXME: estimating the group size should be removed once
+ // available in the object_group structure.
+ // Counting the number of objects per group with a size ratio >
+ // max_ratio.
+ mln::util::array<unsigned>
+ group_size(groups.size(), 0),
+ invalid_object_in_group(groups.size(), 0);
+
+ for_all_ncomponents(i, objects.nlabels())
+ {
+ if ((objects.bbox(i).nrows() / objects.bbox(i).ncols())
+ >= max_size_ratio)
+ ++invalid_object_in_group[groups[i]];
+
+ ++group_size[groups[i]];
+ }
+
+ object_groups<L> output(groups);
+ 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)
+ output(i) = 0;
+
+ trace::exiting("scribo::filter::object_groups_size_ratio");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_FILTER_OBJECT_GROUPS_SIZE_RATIO_HH
diff --git a/scribo/filter/objects_size_ratio.hh b/scribo/filter/objects_size_ratio.hh
new file mode 100644
index 0000000..7a68f7f
--- /dev/null
+++ b/scribo/filter/objects_size_ratio.hh
@@ -0,0 +1,120 @@
+// 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_OBJECTS_SIZE_RATIO_HH
+# define SCRIBO_FILTER_OBJECTS_SIZE_RATIO_HH
+
+/// \file
+///
+///
+
+# include <mln/core/concept/function.hh>
+# include <scribo/core/object_image.hh>
+
+
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+
+ template <typename L>
+ object_image(L)
+ objects_size_ratio(const object_image(L)& objects,
+ float size_ratio);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+
+ /// Filter Functor.
+ /// Return false for all objects which have a bad ratio.
+ template <typename L>
+ struct objects_size_ratio_filter
+ : Function_v2b< objects_size_ratio_filter<L> >
+ {
+ typedef accu::shape::bbox<mln_psite(L)> box_accu_t;
+
+ objects_size_ratio_filter(const object_image(L)& objects,
+ float ratio)
+ : objects_(objects), ratio_(ratio)
+ {
+ }
+
+ bool operator()(const mln_value(L)& l) const
+ {
+ if (l == literal::zero)
+ return true;
+ return (objects_.bbox(l).nrows() / static_cast<float>(objects_.bbox(l).ncols()))
< ratio_;
+ }
+
+ /// Component bounding boxes.
+ object_image(L) objects_;
+
+ /// The maximum size ratio.
+ float ratio_;
+ };
+
+
+ } // end of namespace scribo::filter::internal
+
+
+
+ template <typename L>
+ object_image(L)
+ objects_size_ratio(const object_image(L)& objects,
+ float size_ratio)
+ {
+
+ trace::entering("scribo::primitive::objects_size_ratio");
+
+ mln_precondition(objects.is_valid());
+
+ typedef internal::objects_size_ratio_filter<L> func_t;
+ func_t has_bad_ratio(objects, size_ratio);
+
+ object_image(L) output;
+ output.init_from_(objects);
+ output.relabel(has_bad_ratio);
+
+ trace::exiting("scribo::primitive::objects_size_ratio");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_FILTER_OBJECTs_SIZE_RATIO_HH
--
1.5.6.5
Show replies by date