Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
August 2009
- 6 participants
- 108 discussions
* src/Makefile.am: update.
* src/text/Makefile.am,
* src/text/grouping/Makefile.am: New.
* src/extract_text_double_link.cc,
* src/extract_text_double_several_links.cc,
* src/extract_text_graph.cc,
* src/extract_text_several_graph.cc,
* src/extract_text_several_left_links.cc,
* src/extract_text_single_link.cc: Move...
* src/text/grouping/group_from_double_link.cc,
* src/text/grouping/group_from_double_several_links.cc,
* src/text/grouping/group_from_graph.cc,
* src/text/grouping/group_from_several_graph.cc,
* src/text/grouping/group_from_several_left_links.cc,
* src/text/grouping/group_from_single_link.cc: ... here.
---
scribo/ChangeLog | 23 +++++++++++
scribo/src/Makefile.am | 18 ++------
scribo/src/text/Makefile.am | 1 +
scribo/src/text/grouping/Makefile.am | 40 ++++++++++++++++++++
.../grouping/group_from_double_link.cc} | 0
.../grouping/group_from_double_several_links.cc} | 2 +-
.../grouping/group_from_graph.cc} | 2 +-
.../grouping/group_from_several_graph.cc} | 2 +-
.../grouping/group_from_several_left_links.cc} | 2 +-
.../grouping/group_from_single_link.cc} | 2 +-
10 files changed, 74 insertions(+), 18 deletions(-)
create mode 100644 scribo/src/text/Makefile.am
create mode 100644 scribo/src/text/grouping/Makefile.am
rename scribo/src/{extract_text_double_link.cc => text/grouping/group_from_double_link.cc} (100%)
rename scribo/src/{extract_text_double_several_links.cc => text/grouping/group_from_double_several_links.cc} (97%)
rename scribo/src/{extract_text_graph.cc => text/grouping/group_from_graph.cc} (97%)
rename scribo/src/{extract_text_several_graph.cc => text/grouping/group_from_several_graph.cc} (97%)
rename scribo/src/{extract_text_several_left_links.cc => text/grouping/group_from_several_left_links.cc} (97%)
rename scribo/src/{extract_text_single_link.cc => text/grouping/group_from_single_link.cc} (98%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 4aab740..3ab33cd 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,26 @@
+2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Move example files.
+
+ * src/Makefile.am: update.
+
+ * src/text/Makefile.am,
+ * src/text/grouping/Makefile.am: New.
+
+ * src/extract_text_double_link.cc,
+ * src/extract_text_double_several_links.cc,
+ * src/extract_text_graph.cc,
+ * src/extract_text_several_graph.cc,
+ * src/extract_text_several_left_links.cc,
+ * src/extract_text_single_link.cc: Move...
+
+ * src/text/grouping/group_from_double_link.cc,
+ * src/text/grouping/group_from_double_several_links.cc,
+ * src/text/grouping/group_from_graph.cc,
+ * src/text/grouping/group_from_several_graph.cc,
+ * src/text/grouping/group_from_several_left_links.cc,
+ * src/text/grouping/group_from_single_link.cc: ... here.
+
2009-08-19 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
* src/Makefile.am: Link 'recognition' example to libtiff.
diff --git a/scribo/src/Makefile.am b/scribo/src/Makefile.am
index a7a5259..7f39191 100644
--- a/scribo/src/Makefile.am
+++ b/scribo/src/Makefile.am
@@ -24,16 +24,11 @@ SUBDIRS = \
extract \
filter \
preprocessing \
- table
+ table \
+ text
bin_PROGRAMS = \
dmap \
- extract_text_double_link \
- extract_text_double_several_links \
- extract_text_graph \
- extract_text_several_graph \
- extract_text_several_left_links \
- extract_text_single_link \
morpho \
negate \
preprocess \
@@ -42,16 +37,11 @@ bin_PROGRAMS = \
table_rebuild_opening \
table_rebuild_rank \
text_in_photo \
+ text_in_photo_invert \
thin_bboxes
dmap_SOURCES = dmap.cc
-extract_text_double_link_SOURCES = extract_text_double_link.cc
-extract_text_double_several_links_SOURCES = extract_text_double_several_links.cc
-extract_text_graph_SOURCES = extract_text_graph.cc
-extract_text_several_graph_SOURCES = extract_text_several_graph.cc
-extract_text_several_left_links_SOURCES = extract_text_several_left_links.cc
-extract_text_single_link_SOURCES = extract_text_single_link.cc
morpho_SOURCES = morpho.cc
negate_SOURCES = negate.cc
preprocess_SOURCES = preprocess.cc
@@ -60,9 +50,11 @@ superpose_SOURCES = superpose.cc
table_rebuild_opening_SOURCES = table_rebuild_opening.cc
table_rebuild_rank_SOURCES = table_rebuild_rank.cc
text_in_photo_SOURCES = text_in_photo.cc
+text_in_photo_invert_SOURCES = text_in_photo_invert.cc
thin_bboxes_SOURCES = thin_bboxes.cc
+
if HAVE_TESSERACT
if HAVE_TIFF
diff --git a/scribo/src/text/Makefile.am b/scribo/src/text/Makefile.am
new file mode 100644
index 0000000..5f5ed81
--- /dev/null
+++ b/scribo/src/text/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = grouping
diff --git a/scribo/src/text/grouping/Makefile.am b/scribo/src/text/grouping/Makefile.am
new file mode 100644
index 0000000..83c2306
--- /dev/null
+++ b/scribo/src/text/grouping/Makefile.am
@@ -0,0 +1,40 @@
+# 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/>.
+#
+
+## Process this file through Automake to create Makefile.in.
+
+include $(top_srcdir)/scribo/scribo.mk
+
+bin_PROGRAMS = \
+ group_from_double_link \
+ group_from_double_link_filter_non_aligned \
+ group_from_double_several_links \
+ group_from_graph \
+ group_from_rag \
+ group_from_several_graph \
+ group_from_several_left_links \
+ group_from_single_link
+
+group_from_double_link_SOURCES = group_from_double_link.cc
+group_from_double_link_filter_non_aligned_SOURCES = group_from_double_link_filter_non_aligned.cc
+group_from_double_several_links_SOURCES = group_from_double_several_links.cc
+group_from_graph_SOURCES = group_from_graph.cc
+group_from_rag_SOURCES = group_from_rag.cc
+group_from_several_graph_SOURCES = group_from_several_graph.cc
+group_from_several_left_links_SOURCES = group_from_several_left_links.cc
+group_from_single_link_SOURCES = group_from_single_link.cc
+
diff --git a/scribo/src/extract_text_double_link.cc b/scribo/src/text/grouping/group_from_double_link.cc
similarity index 100%
rename from scribo/src/extract_text_double_link.cc
rename to scribo/src/text/grouping/group_from_double_link.cc
diff --git a/scribo/src/extract_text_double_several_links.cc b/scribo/src/text/grouping/group_from_double_several_links.cc
similarity index 97%
rename from scribo/src/extract_text_double_several_links.cc
rename to scribo/src/text/grouping/group_from_double_several_links.cc
index c220e77..e22239d 100644
--- a/scribo/src/extract_text_double_several_links.cc
+++ b/scribo/src/text/grouping/group_from_double_several_links.cc
@@ -62,7 +62,7 @@ int main(int argc, char* argv[])
if (argc < 1)
return usage(argv[0]);
- scribo::make::internal::debug_filename_prefix = "extract_text_double_several_links";
+ scribo::make::internal::debug_filename_prefix = "group_with_double_several_links";
mln::util::timer t, t2;
image2d<bool> input;
diff --git a/scribo/src/extract_text_graph.cc b/scribo/src/text/grouping/group_from_graph.cc
similarity index 97%
rename from scribo/src/extract_text_graph.cc
rename to scribo/src/text/grouping/group_from_graph.cc
index 91bd799..de98ff9 100644
--- a/scribo/src/extract_text_graph.cc
+++ b/scribo/src/text/grouping/group_from_graph.cc
@@ -55,7 +55,7 @@ int main(int argc, char* argv[])
if (argc < 1)
return usage(argv[0]);
- scribo::make::internal::debug_filename_prefix = "extract_text_graph";
+ scribo::make::internal::debug_filename_prefix = "group_with_graph";
image2d<bool> input;
io::pbm::load(input, argv[1]);
diff --git a/scribo/src/extract_text_several_graph.cc b/scribo/src/text/grouping/group_from_several_graph.cc
similarity index 97%
rename from scribo/src/extract_text_several_graph.cc
rename to scribo/src/text/grouping/group_from_several_graph.cc
index bc0d3e0..1db26a7 100644
--- a/scribo/src/extract_text_several_graph.cc
+++ b/scribo/src/text/grouping/group_from_several_graph.cc
@@ -61,7 +61,7 @@ int main(int argc, char* argv[])
if (argc < 1)
return usage(argv[0]);
- scribo::make::internal::debug_filename_prefix = "extract_text_several_graph";
+ scribo::make::internal::debug_filename_prefix = "group_with_several_graph";
image2d<bool> input;
io::pbm::load(input, argv[1]);
diff --git a/scribo/src/extract_text_several_left_links.cc b/scribo/src/text/grouping/group_from_several_left_links.cc
similarity index 97%
rename from scribo/src/extract_text_several_left_links.cc
rename to scribo/src/text/grouping/group_from_several_left_links.cc
index 6e6f1fa..cdc65ae 100644
--- a/scribo/src/extract_text_several_left_links.cc
+++ b/scribo/src/text/grouping/group_from_several_left_links.cc
@@ -62,7 +62,7 @@ int main(int argc, char* argv[])
if (argc < 1)
return usage(argv[0]);
- scribo::make::internal::debug_filename_prefix = "extract_text_several_left_links";
+ scribo::make::internal::debug_filename_prefix = "group_with_several_left_links";
image2d<bool> input;
io::pbm::load(input, argv[1]);
diff --git a/scribo/src/extract_text_single_link.cc b/scribo/src/text/grouping/group_from_single_link.cc
similarity index 98%
rename from scribo/src/extract_text_single_link.cc
rename to scribo/src/text/grouping/group_from_single_link.cc
index e29b1c4..58a7f2f 100644
--- a/scribo/src/extract_text_single_link.cc
+++ b/scribo/src/text/grouping/group_from_single_link.cc
@@ -62,7 +62,7 @@ int main(int argc, char* argv[])
if (argc != 2)
return usage(argv);
- scribo::make::internal::debug_filename_prefix = "extract_text_single_link";
+ scribo::make::internal::debug_filename_prefix = "group_with_single_link";
image2d<bool> input;
io::pbm::load(input, argv[1]);
--
1.5.6.5
1
0
21 Aug '09
---
milena/ChangeLog | 4 ++++
milena/mln/debug/superpose.hh | 18 ++++++++++++------
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 6cea6f0..6785877 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2009-08-21 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ * mln/debug/superpose.hh: Add support for more image types.
+
+2009-08-21 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
* mln/core/image/imorph/labeled_image.hh: Improve relabeling.
2009-08-21 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
diff --git a/milena/mln/debug/superpose.hh b/milena/mln/debug/superpose.hh
index c96dc83..f6f1d2d 100644
--- a/milena/mln/debug/superpose.hh
+++ b/milena/mln/debug/superpose.hh
@@ -32,6 +32,8 @@
# include <mln/core/concept/image.hh>
# include <mln/core/image/dmorph/image_if.hh>
+# include <mln/value/concept/scalar.hh>
+# include <mln/value/concept/symbolic.hh>
# include <mln/value/rgb8.hh>
# include <mln/data/fill.hh>
# include <mln/data/convert.hh>
@@ -49,8 +51,9 @@ namespace mln
/// \param[in] input_ An image. Its value type must be convertible
/// toward value::rgb8 thanks to a conversion
/// operator or convert::from_to.
- /// \param[in] object_ A binary image. Objects used for superposition
- /// are set to 'true'.
+ /// \param[in] object_ A scalar or labeled image. Objects used for
+ /// superposition.
+ /// have their pixel values different from 0.
/// \param[in] object_color The color used to draw the objects in
/// \p object_.
///
@@ -63,14 +66,12 @@ namespace mln
superpose(const Image<I>& input_, const Image<J>& object_,
const value::rgb8& object_color);
-
/// \overload
template <typename I, typename J>
mln_ch_value(I,value::rgb8)
superpose(const Image<I>& input, const Image<J>& object);
-
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename J>
@@ -83,13 +84,18 @@ namespace mln
const I& input = exact(input_);
const J& object = exact(object_);
- mlc_equal(mln_value(J), bool)::check();
+ //FIXME: Allow symbolic values may not be correct...
+ mlc_or(mlc_or(mlc_is_a(mln_value(J), value::Scalar),
+ mlc_is(mln_value(J), bool)),
+ mlc_is_a(mln_value(J), value::Symbolic))::check();
+
mln_precondition(input.is_valid());
mln_precondition(object.is_valid());
mln_precondition(input.domain() == object.domain());
mln_ch_value(I,value::rgb8) output = data::convert(value::rgb8(), input);
- data::fill((output | pw::value(object)).rw(), object_color);
+ data::fill((output | (pw::value(object) != pw::cst(literal::zero))).rw(),
+ object_color);
trace::exiting("debug::superpose");
return output;
--
1.5.6.5
1
0
21 Aug '09
---
milena/ChangeLog | 4 +
milena/mln/core/image/imorph/labeled_image.hh | 110 ++++++++++++++++--------
2 files changed, 77 insertions(+), 37 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 6d54e86..6cea6f0 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2009-08-21 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ * mln/core/image/imorph/labeled_image.hh: Improve relabeling.
+
+2009-08-21 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
* mln/labeling/pack.hh: Add new overloads.
2009-08-21 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
diff --git a/milena/mln/core/image/imorph/labeled_image.hh b/milena/mln/core/image/imorph/labeled_image.hh
index 5672e92..8e27163 100644
--- a/milena/mln/core/image/imorph/labeled_image.hh
+++ b/milena/mln/core/image/imorph/labeled_image.hh
@@ -55,6 +55,11 @@
# endif // ! NDEBUG
+# include <mln/accu/shape/bbox.hh>
+# include <mln/labeling/relabel.hh>
+# include <mln/make/relabelfun.hh>
+
+
namespace mln
{
@@ -75,6 +80,8 @@ namespace mln
struct data< labeled_image<I> >
{
data(const I& ima, const mln_value(I)& nlabels);
+ data(const I& ima, const mln_value(I)& nlabels,
+ const util::array<mln_box(I)>& bboxes);
I ima_;
mln_value(I) nlabels_;
@@ -141,6 +148,11 @@ namespace mln
/// Constructor from an image \p ima and the number of labels \p nlabels.
labeled_image(const I& ima, const mln_value(I)& nlabels);
+
+ /// Constructor from an image \p ima, the number of labels \p
+ /// nlabels and the object bounding boxes.
+ labeled_image(const I& ima, const mln_value(I)& nlabels,
+ const util::array<mln_box(I)>& bboxes);
/// @}
/// Deferred initialization from a labeled image \p ima and the number
@@ -153,11 +165,11 @@ namespace mln
/// Relabel according to a function.
/// @{
//
- /// Labels may be removed and the labeling may not be contiguous
- /// afterwards.
- /// FIXME: currently the labels are packed after relabeling for
- /// performance reasons. Do we want to be less restrictive?
- /// \sa pack_().
+ /// Merge or delete labels according to the given function.
+ /// This method ensures that the labeling remains contiguous.
+ ///
+ // FIXME: currently the label is kept contiguous for
+ // performance reasons. Do we want to be less restrictive?
template <typename F>
void relabel(const Function_v2v<F>& f);
//
@@ -167,14 +179,11 @@ namespace mln
void relabel(const Function_v2b<F>& f);
/// @}
- /// Pack labeling. Relabel if the labeling is not contiguous.
- void pack_();
-
/// Return the number of labels;
mln_value(I) nlabels() const;
/// Update bounding boxes information.
- void update_();
+ void update_(const fun::i2v::array<mln_value(I)>& relabel_fun);
/// Return the bounding box of the component \p label.
const bbox_t& bbox(const mln_value(I)& label) const;
@@ -229,6 +238,15 @@ namespace mln
{
}
+ template <typename I>
+ inline
+ data< labeled_image<I> >::data(const I& ima, const mln_value(I)& nlabels,
+ const util::array<mln_box(I)>& bboxes)
+ : ima_(ima), nlabels_(nlabels), bboxes_(bboxes)
+ {
+ }
+
+
} // end of namespace mln::internal
@@ -247,12 +265,24 @@ namespace mln
template <typename I>
inline
+ labeled_image<I>::labeled_image(const I& ima, const mln_value(I)& nlabels,
+ const util::array<mln_box(I)>& bboxes)
+ {
+ mln_precondition(data::compute(accu::meta::stat::max(), ima) == nlabels);
+ this->data_ = new internal::data< labeled_image<I> >(ima, nlabels, bboxes);
+ }
+
+
+ template <typename I>
+ inline
void
labeled_image<I>::init_(const I& ima, const mln_value(I)& nlabels)
{
mln_precondition(data::compute(accu::meta::stat::max(), ima) == nlabels);
this->data_ = new internal::data< labeled_image<I> >(ima, nlabels);
- this->update_();
+ this->data_->bboxes_ = labeling::compute(accu::meta::shape::bbox(),
+ this->data_->ima_,
+ this->data_->nlabels_);
}
template <typename I>
@@ -273,18 +303,23 @@ namespace mln
labeled_image<I>::relabel(const Function_v2v<F>& f_)
{
const F& f = exact(f_);
- labeling::relabel_inplace(this->data_->ima_, this->data_->nlabels_, f);
+ mln_value(I) new_nlabels;
+
+ fun::i2v::array<mln_value(I)>
+ packed_relabel_fun = make::relabelfun(f,
+ this->data_->nlabels_,
+ new_nlabels);
+ labeling::relabel_inplace(this->data_->ima_, this->data_->nlabels_,
+ packed_relabel_fun);
- /// We MUST be sure that the labeling is contiguous in order to compute
- /// attributes.
- ///FIXME: do we want to be less restrictive?
- pack_();
+ this->data_->nlabels_ = new_nlabels;
- /// FIXME: could be highly improved: reorder the attributes according to
- /// the function f.
- this->update_();
+ /// We may have merged or deleted labels.
+ update_(packed_relabel_fun);
}
+
+
template <typename I>
template <typename F>
inline
@@ -292,25 +327,19 @@ namespace mln
labeled_image<I>::relabel(const Function_v2b<F>& f_)
{
const F& f = exact(f_);
- labeling::relabel_inplace(this->data_->ima_, this->data_->nlabels_, f);
- /// FIXME: could be highly improved: reorder the attributes according to
- /// the function f.
- this->update_();
- }
+ // Relabel the underlying image.
+ typedef fun::i2v::array<mln_value(I)> fv2v_t;
+ fv2v_t fv2v = make::relabelfun(f,
+ this->data_->nlabels_,
+ this->data_->nlabels_);
- template <typename I>
- inline
- void
- labeled_image<I>::pack_()
- {
- labeling::pack_inplace(this->data_->ima_, this->data_->nlabels_);
+ labeling::relabel_inplace(this->data_->ima_, this->data_->nlabels_, fv2v);
- /// FIXME: could be highly improved: reorder the attributes according to
- /// the way the labels are packed.
- this->update_();
- }
+ // Then, merge or delete bounding boxes according to this relabeling.
+ update_(fv2v);
+ }
template <typename I>
inline
@@ -335,11 +364,18 @@ namespace mln
template <typename I>
void
- labeled_image<I>::update_()
+ labeled_image<I>::update_(const fun::i2v::array<mln_value(I)>& relabel_fun)
{
- this->data_->bboxes_ = labeling::compute(accu::meta::shape::bbox(),
- this->data_->ima_,
- this->data_->nlabels_);
+ util::array<accu::shape::bbox<mln_psite(I)> >
+ new_bboxes(static_cast<unsigned>(this->data_->nlabels_) + 1);
+
+ for (unsigned i = 1; i < this->data_->bboxes_.size(); ++i)
+ if (relabel_fun(i) != 0)
+ new_bboxes[relabel_fun(i)].take(this->data_->bboxes_[i]);
+
+ convert::from_to(new_bboxes, this->data_->bboxes_);
+
+ mln_assertion(new_bboxes.size() == this->data_->bboxes_.size());
}
--
1.5.6.5
1
0
---
milena/ChangeLog | 4 +++
milena/mln/labeling/pack.hh | 52 +++++++++++++++++++++++++++++++++++-------
2 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index bf1e791..6d54e86 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2009-08-21 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ * mln/labeling/pack.hh: Add new overloads.
+
+2009-08-21 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Fix buggy from_to overloads and add a missing one.
* mln/convert/from_to.hxx: Add a new overload.
diff --git a/milena/mln/labeling/pack.hh b/milena/mln/labeling/pack.hh
index c70d758..c5e766e 100644
--- a/milena/mln/labeling/pack.hh
+++ b/milena/mln/labeling/pack.hh
@@ -52,11 +52,19 @@ namespace mln
///
/// \param[in] label The labeled image.
/// \param[out] new_nlabels The number of labels after relabeling.
+ /// \param[out] repack_fun The function used to repack the labels.
///
/// \return The relabeled image.
//
template <typename I>
mln_concrete(I)
+ pack(const Image<I>& label, mln_value(I)& new_nlabels,
+ fun::i2v::array<mln_value(I)>& repack_fun);
+
+
+ /// \overload
+ template <typename I>
+ mln_concrete(I)
pack(const Image<I>& label, mln_value(I)& new_nlabels);
@@ -66,9 +74,17 @@ namespace mln
///
/// \param[in] label The labeled image.
/// \param[out] new_nlabels The number of labels after relabeling.
+ /// \param[out] repack_fun The function used to repack the labels.
//
template <typename I>
void
+ pack_inplace(Image<I>& label, mln_value(I)& new_nlabels,
+ fun::i2v::array<mln_value(I)>& repack_fun);
+
+
+ /// \overload
+ template <typename I>
+ void
pack_inplace(Image<I>& label, mln_value(I)& new_nlabels);
@@ -98,6 +114,16 @@ namespace mln
mln_concrete(I)
pack(const Image<I>& label, mln_value(I)& new_nlabels)
{
+ fun::i2v::array<mln_value(I)> repack_fun;
+ return pack(label, new_nlabels, repack_fun);
+ }
+
+
+ template <typename I>
+ mln_concrete(I)
+ pack(const Image<I>& label, mln_value(I)& new_nlabels,
+ fun::i2v::array<mln_value(I)>& repack_fun)
+ {
trace::entering("labeling::pack");
internal::pack_tests(label, new_nlabels);
@@ -106,22 +132,31 @@ namespace mln
fv2b = data::compute(accu::meta::label_used(), label);
mln_value(I) tmp_nlabels = fv2b.size() - 1;
+
+ repack_fun = make::relabelfun(fv2b, tmp_nlabels, new_nlabels);
+
mln_concrete(I)
- output = data::transform(label,
- make::relabelfun(fv2b,
- tmp_nlabels,
- new_nlabels));
+ output = data::transform(label, repack_fun);
trace::exiting("labeling::pack");
return output;
}
-
template <typename I>
void
pack_inplace(Image<I>& label, mln_value(I)& new_nlabels)
{
+ fun::i2v::array<mln_value(I)> repack_fun;
+ pack_inplace(label, new_nlabels, repack_fun);
+ }
+
+
+ template <typename I>
+ void
+ pack_inplace(Image<I>& label, mln_value(I)& new_nlabels,
+ fun::i2v::array<mln_value(I)>& repack_fun)
+ {
trace::entering("labeling::pack_inplace");
internal::pack_tests(label, new_nlabels);
@@ -130,10 +165,9 @@ namespace mln
fv2b = data::compute(accu::meta::label_used(), label);
mln_value(I) tmp_nlabels = fv2b.size() - 1;
- exact(label) = data::transform(label,
- make::relabelfun(fv2b,
- tmp_nlabels,
- new_nlabels));
+ repack_fun = make::relabelfun(fv2b, tmp_nlabels, new_nlabels);
+
+ exact(label) = data::transform(label, repack_fun);
trace::exiting("labeling::pack_inplace");
}
--
1.5.6.5
1
0
* mln/convert/from_to.hxx: Add a new overload.
* mln/fun/i2v/array.hh: Fix buggy from_to overloads.
* mln/util/array.hh: Fix buggy from_to overloads and add a new
one.
---
milena/ChangeLog | 11 +++++++++++
milena/mln/convert/from_to.hxx | 4 ++++
milena/mln/fun/i2v/array.hh | 8 ++++----
milena/mln/util/array.hh | 19 +++++++++++++++++--
4 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 31f5d3d..bf1e791 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,16 @@
2009-08-21 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Fix buggy from_to overloads and add a missing one.
+
+ * mln/convert/from_to.hxx: Add a new overload.
+
+ * mln/fun/i2v/array.hh: Fix buggy from_to overloads.
+
+ * mln/util/array.hh: Fix buggy from_to overloads and add a new
+ one.
+
+2009-08-21 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add blobs_and_compute.
* mln/canvas/labeling/blobs.hh: New. Make labeling blobs a canvas.
diff --git a/milena/mln/convert/from_to.hxx b/milena/mln/convert/from_to.hxx
index 6a10923..ebc30cd 100644
--- a/milena/mln/convert/from_to.hxx
+++ b/milena/mln/convert/from_to.hxx
@@ -376,6 +376,10 @@ namespace mln
void
from_to_(const util::array<T1>& from, util::array<T2>& to);
+ // fun::i2v::array<T1> -> util::array<T2>
+ template <typename T1, typename T2>
+ void
+ from_to_(const fun::i2v::array<T1>& from, util::array<T2>& to);
// Accumulator<A> -> mln_result(A)
diff --git a/milena/mln/fun/i2v/array.hh b/milena/mln/fun/i2v/array.hh
index f60629d..ed4a379 100644
--- a/milena/mln/fun/i2v/array.hh
+++ b/milena/mln/fun/i2v/array.hh
@@ -191,9 +191,9 @@ namespace mln
void
from_to_(const util::array<T>& from, fun::i2v::array<U>& to)
{
- to.reserve(from.nelements());
+ to.resize(from.nelements());
for (unsigned i = 0; i < from.nelements(); ++i)
- to.append(convert::to<U>(from[i]));
+ to(i) = convert::to<U>(from[i]);
}
template <typename T>
@@ -209,9 +209,9 @@ namespace mln
void
from_to_(const std::vector<T>& from, fun::i2v::array<U>& to)
{
- to.reserve(from.nelements());
+ to.resize(from.nelements());
for (unsigned i = 0; i < from.size(); ++i)
- to.append(convert::to<U>(from[i]));
+ to(i) = convert::to<U>(from[i]);
}
diff --git a/milena/mln/util/array.hh b/milena/mln/util/array.hh
index b9f4798..b64511e 100644
--- a/milena/mln/util/array.hh
+++ b/milena/mln/util/array.hh
@@ -68,6 +68,10 @@ namespace mln
void
from_to_(const util::array<T1>& from, util::array<T2>& to);
+ template <typename T1, typename T2>
+ void
+ from_to_(const fun::i2v::array<T1>& from, util::array<T2>& to);
+
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
@@ -385,12 +389,23 @@ namespace mln
void
from_to_(const util::array<T1>& from, util::array<T2>& to)
{
- to.reserve(from.nelements());
+ to.resize(from.nelements());
for (unsigned i = 0; i < from.nelements(); ++i)
- to.append(convert::to<T2>(from[i]));
+ to[i] = convert::to<T2>(from[i]);
+ }
+
+ template <typename T1, typename T2>
+ void
+ from_to_(const fun::i2v::array<T1>& from, util::array<T2>& to)
+ {
+ to.resize(from.size());
+
+ for (unsigned i = 0; i < from.size(); ++i)
+ to[i] = convert::to<T2>(from(i));
}
+
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
--
1.5.6.5
1
0
* mln/canvas/labeling/blobs.hh: New. Make labeling blobs a canvas.
* mln/labeling/blobs.hh: Use the brand new canvas.
* mln/labeling/blobs_and_compute.hh: New routine.
---
milena/ChangeLog | 13 ++
milena/mln/canvas/labeling/blobs.hh | 179 ++++++++++++++++++++++++++++
milena/mln/labeling/blobs.hh | 88 ++++----------
milena/mln/labeling/blobs_and_compute.hh | 169 ++++++++++++++++++++++++++
milena/tests/labeling/Makefile.am | 2 +
milena/tests/labeling/blobs_and_compute.cc | 56 +++++++++
6 files changed, 441 insertions(+), 66 deletions(-)
create mode 100644 milena/mln/canvas/labeling/blobs.hh
create mode 100644 milena/mln/labeling/blobs_and_compute.hh
create mode 100644 milena/tests/labeling/blobs_and_compute.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 896aad1..31f5d3d 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,18 @@
2009-08-21 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add blobs_and_compute.
+
+ * mln/canvas/labeling/blobs.hh: New. Make labeling blobs a canvas.
+
+ * mln/labeling/blobs.hh: Use the brand new canvas.
+
+ * mln/labeling/blobs_and_compute.hh: New routine.
+
+ * milena/tests/labeling/Makefile.am,
+ * milena/tests/labeling/blobs_and_compute.cc: New test.
+
+2009-08-21 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Split canvas/labeling.hh into separate files.
* mln/canvas/labeling/all.hh,
diff --git a/milena/mln/canvas/labeling/blobs.hh b/milena/mln/canvas/labeling/blobs.hh
new file mode 100644
index 0000000..8f85541
--- /dev/null
+++ b/milena/mln/canvas/labeling/blobs.hh
@@ -0,0 +1,179 @@
+// 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 MLN_CANVAS_LABELING_BLOBS_HH
+# define MLN_CANVAS_LABELING_BLOBS_HH
+
+/// \file
+///
+/// Canvas for connected component labeling of the binary objects of a
+/// binary image using a queue-based algorithm.
+
+
+# include <mln/util/pix.hh>
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ namespace labeling
+ {
+
+ /*! \brief Canvas for connected component labeling of the binary
+ objects of a binary image using a queue-based algorithm.
+
+ \param[in] input The input image.
+ \param[in] nbh The connexity of the objects.
+ \param[out] nlabels The Number of labels. Its value is set in
+ the algorithms.
+ \param[in,out] functor A functor computing data while labeling.
+
+ \return The label image.
+
+ \pre The input image has to be binary (checked at compile-time).
+
+ A fast queue is used so that the algorithm is not recursive and
+ can handle large binary objects (blobs).
+ */
+ template <typename I, typename N, typename L, typename F>
+ mln_ch_value(I, L)
+ blobs(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ L& nlabels, F& functor);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // Implementations.
+
+ namespace impl
+ {
+
+ // Generic implementation.
+
+ namespace generic
+ {
+
+ template <typename I, typename N, typename L, typename F>
+ mln_ch_value(I, L)
+ blobs(const I& input, const N& nbh, L& nlabels, F& functor)
+ {
+ typedef mln_psite(I) P;
+
+ P cur;
+ mln_niter(N) n(nbh, cur);
+ p_queue_fast<P> qu;
+ const L zero = literal::zero;
+
+ // Initialization.
+ nlabels = literal::zero;
+ typedef mln_ch_value(I, L) out_t;
+ out_t output;
+ initialize(output, input);
+ data::fill(output, zero);
+ functor.init(); // <-- functor.init()
+
+ // Loop.
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ if (input(p) && output(p) == zero) // Object point, not labeled yet.
+ {
+ // Label this point component.
+ if (nlabels == mln_max(L))
+ {
+ trace::warning("labeling aborted! Too many labels \
+for this label type: nlabels > max(label_type).");
+
+ return output;
+ }
+ ++nlabels;
+ functor.new_label(nlabels); // <-- functor.new_label()
+ mln_invariant(qu.is_empty());
+ qu.push(p);
+ output(p) = nlabels;
+ functor.process_p(util::pix<out_t>(output, p)); // <-- functor.process_p()
+ do
+ {
+ cur = qu.front();
+ qu.pop();
+ for_all(n) if (input.has(n))
+ if (input(n) && output(n) == zero)
+ {
+ mln_invariant(! qu.compute_has(n));
+ qu.push(n);
+ output(n) = nlabels;
+ functor.process_n(util::pix<out_t>(output, n)); // <-- functor.process_n()
+ }
+ }
+ while (! qu.is_empty());
+ }
+
+ functor.finalize(); // <-- functor.finalize()
+ return output;
+ }
+
+ } // end of namespace mln::labeling::impl::generic
+
+ } // end of namespace mln::labeling::impl
+
+
+
+ // Facade.
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ blobs(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ L& nlabels, F& functor)
+ {
+ trace::entering("labeling::blobs");
+ mlc_equal(mln_trait_image_kind(I),
+ mln::trait::image::kind::binary)::check();
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ mln_precondition(input.is_valid());
+
+ // The only implementation is the generic one.
+ mln_ch_value(I, L)
+ output = impl::generic::blobs(input, nbh, nlabels, functor);
+
+ trace::exiting("labeling::blobs");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::canvas::labeling
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CANVAS_LABELING_BLOBS_HH
diff --git a/milena/mln/labeling/blobs.hh b/milena/mln/labeling/blobs.hh
index bfb7b4c..f63430f 100644
--- a/milena/mln/labeling/blobs.hh
+++ b/milena/mln/labeling/blobs.hh
@@ -41,6 +41,7 @@
# include <mln/data/fill.hh>
# include <mln/core/site_set/p_queue_fast.hh>
+# include <mln/canvas/labeling/blobs.hh>
namespace mln
@@ -71,76 +72,28 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
- namespace impl
+
+ namespace internal
{
- namespace generic
+ /// Functor not computing anything. To be passed to the labeling
+ /// blobs canvas.
+ template <typename L>
+ struct dummy_functor
{
+ void init() {}
- template <typename I, typename N, typename L>
- mln_ch_value(I, L)
- blobs_(const I& input, const N& nbh, L& nlabels)
- {
- typedef mln_psite(I) P;
-
- P cur;
- mln_niter(N) n(nbh, cur);
- p_queue_fast<P> qu;
- const L zero = literal::zero;
-
- // Initialization.
- nlabels = literal::zero;
- mln_ch_value(I, L) output;
- initialize(output, input);
- data::fill(output, zero);
-
- // Loop.
- mln_piter(I) p(input.domain());
- for_all(p)
- if (input(p) && output(p) == zero) // Object point, not labeled yet.
- {
- // Label this point component.
- if (nlabels == mln_max(L))
- {
- trace::warning("labeling aborted! Too many labels \
-for this label type: nlabels > max(label_type).");
-
- return output;
- }
- ++nlabels;
- mln_invariant(qu.is_empty());
- qu.push(p);
- output(p) = nlabels;
- do
- {
- cur = qu.front();
- qu.pop();
- for_all(n) if (input.has(n))
- if (input(n) && output(n) == zero)
- {
- mln_invariant(! qu.compute_has(n));
- qu.push(n);
- output(n) = nlabels;
- }
- }
- while (! qu.is_empty());
- }
-
- return output;
- }
-
- } // end of namespace mln::labeling::impl::generic
-
-
- template <typename I, typename N, typename L>
- mln_ch_value(I, L)
- blobs_(const I& input, const N& nbh, L& nlabels)
- {
- // The only implementation is the generic one.
- return generic::blobs_(input, nbh, nlabels);
- }
+ void new_label(const mln_value(L)&) {}
+
+ void process_p(const util::pix<L>&) {}
+
+ void process_n(const util::pix<L>&) {}
+
+ void finalize() {}
+ };
+
+ } // end of namespace mln::labeling::internal
- } // end of namespace mln::labeling::impl
// Facade.
@@ -158,7 +111,10 @@ for this label type: nlabels > max(label_type).");
const N& nbh = exact(nbh_);
mln_precondition(input.is_valid());
- mln_ch_value(I, L) output = impl::blobs_(input, nbh, nlabels);
+ typedef mln_ch_value(I,L) out_t;
+ internal::dummy_functor<out_t> functor;
+ out_t
+ output = canvas::labeling::blobs(input, nbh, nlabels, functor);
trace::exiting("labeling::blobs");
return output;
diff --git a/milena/mln/labeling/blobs_and_compute.hh b/milena/mln/labeling/blobs_and_compute.hh
new file mode 100644
index 0000000..4d5d5d8
--- /dev/null
+++ b/milena/mln/labeling/blobs_and_compute.hh
@@ -0,0 +1,169 @@
+// 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 MLN_LABELING_BLOBS_AND_COMPUTE_HH
+# define MLN_LABELING_BLOBS_AND_COMPUTE_HH
+
+/// \file
+///
+/// Label an image and compute given accumulators.
+
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+
+# include <mln/labeling/blobs.hh>
+# include <mln/labeling/compute.hh>
+
+
+namespace mln
+{
+
+ namespace labeling
+ {
+
+ /*! Label an image and compute given accumulators.
+
+ \param[in] input A binary image.
+ \param[in] nbh A neighborhood used for labeling.
+ \param[in,out] nlabels The number of labels found.
+ \param[in] accu An accumulator to be computed while labeling.
+
+ */
+ template <typename I, typename N, typename L, typename A>
+ util::couple<mln_ch_value(I, L), util::array<mln_result(A)> >
+ blobs_and_compute(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nlabels, const Accumulator<A>& accu);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ /// Functor not computing anything. To be passed to the labeling
+ /// blobs canvas.
+ template <typename L, typename A>
+ struct compute_functor
+ {
+ typedef mln_result(A) accu_result;
+ typedef mln_argument(A) accu_argument;
+ typedef util::array<accu_result> result;
+
+ void init()
+ {
+ // FIXME: arbitrary value...
+ accus_.reserve(static_cast<unsigned>(mln_max(mln_value(L))) / 2);
+ accus_.append(A());
+ }
+
+ void new_label(const mln_value(L)& l)
+ {
+ current_lbl_ = l;
+ accus_.append(A());
+ }
+
+ void process_p(const util::pix<L>& pix)
+ {
+ process_(accu_argument(), pix);
+ }
+
+ void process_n(const util::pix<L>& pix)
+ {
+ process_(accu_argument(), pix);
+ }
+
+ void finalize()
+ {
+ convert::from_to(accus_, result_);
+ }
+
+
+ private:
+ void process_(const mln_psite(L)&, const util::pix<L>& pix)
+ {
+ accus_[current_lbl_].take(pix.p());
+ }
+
+ void process_(const mln_value(L)&, const util::pix<L>& pix)
+ {
+ accus_[current_lbl_].take(pix.v());
+ }
+
+ void process_(const util::pix<L>&, const util::pix<L>& pix)
+ {
+ accus_[current_lbl_].take(pix);
+ }
+
+ public:
+ util::array<mln_result(A)> result_;
+ util::array<A> accus_;
+ mln_value(L) current_lbl_;
+ };
+
+ } // end of namespace mln::labeling::internal
+
+
+
+ // Facade.
+
+
+ template <typename I, typename N, typename L, typename A>
+ util::couple<mln_ch_value(I,L), util::array<mln_result(A)> >
+ blobs_and_compute(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nlabels, const Accumulator<A>& accu)
+ {
+ trace::entering("labeling::blobs_and_compute");
+
+ (void) accu;
+ mlc_equal(mln_trait_image_kind(I),
+ mln::trait::image::kind::binary)::check();
+ mln_precondition(exact(input).is_valid());
+
+ typedef mln_ch_value(I,L) out_t;
+ typedef internal::compute_functor<out_t,A> func_t;
+ func_t functor;
+ out_t
+ output = canvas::labeling::blobs(input, nbh, nlabels, functor);
+
+ util::couple<out_t, typename func_t::result>
+ result = make::couple(output, functor.result_);
+
+ trace::exiting("labeling::blobs_and_compute");
+ return result;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace mln::labeling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LABELING_BLOBS_AND_COMPUTE_HH
diff --git a/milena/tests/labeling/Makefile.am b/milena/tests/labeling/Makefile.am
index 8ec17c4..1509d72 100644
--- a/milena/tests/labeling/Makefile.am
+++ b/milena/tests/labeling/Makefile.am
@@ -22,6 +22,7 @@ include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
background \
blobs \
+ blobs_and_compute \
colorize \
compute \
fill_holes \
@@ -38,6 +39,7 @@ check_PROGRAMS = \
background_SOURCES = background.cc
blobs_SOURCES = blobs.cc
+blobs_and_compute_SOURCES = blobs_and_compute.cc
colorize_SOURCES = colorize.cc
compute_SOURCES = compute.cc
fill_holes_SOURCES = fill_holes.cc
diff --git a/milena/tests/labeling/blobs_and_compute.cc b/milena/tests/labeling/blobs_and_compute.cc
new file mode 100644
index 0000000..8516bba
--- /dev/null
+++ b/milena/tests/labeling/blobs_and_compute.cc
@@ -0,0 +1,56 @@
+// 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.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/io/pbm/load.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/accu/center.hh>
+#include <mln/labeling/blobs_and_compute.hh>
+#include <mln/util/array.hh>
+#include <mln/util/couple.hh>
+#include <mln/value/label_8.hh>
+
+#include "tests/data.hh"
+
+
+int main()
+{
+ using namespace mln;
+
+ image2d<bool> pic = io::pbm::load(MLN_IMG_DIR "/picasso.pbm");
+ value::label_8 n;
+
+
+ typedef image2d<value::label_8> L;
+ typedef util::array<point2d> arr_t;
+ typedef util::couple<L,arr_t> res_t;
+ res_t result = labeling::blobs_and_compute(pic, c4(), n,
+ accu::center<point2d,point2d>());
+
+ mln_assertion(result.second().size() == 34);
+ mln_assertion(result.second()[1] == point2d(10,30));
+ mln_assertion(result.second()[33] == point2d(310,66));
+ mln_assertion(n == 33);
+}
--
1.5.6.5
1
0
* mln/canvas/labeling/all.hh,
* mln/canvas/labeling/essential.hh: New.
* mln/canvas/labeling.hh: Move and split into...
* mln/canvas/labeling/generic.hh,
* mln/canvas/labeling/internal/find_root_fastest.hh,
* mln/canvas/labeling/internal/tests.hh,
* mln/canvas/labeling/sorted.hh,
* mln/canvas/labeling/video.hh: ... these files.
* tests/labeling/flat_zones.cc,
* 6tests/labeling/foreground.cc,
* mln/canvas/all.hh,
* mln/canvas/essential.hh,
* mln/labeling/flat_zones.hh,
* mln/labeling/regional_maxima.hh,
* mln/labeling/regional_minima.hh,
* mln/labeling/value.hh: Update includes and function calls.
---
milena/ChangeLog | 24 +
milena/mln/canvas/all.hh | 2 +-
milena/mln/canvas/essential.hh | 5 +-
milena/mln/canvas/labeling.hh | 616 --------------------
milena/mln/canvas/{ => labeling}/all.hh | 31 +-
milena/mln/canvas/{ => labeling}/essential.hh | 21 +-
milena/mln/canvas/labeling/generic.hh | 193 ++++++
.../internal/find_root_fastest.hh} | 52 ++-
.../canvas/{all.hh => labeling/internal/tests.hh} | 59 ++-
milena/mln/canvas/labeling/sorted.hh | 283 +++++++++
milena/mln/canvas/labeling/video.hh | 262 +++++++++
milena/mln/labeling/flat_zones.hh | 8 +-
milena/mln/labeling/regional_maxima.hh | 9 +-
milena/mln/labeling/regional_minima.hh | 13 +-
milena/mln/labeling/value.hh | 11 +-
milena/tests/labeling/flat_zones.cc | 21 +-
milena/tests/labeling/foreground.cc | 9 +-
17 files changed, 908 insertions(+), 711 deletions(-)
delete mode 100644 milena/mln/canvas/labeling.hh
copy milena/mln/canvas/{ => labeling}/all.hh (68%)
copy milena/mln/canvas/{ => labeling}/essential.hh (73%)
create mode 100644 milena/mln/canvas/labeling/generic.hh
copy milena/mln/canvas/{all.hh => labeling/internal/find_root_fastest.hh} (59%)
copy milena/mln/canvas/{all.hh => labeling/internal/tests.hh} (52%)
create mode 100644 milena/mln/canvas/labeling/sorted.hh
create mode 100644 milena/mln/canvas/labeling/video.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 1d495c1..896aad1 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,27 @@
+2009-08-21 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Split canvas/labeling.hh into separate files.
+
+ * mln/canvas/labeling/all.hh,
+ * mln/canvas/labeling/essential.hh: New.
+
+ * mln/canvas/labeling.hh: Move and split into...
+
+ * mln/canvas/labeling/generic.hh,
+ * mln/canvas/labeling/internal/find_root_fastest.hh,
+ * mln/canvas/labeling/internal/tests.hh,
+ * mln/canvas/labeling/sorted.hh,
+ * mln/canvas/labeling/video.hh: ... these files.
+
+ * tests/labeling/flat_zones.cc,
+ * tests/labeling/foreground.cc,
+ * mln/canvas/all.hh,
+ * mln/canvas/essential.hh,
+ * mln/labeling/flat_zones.hh,
+ * mln/labeling/regional_maxima.hh,
+ * mln/labeling/regional_minima.hh,
+ * mln/labeling/value.hh: Update includes and function calls.
+
2009-08-21 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
Remove extra ";" to compile.
diff --git a/milena/mln/canvas/all.hh b/milena/mln/canvas/all.hh
index b5ae38c..76ee819 100644
--- a/milena/mln/canvas/all.hh
+++ b/milena/mln/canvas/all.hh
@@ -50,7 +50,7 @@ namespace mln
# include <mln/canvas/chamfer.hh>
# include <mln/canvas/distance_front.hh>
# include <mln/canvas/distance_geodesic.hh>
-# include <mln/canvas/labeling.hh>
+# include <mln/canvas/labeling/all.hh>
#endif // ! MLN_CANVAS_ALL_HH
diff --git a/milena/mln/canvas/essential.hh b/milena/mln/canvas/essential.hh
index 88ea809..5184aae 100644
--- a/milena/mln/canvas/essential.hh
+++ b/milena/mln/canvas/essential.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -34,6 +35,6 @@
# include <mln/canvas/browsing/essential.hh>
# include <mln/canvas/morpho/essential.hh>
# include <mln/canvas/chamfer.hh>
-# include <mln/canvas/labeling.hh>
+# include <mln/canvas/labeling/essential.hh>
#endif // ! MLN_CANVAS_ESSENTIAL_HH
diff --git a/milena/mln/canvas/labeling.hh b/milena/mln/canvas/labeling.hh
deleted file mode 100644
index c999380..0000000
--- a/milena/mln/canvas/labeling.hh
+++ /dev/null
@@ -1,616 +0,0 @@
-// Copyright (C) 2007, 2008, 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 MLN_CANVAS_LABELING_HH
-# define MLN_CANVAS_LABELING_HH
-
-/// \file
-///
-/// Connected component labeling of the object part in a binary image.
-///
-/// \todo Can we get rid of 'deja_vu' (while playing with the border)
-/// in the fastest video version?
-
-# include <mln/core/concept/image.hh>
-# include <mln/data/fill.hh>
-# include <mln/literal/zero.hh>
-# include <mln/convert/to_upper_window.hh>
-# include <mln/extension/adjust_fill.hh>
-
-# include <mln/data/sort_psites.hh>
-# include <mln/data/sort_offsets.hh>
-
-
-namespace mln
-{
-
- namespace canvas
- {
-
- template <typename I, typename N, typename L,
- typename F>
- mln_ch_value(I, L)
- labeling_video(const Image<I>& input, const Neighborhood<N>& nbh, L& nlabels,
- F& functor);
-
-
- template <typename I, typename N, typename L,
- typename F>
- mln_ch_value(I, L)
- labeling_sorted(const Image<I>& input, const Neighborhood<N>& nbh, L& nlabels,
- F& functor, bool increasing);
-
-
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- // Tests.
-
- namespace internal
- {
-
- template <typename I, typename N, typename L,
- typename F>
- void
- labeling_tests(const Image<I>& input_, const Neighborhood<N>& nbh_, const L& nlabels,
- const F& f)
- {
- const I& input = exact(input_);
- const N& nbh = exact(nbh_);
-
- mln_precondition(input.is_valid());
- // mln_precondition(nbh.is_valid());
-
- (void) input;
- (void) nbh;
- (void) nlabels;
- (void) f;
- }
-
- } // end of namespace mln::canvas::internal
-
-
-
- // Implementations.
-
- namespace impl
- {
-
- namespace generic
- {
-
- template <typename I>
- static inline
- mln_psite(I)
- find_root(I& parent, const mln_psite(I)& x)
- {
- if (parent(x) == x)
- return x;
- else
- return parent(x) = find_root(parent, parent(x));
- }
-
- template <typename I, typename N, typename L,
- typename S, typename F>
- mln_ch_value(I, L)
- labeling(const Image<I>& input_, const Neighborhood<N>& nbh_, L& nlabels,
- const Site_Set<S>& s_, F& f)
- {
- trace::entering("canvas::impl::generic::labeling");
-
- // FIXME: Test?!
-
- const I& input = exact(input_);
- const N& nbh = exact(nbh_);
- const S& s = exact(s_);
-
- // Local type.
- typedef mln_psite(I) P;
-
- // Auxiliary data.
- mln_ch_value(I, bool) deja_vu;
- mln_ch_value(I, P) parent;
-
- // Output.
- mln_ch_value(I, L) output;
- bool status; // FIXME: Is-it useful?
-
- // Initialization.
- {
- initialize(deja_vu, input);
- mln::data::fill(deja_vu, false);
-
- initialize(parent, input);
-
- initialize(output, input);
- mln::data::fill(output, L(literal::zero));
- nlabels = 0;
-
- f.init(); // Client initialization.
- }
-
- // First Pass.
- {
- mln_bkd_piter(S) p(s); // Backward.
- mln_niter(N) n(nbh, p);
- for_all(p) if (f.handles(p))
- {
- // Make-Set.
- parent(p) = p;
- f.init_attr(p);
-
- for_all(n)
- if (input.domain().has(n) && deja_vu(n))
- {
- if (f.equiv(n, p))
- {
- // Do-Union.
- P r = find_root(parent, n);
- if (r != p)
- {
- parent(r) = p;
- f.merge_attr(r, p);
- }
- }
- else
- f.do_no_union(n, p);
- }
- deja_vu(p) = true;
- }
- }
-
- // Second Pass.
- {
- mln_fwd_piter(S) p(s); // Forward.
- for_all(p) if (f.handles(p))
- {
- if (parent(p) == p) // if p is root
- {
- if (f.labels(p))
- {
- if (nlabels == mln_max(L))
- {
- status = false;
- trace::warning("labeling aborted! Too many labels \
- for this label type: nlabels > \
- max(label_type).");
-
- return output;
- }
- output(p) = ++nlabels;
- }
- }
- else
- output(p) = output(parent(p));
- }
- status = true;
- }
-
- trace::exiting("canvas::impl::generic::labeling");
- return output;
- }
-
- } // end of namespace mln::canvas::impl::generic
-
-
-
- // Fastest video version.
-
- template <typename I>
- static inline
- unsigned
- find_root_fastest(I& parent, unsigned x)
- {
- if (parent.element(x) == x)
- return x;
- else
- return parent.element(x) = find_root_fastest(parent, parent.element(x));
- }
-
-
- template <typename I, typename N, typename L,
- typename F>
- mln_ch_value(I, L)
- labeling_video_fastest(const Image<I>& input_, const Neighborhood<N>& nbh_,
- L& nlabels, F& f)
- {
- trace::entering("canvas::impl::labeling_video_fastest");
-
- // FIXME: Test?!
-
- const I& input = exact(input_);
- const N& nbh = exact(nbh_);
-
- extension::adjust(input, nbh);
-
- // Auxiliary data.
- mln_ch_value(I, bool) deja_vu;
- mln_ch_value(I, unsigned) parent;
-
- // Output.
- mln_ch_value(I, L) output;
- bool status;
-
- // Initialization.
- {
- initialize(deja_vu, input);
- mln::data::fill(deja_vu, true);
- extension::fill(deja_vu, false); // So that the extension is ignored.
-
- initialize(parent, input);
-
- initialize(output, input);
- mln::data::fill(output, L(literal::zero));
- nlabels = 0;
-
- f.init_(); // Client initialization.
- }
-
- // First Pass.
- {
- util::array<int> dp = positive_offsets_wrt(input, nbh);
- const unsigned n_nbhs = dp.nelements();
-
- mln_bkd_pixter(const I) px(input); // Backward.
- for_all(px)
- {
- unsigned p = px.offset();
- if (! f.handles_(p))
- continue;
-
- // Make-Set.
- parent.element(p) = p;
- f.init_attr_(p);
- for (unsigned i = 0; i < n_nbhs; ++i)
- {
- unsigned n = p + dp[i];
- if (deja_vu.element(n)) // Only false in the external border.
- {
- if (f.equiv_(n, p))
- {
- // Do-Union.
- unsigned r = find_root_fastest(parent, n);
- if (r != p)
- {
- parent.element(r) = p;
- f.merge_attr_(r, p);
- }
- }
- else
- f.do_no_union_(n, p);
- }
- }
- }
- }
-
- // Second Pass.
- {
- mln_fwd_pixter(const I) px(input); // Forward.
- for_all(px)
- {
- unsigned p = px.offset();
- if (! f.handles_(p))
- continue;
- if (parent.element(p) == p) // if p is root
- {
- if (f.labels_(p))
- {
- if (nlabels == mln_max(L))
- {
- status = false;
- trace::warning("labeling aborted! Too many labels for \
- this label type: nlabels > \
- max(label_type).");
- return output;
- }
- output.element(p) = ++nlabels;
- }
- }
- else
- output.element(p) = output.element(parent.element(p));
- }
- status = true;
- }
-
- trace::exiting("canvas::impl::labeling_video_fastest");
- return output;
- }
-
-
-
- // Fastest sorted version
-
- template <typename I, typename N, typename L,
- typename S, typename F>
- mln_ch_value(I, L)
- labeling_sorted_fastest(const Image<I>& input_, const Neighborhood<N>& nbh_, L& nlabels,
- const S& s, F& f)
- {
- trace::entering("canvas::impl::labeling_sorted_fastest");
-
- // FIXME: Test?!
-
- const I& input = exact(input_);
- const N& nbh = exact(nbh_);
-
- extension::adjust(input, nbh);
-
- // Local type.
- typedef mln_psite(I) P;
-
- // Auxiliary data.
- mln_ch_value(I, bool) deja_vu;
- mln_ch_value(I, unsigned) parent;
-
- // Output.
- mln_ch_value(I, L) output;
- bool status;
-
- // Initialization.
- {
- initialize(deja_vu, input);
- mln::data::fill(deja_vu, false);
- extension::fill(deja_vu, false); // So that the extension is ignored.
-
- initialize(parent, input);
-
- initialize(output, input);
- mln::data::fill(output, L(literal::zero));
- nlabels = 0;
-
- f.init_(); // Client initialization.
- }
-
- util::array<int> dp = offsets_wrt(input, nbh);
- const unsigned n_nbhs = dp.nelements();
-
- const unsigned n_points = s.nelements();
-
- // First Pass.
- {
- for (int i = n_points - 1; i >=0; --i) // Backward.
- {
- unsigned p = s[i];
- if (! f.handles_(p))
- continue;
-
- // Make-Set.
- parent.element(p) = p;
- f.init_attr_(p);
-
- for (unsigned j = 0; j < n_nbhs; ++j)
- {
- unsigned n = p + dp[j];
- if (! deja_vu.element(n))
- continue;
-
- if (f.equiv_(n, p))
- {
- // Do-Union.
- unsigned r = find_root_fastest(parent, n);
- if (r != p)
- {
- parent.element(r) = p;
- f.merge_attr_(r, p);
- }
- }
- else
- f.do_no_union_(n, p);
- }
- deja_vu.element(p) = true;
- }
- }
-
- // Second Pass.
- {
- for (unsigned i = 0; i < n_points; ++i) // Forward.
- {
- unsigned p = s[i];
- if (! f.handles_(p))
- continue;
-
- if (parent.element(p) == p) // if p is root
- {
- if (f.labels_(p))
- {
- if (nlabels == mln_max(L))
- {
- status = false;
- trace::warning("labeling aborted! Too many labels \
- for this label type: nlabels > \
- max(label_type).");
- return output;
- }
- output.element(p) = ++nlabels;
- }
- }
- else
- output.element(p) = output.element(parent.element(p));
- }
- status = true;
- }
-
- trace::exiting("canvas::impl::labeling_sorted_fastest");
- return output;
- }
-
- } // end of namespace mln::canvas::impl
-
-
-
- // Dispatch.
-
- namespace internal
- {
-
- // Video
-
- template <typename I, typename N, typename L,
- typename F>
- inline
- mln_ch_value(I, L)
- labeling_video_dispatch(metal::false_,
- const Image<I>& input, const Neighborhood<N>& nbh, L& nlabels,
- F& functor)
- {
- return impl::generic::labeling(input, nbh, nlabels, exact(input).domain(),
- functor);
- }
-
- template <typename I, typename N, typename L,
- typename F>
- inline
- mln_ch_value(I, L)
- labeling_video_dispatch(metal::true_,
- const Image<I>& input, const Neighborhood<N>& nbh, L& nlabels,
- F& functor)
- {
- return impl::labeling_video_fastest(input, nbh, nlabels, functor);
- }
-
- template <typename I, typename N, typename L,
- typename F>
- inline
- mln_ch_value(I, L)
- labeling_video_dispatch(const Image<I>& input, const Neighborhood<N>& nbh, L& nlabels,
- F& functor)
- {
- enum {
- test = mlc_equal(mln_trait_image_speed(I),
- trait::image::speed::fastest)::value
- &&
- mln_is_simple_neighborhood(N)::value
- };
- return labeling_video_dispatch(metal::bool_<test>(),
- input, nbh, nlabels,
- functor);
- }
-
-
- // Sorted dispatch.
-
- template <typename I, typename N, typename L, typename F>
- inline
- mln_ch_value(I, L)
- labeling_sorted_dispatch(metal::false_,
- const Image<I>& input, const Neighborhood<N>& nbh, L& nlabels,
- F& functor, bool increasing)
- {
- p_array<mln_psite(I)> s =
- increasing ?
- data::sort_psites_increasing(input) :
- data::sort_psites_decreasing(input);
- return impl::generic::labeling(input, nbh, nlabels, s,
- functor);
- }
-
- template <typename I, typename N, typename L, typename F>
- inline
- mln_ch_value(I, L)
- labeling_sorted_dispatch(metal::true_,
- const Image<I>& input, const Neighborhood<N>& nbh, L& nlabels,
- F& functor, bool increasing)
- {
- util::array<unsigned> s =
- increasing ?
- data::sort_offsets_increasing(input) :
- data::sort_offsets_decreasing(input);
- return impl::labeling_sorted_fastest(input, nbh, nlabels, s,
- functor);
- }
-
- template <typename I, typename N, typename L, typename F>
- inline
- mln_ch_value(I, L)
- labeling_sorted_dispatch(const Image<I>& input, const Neighborhood<N>& nbh, L& nlabels,
- F& functor, bool increasing)
- {
- enum {
- test = mlc_equal(mln_trait_image_speed(I),
- trait::image::speed::fastest)::value
- &&
- mln_is_simple_neighborhood(N)::value
- };
- return labeling_sorted_dispatch(metal::bool_<test>(),
- input, nbh, nlabels,
- functor, increasing);
- }
-
-
- } // end of namespace mln::canvas::internal
-
-
-
- // Facades.
-
-
- template <typename I, typename N, typename L,
- typename F>
- inline
- mln_ch_value(I, L)
- labeling_video(const Image<I>& input, const Neighborhood<N>& nbh, L& nlabels,
- F& functor)
- {
- trace::entering("canvas::labeling_video");
-
- internal::labeling_tests(input, nbh, nlabels, functor);
-
- mln_ch_value(I, L) output;
- output = internal::labeling_video_dispatch(input, nbh, nlabels,
- functor);
-
- trace::exiting("canvas::labeling_video");
- return output;
- }
-
-
- template <typename I, typename N, typename L,
- typename F>
- inline
- mln_ch_value(I, L)
- labeling_sorted(const Image<I>& input, const Neighborhood<N>& nbh, L& nlabels,
- F& functor, bool increasing)
- {
- trace::entering("canvas::labeling_sorted");
-
- internal::labeling_tests(input, nbh, nlabels, functor);
-
- mln_ch_value(I, L) output;
- output = internal::labeling_sorted_dispatch(input, nbh, nlabels,
- functor, increasing);
-
- trace::exiting("canvas::labeling_sorted");
- return output;
- }
-
-# endif // ! MLN_INCLUDE_ONLY
-
- } // end of namespace mln::canvas
-
-} // end of namespace mln
-
-
-#endif // ! MLN_CANVAS_LABELING_HH
diff --git a/milena/mln/canvas/all.hh b/milena/mln/canvas/labeling/all.hh
similarity index 68%
copy from milena/mln/canvas/all.hh
copy to milena/mln/canvas/labeling/all.hh
index b5ae38c..5ee97de 100644
--- a/milena/mln/canvas/all.hh
+++ b/milena/mln/canvas/labeling/all.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,12 +23,12 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_CANVAS_ALL_HH
-# define MLN_CANVAS_ALL_HH
+#ifndef MLN_CANVAS_LABELING_ALL_HH
+# define MLN_CANVAS_LABELING_ALL_HH
/// \file
///
-/// File that includes all canvas-related routines.
+/// File that includes all labeling canvas-related routines.
namespace mln
@@ -38,19 +38,22 @@ namespace mln
namespace canvas
{
- /// Implementation namespace of canvas namespace.
- namespace impl {}
+ /// Namespace of labeling canvas.
+ namespace labeling
+ {
+
+ /// Implementation namespace of labeling canvas namespace.
+ namespace impl {}
+
+ }
}
}
-
-# include <mln/canvas/browsing/all.hh>
-# include <mln/canvas/morpho/all.hh>
-# include <mln/canvas/chamfer.hh>
-# include <mln/canvas/distance_front.hh>
-# include <mln/canvas/distance_geodesic.hh>
-# include <mln/canvas/labeling.hh>
+# include <mln/canvas/labeling/blobs.hh>
+# include <mln/canvas/labeling/generic.hh>
+# include <mln/canvas/labeling/video.hh>
+# include <mln/canvas/labeling/sorted.hh>
-#endif // ! MLN_CANVAS_ALL_HH
+#endif // ! MLN_CANVAS_LABELING_ALL_HH
diff --git a/milena/mln/canvas/essential.hh b/milena/mln/canvas/labeling/essential.hh
similarity index 73%
copy from milena/mln/canvas/essential.hh
copy to milena/mln/canvas/labeling/essential.hh
index 88ea809..a68bec4 100644
--- a/milena/mln/canvas/essential.hh
+++ b/milena/mln/canvas/labeling/essential.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,17 +23,14 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_CANVAS_ESSENTIAL_HH
-# define MLN_CANVAS_ESSENTIAL_HH
+#ifndef MLN_CANVAS_LABELING_ESSENTIAL_HH
+# define MLN_CANVAS_LABELING_ESSENTIAL_HH
-/*! \file
- *
- * \brief File that includes the most useful canvas-related routines.
- */
+/// \file
+///
+/// File that includes essential labeling canvas-related routines.
-# include <mln/canvas/browsing/essential.hh>
-# include <mln/canvas/morpho/essential.hh>
-# include <mln/canvas/chamfer.hh>
-# include <mln/canvas/labeling.hh>
-#endif // ! MLN_CANVAS_ESSENTIAL_HH
+# include <mln/canvas/labeling/all.hh>
+
+#endif // ! MLN_CANVAS_LABELING_ESSENTIAL_HH
diff --git a/milena/mln/canvas/labeling/generic.hh b/milena/mln/canvas/labeling/generic.hh
new file mode 100644
index 0000000..b701e42
--- /dev/null
+++ b/milena/mln/canvas/labeling/generic.hh
@@ -0,0 +1,193 @@
+// 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 MLN_CANVAS_LABELING_GENERIC_HH
+# define MLN_CANVAS_LABELING_GENERIC_HH
+
+/// \file
+///
+/// Generic Connected component labeling of the object part in a
+/// binary image.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/concept/site_set.hh>
+
+# include <mln/data/fill.hh>
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ namespace labeling
+ {
+
+ namespace impl
+ {
+
+ namespace generic
+ {
+
+ /// Generic Connected component labeling of the object part in a
+ /// binary image.
+ //
+ template <typename I, typename N, typename L,
+ typename S, typename F>
+ mln_ch_value(I, L)
+ labeling(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ L& nlabels, const Site_Set<S>& s_, F& f);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ static inline
+ mln_psite(I)
+ find_root(I& parent, const mln_psite(I)& x)
+ {
+ if (parent(x) == x)
+ return x;
+ else
+ return parent(x) = find_root(parent, parent(x));
+ }
+
+
+
+ template <typename I, typename N, typename L,
+ typename S, typename F>
+ mln_ch_value(I, L)
+ labeling(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ L& nlabels, const Site_Set<S>& s_, F& f)
+ {
+ trace::entering("canvas::labeling::impl::generic::labeling");
+
+ // FIXME: Test?!
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ const S& s = exact(s_);
+
+ // Local type.
+ typedef mln_psite(I) P;
+
+ // Auxiliary data.
+ mln_ch_value(I, bool) deja_vu;
+ mln_ch_value(I, P) parent;
+
+ // Output.
+ mln_ch_value(I, L) output;
+ bool status; // FIXME: Is-it useful?
+
+ // Initialization.
+ {
+ initialize(deja_vu, input);
+ mln::data::fill(deja_vu, false);
+
+ initialize(parent, input);
+
+ initialize(output, input);
+ mln::data::fill(output, L(literal::zero));
+ nlabels = 0;
+
+ f.init(); // <-- f.init() - Client initialization.
+ }
+
+ // First Pass.
+ {
+ mln_bkd_piter(S) p(s); // Backward.
+ mln_niter(N) n(nbh, p);
+ for_all(p) if (f.handles(p)) // <-- f.handles()
+ {
+ // Make-Set.
+ parent(p) = p;
+ f.init_attr(p);
+
+ for_all(n)
+ if (input.domain().has(n) && deja_vu(n))
+ {
+ if (f.equiv(n, p)) // <-- f.equiv()
+ {
+ // Do-Union.
+ P r = find_root(parent, n);
+ if (r != p)
+ {
+ parent(r) = p;
+ f.merge_attr(r, p); // <-- f.merge_attr()
+ }
+ }
+ else
+ f.do_no_union(n, p); // <-- f.do_no_union()
+ }
+ deja_vu(p) = true;
+ }
+ }
+
+ // Second Pass.
+ {
+ mln_fwd_piter(S) p(s); // Forward.
+ for_all(p) if (f.handles(p)) // <-- f.handles()
+ {
+ if (parent(p) == p) // if p is root
+ {
+ if (f.labels(p)) // <-- f.labels()
+ {
+ if (nlabels == mln_max(L))
+ {
+ status = false;
+ trace::warning("labeling aborted! Too many labels \
+ for this label type: nlabels > \
+ max(label_type).");
+
+ return output;
+ }
+ output(p) = ++nlabels;
+ }
+ }
+ else
+ output(p) = output(parent(p));
+ }
+ status = true;
+ }
+
+ trace::exiting("canvas::labeling::impl::generic::labeling");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::canvas::labeling::impl::generic
+
+ } // end of namespace mln::canvas::labeling::impl
+
+ } // end of namespace mln::canvas::labeling
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CANVAS_LABELING_GENERIC_HH
diff --git a/milena/mln/canvas/all.hh b/milena/mln/canvas/labeling/internal/find_root_fastest.hh
similarity index 59%
copy from milena/mln/canvas/all.hh
copy to milena/mln/canvas/labeling/internal/find_root_fastest.hh
index b5ae38c..8af3eac 100644
--- a/milena/mln/canvas/all.hh
+++ b/milena/mln/canvas/labeling/internal/find_root_fastest.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,34 +23,52 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_CANVAS_ALL_HH
-# define MLN_CANVAS_ALL_HH
+#ifndef MLN_CANVAS_LABELING_INTERNAL_FIND_ROOT_FASTEST_HH
+# define MLN_CANVAS_LABELING_INTERNAL_FIND_ROOT_FASTEST_HH
/// \file
///
-/// File that includes all canvas-related routines.
-
+/// Shared 'find root' function for labeling canvas.
namespace mln
{
- /// Namespace of canvas.
namespace canvas
{
- /// Implementation namespace of canvas namespace.
- namespace impl {}
+ namespace labeling
+ {
+
+ namespace internal
+ {
+
+ template <typename I>
+ unsigned
+ find_root_fastest(I& parent, unsigned x);
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ inline
+ unsigned
+ find_root_fastest(I& parent, unsigned x)
+ {
+ if (parent.element(x) == x)
+ return x;
+ else
+ return parent.element(x) = find_root_fastest(parent,
+ parent.element(x));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
- }
-}
+ } // end of namespace mln::canvas::internal
+ } // end of namespace mln::canvas::labeling
-# include <mln/canvas/browsing/all.hh>
-# include <mln/canvas/morpho/all.hh>
-# include <mln/canvas/chamfer.hh>
-# include <mln/canvas/distance_front.hh>
-# include <mln/canvas/distance_geodesic.hh>
-# include <mln/canvas/labeling.hh>
+ } // end of namespace mln::canvas
+} // end of namespace mln
-#endif // ! MLN_CANVAS_ALL_HH
+#endif // ! MLN_CANVAS_LABELING_INTERNAL_FIND_ROOT_FASTEST_HH
diff --git a/milena/mln/canvas/all.hh b/milena/mln/canvas/labeling/internal/tests.hh
similarity index 52%
copy from milena/mln/canvas/all.hh
copy to milena/mln/canvas/labeling/internal/tests.hh
index b5ae38c..d1b9cf7 100644
--- a/milena/mln/canvas/all.hh
+++ b/milena/mln/canvas/labeling/internal/tests.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,34 +23,59 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_CANVAS_ALL_HH
-# define MLN_CANVAS_ALL_HH
+#ifndef MLN_CANVAS_LABELING_INTERNAL_TESTS_HH
+# define MLN_CANVAS_LABELING_INTERNAL_TESTS_HH
/// \file
///
-/// File that includes all canvas-related routines.
-
+/// Shared tests for labeling canvas arguments.
namespace mln
{
- /// Namespace of canvas.
namespace canvas
{
- /// Implementation namespace of canvas namespace.
- namespace impl {}
+ namespace labeling
+ {
+
+ namespace internal
+ {
+
+
+ template <typename I, typename N, typename L, typename F>
+ void
+ labeling_tests(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ const L& nlabels, const F& f);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename N, typename L, typename F>
+ void
+ labeling_tests(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ const L& nlabels, const F& f)
+ {
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+
+ mln_precondition(input.is_valid());
+ // mln_precondition(nbh.is_valid());
+
+ (void) input;
+ (void) nbh;
+ (void) nlabels;
+ (void) f;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
- }
-}
+ } // end of namespace mln::canvas::internal
+ } // end of namespace mln::canvas::labeling
-# include <mln/canvas/browsing/all.hh>
-# include <mln/canvas/morpho/all.hh>
-# include <mln/canvas/chamfer.hh>
-# include <mln/canvas/distance_front.hh>
-# include <mln/canvas/distance_geodesic.hh>
-# include <mln/canvas/labeling.hh>
+ } // end of namespace mln::canvas
+} // end of namespace mln
-#endif // ! MLN_CANVAS_ALL_HH
+#endif // ! MLN_CANVAS_LABELING_INTERNAL_TESTS_HH
diff --git a/milena/mln/canvas/labeling/sorted.hh b/milena/mln/canvas/labeling/sorted.hh
new file mode 100644
index 0000000..4f7dd5f
--- /dev/null
+++ b/milena/mln/canvas/labeling/sorted.hh
@@ -0,0 +1,283 @@
+// 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 MLN_CANVAS_LABELING_SORTED_HH
+# define MLN_CANVAS_LABELING_SORTED_HH
+
+/// \file
+///
+/// Fast connected component labeling of the object part in a binary image.
+
+
+# include <mln/core/concept/image.hh>
+# include <mln/data/fill.hh>
+# include <mln/literal/zero.hh>
+# include <mln/extension/adjust_fill.hh>
+
+# include <mln/data/sort_psites.hh>
+# include <mln/data/sort_offsets.hh>
+
+# include <mln/canvas/labeling/generic.hh>
+# include <mln/canvas/labeling/internal/tests.hh>
+# include <mln/canvas/labeling/internal/find_root_fastest.hh>
+
+
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ namespace labeling
+ {
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ sorted(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nlabels, F& functor, bool increasing);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // Implementations.
+
+ namespace impl
+ {
+
+ // Fastest sorted version
+
+ template <typename I, typename N, typename L,
+ typename S, typename F>
+ mln_ch_value(I, L)
+ sorted_fastest(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, L& nlabels,
+ const S& s, F& f)
+ {
+ trace::entering("canvas::impl::labeling::sorted_fastest");
+
+ // FIXME: Test?!
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+
+ extension::adjust(input, nbh);
+
+ // Local type.
+ typedef mln_psite(I) P;
+
+ // Auxiliary data.
+ mln_ch_value(I, bool) deja_vu;
+ mln_ch_value(I, unsigned) parent;
+
+ // Output.
+ mln_ch_value(I, L) output;
+ bool status;
+
+ // Initialization.
+ {
+ initialize(deja_vu, input);
+ mln::data::fill(deja_vu, false);
+ extension::fill(deja_vu, false); // So that the extension is ignored.
+
+ initialize(parent, input);
+
+ initialize(output, input);
+ mln::data::fill(output, L(literal::zero));
+ nlabels = 0;
+
+ f.init_(); // Client initialization.
+ }
+
+ util::array<int> dp = offsets_wrt(input, nbh);
+ const unsigned n_nbhs = dp.nelements();
+
+ const unsigned n_points = s.nelements();
+
+ // First Pass.
+ {
+ for (int i = n_points - 1; i >=0; --i) // Backward.
+ {
+ unsigned p = s[i];
+ if (! f.handles_(p))
+ continue;
+
+ // Make-Set.
+ parent.element(p) = p;
+ f.init_attr_(p);
+
+ for (unsigned j = 0; j < n_nbhs; ++j)
+ {
+ unsigned n = p + dp[j];
+ if (! deja_vu.element(n))
+ continue;
+
+ if (f.equiv_(n, p))
+ {
+ // Do-Union.
+ unsigned r = internal::find_root_fastest(parent, n);
+ if (r != p)
+ {
+ parent.element(r) = p;
+ f.merge_attr_(r, p);
+ }
+ }
+ else
+ f.do_no_union_(n, p);
+ }
+ deja_vu.element(p) = true;
+ }
+ }
+
+ // Second Pass.
+ {
+ for (unsigned i = 0; i < n_points; ++i) // Forward.
+ {
+ unsigned p = s[i];
+ if (! f.handles_(p))
+ continue;
+
+ if (parent.element(p) == p) // if p is root
+ {
+ if (f.labels_(p))
+ {
+ if (nlabels == mln_max(L))
+ {
+ status = false;
+ trace::warning("labeling aborted! Too many labels \
+ for this label type: nlabels > \
+ max(label_type).");
+ return output;
+ }
+ output.element(p) = ++nlabels;
+ }
+ }
+ else
+ output.element(p) = output.element(parent.element(p));
+ }
+ status = true;
+ }
+
+ trace::exiting("canvas::impl::labeling::sorted_fastest");
+ return output;
+ }
+
+ } // end of namespace mln::canvas::impl
+
+
+ // Dispatch.
+
+ namespace internal
+ {
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ sorted_dispatch(metal::false_,
+ const Image<I>& input,
+ const Neighborhood<N>& nbh, L& nlabels,
+ F& functor, bool increasing)
+ {
+ p_array<mln_psite(I)> s =
+ increasing ?
+ data::sort_psites_increasing(input) :
+ data::sort_psites_decreasing(input);
+ return impl::generic::labeling(input, nbh, nlabels, s,
+ functor);
+ }
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ sorted_dispatch(metal::true_,
+ const Image<I>& input,
+ const Neighborhood<N>& nbh, L& nlabels,
+ F& functor, bool increasing)
+ {
+ util::array<unsigned> s =
+ increasing ?
+ data::sort_offsets_increasing(input) :
+ data::sort_offsets_decreasing(input);
+ return impl::sorted_fastest(input, nbh, nlabels, s,
+ functor);
+ }
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ sorted_dispatch(const Image<I>& input,
+ const Neighborhood<N>& nbh, L& nlabels,
+ F& functor, bool increasing)
+ {
+ enum {
+ test = mlc_equal(mln_trait_image_speed(I),
+ trait::image::speed::fastest)::value
+ &&
+ mln_is_simple_neighborhood(N)::value
+ };
+ return sorted_dispatch(metal::bool_<test>(),
+ input, nbh, nlabels,
+ functor, increasing);
+ }
+
+
+ } // end of namespace mln::canvas::internal
+
+
+
+ // Facades.
+
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ sorted(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nlabels, F& functor, bool increasing)
+ {
+ trace::entering("canvas::labeling::sorted");
+
+ internal::labeling_tests(input, nbh, nlabels, functor);
+
+ mln_ch_value(I, L) output;
+ output = internal::sorted_dispatch(input, nbh, nlabels,
+ functor, increasing);
+
+ trace::exiting("canvas::labeling::sorted");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::canvas::labeling
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CANVAS_LABELING_SORTED_HH
diff --git a/milena/mln/canvas/labeling/video.hh b/milena/mln/canvas/labeling/video.hh
new file mode 100644
index 0000000..31afda4
--- /dev/null
+++ b/milena/mln/canvas/labeling/video.hh
@@ -0,0 +1,262 @@
+// Copyright (C) 2007, 2008, 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 MLN_CANVAS_LABELING_VIDEO_HH
+# define MLN_CANVAS_LABELING_VIDEO_HH
+
+/// \file
+///
+/// Fast connected component labeling of the object part in a binary image.
+///
+/// \todo Can we get rid of 'deja_vu' (while playing with the border)
+/// in the fastest video version?
+
+# include <mln/core/concept/image.hh>
+# include <mln/data/fill.hh>
+# include <mln/literal/zero.hh>
+# include <mln/extension/adjust_fill.hh>
+
+# include <mln/canvas/labeling/internal/tests.hh>
+# include <mln/canvas/labeling/internal/find_root_fastest.hh>
+# include <mln/canvas/labeling/generic.hh>
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ namespace labeling
+ {
+
+ template <typename I, typename N, typename L, typename F>
+ mln_ch_value(I, L)
+ video(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nlabels, F& functor);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // Implementations.
+
+ namespace impl
+ {
+
+ template <typename I, typename N, typename L, typename F>
+ mln_ch_value(I, L)
+ video_fastest(const Image<I>& input_,
+ const Neighborhood<N>& nbh_,
+ L& nlabels, F& f)
+ {
+ trace::entering("canvas::impl::video_fastest");
+
+ // FIXME: Test?!
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+
+ extension::adjust(input, nbh);
+
+ // Auxiliary data.
+ mln_ch_value(I, bool) deja_vu;
+ mln_ch_value(I, unsigned) parent;
+
+ // Output.
+ mln_ch_value(I, L) output;
+ bool status;
+
+ // Initialization.
+ {
+ initialize(deja_vu, input);
+ mln::data::fill(deja_vu, true);
+ extension::fill(deja_vu, false); // So that the extension is ignored.
+
+ initialize(parent, input);
+
+ initialize(output, input);
+ mln::data::fill(output, L(literal::zero));
+ nlabels = 0;
+
+ f.init_(); // Client initialization.
+ }
+
+ // First Pass.
+ {
+ util::array<int> dp = positive_offsets_wrt(input, nbh);
+ const unsigned n_nbhs = dp.nelements();
+
+ mln_bkd_pixter(const I) px(input); // Backward.
+ for_all(px)
+ {
+ unsigned p = px.offset();
+ if (! f.handles_(p))
+ continue;
+
+ // Make-Set.
+ parent.element(p) = p;
+ f.init_attr_(p);
+ for (unsigned i = 0; i < n_nbhs; ++i)
+ {
+ unsigned n = p + dp[i];
+ if (deja_vu.element(n)) // Only false in the external border.
+ {
+ if (f.equiv_(n, p))
+ {
+ // Do-Union.
+ unsigned r = internal::find_root_fastest(parent, n);
+ if (r != p)
+ {
+ parent.element(r) = p;
+ f.merge_attr_(r, p);
+ }
+ }
+ else
+ f.do_no_union_(n, p);
+ }
+ }
+ }
+ }
+
+ // Second Pass.
+ {
+ mln_fwd_pixter(const I) px(input); // Forward.
+ for_all(px)
+ {
+ unsigned p = px.offset();
+ if (! f.handles_(p))
+ continue;
+ if (parent.element(p) == p) // if p is root
+ {
+ if (f.labels_(p))
+ {
+ if (nlabels == mln_max(L))
+ {
+ status = false;
+ trace::warning("labeling aborted! Too many labels for \
+ this label type: nlabels > \
+ max(label_type).");
+ return output;
+ }
+ output.element(p) = ++nlabels;
+ }
+ }
+ else
+ output.element(p) = output.element(parent.element(p));
+ }
+ status = true;
+ }
+
+ trace::exiting("canvas::impl::video_fastest");
+ return output;
+ }
+
+ } // end of namespace mln::canvas::impl
+
+
+
+ // Dispatch.
+
+ namespace internal
+ {
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ video_dispatch(metal::false_,
+ const Image<I>& input,
+ const Neighborhood<N>& nbh, L& nlabels,
+ F& functor)
+ {
+ return impl::generic::labeling(input, nbh, nlabels,
+ exact(input).domain(), functor);
+ }
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ video_dispatch(metal::true_,
+ const Image<I>& input,
+ const Neighborhood<N>& nbh, L& nlabels,
+ F& functor)
+ {
+ return impl::video_fastest(input, nbh, nlabels, functor);
+ }
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ video_dispatch(const Image<I>& input,
+ const Neighborhood<N>& nbh, L& nlabels,
+ F& functor)
+ {
+ enum {
+ test = mlc_equal(mln_trait_image_speed(I),
+ trait::image::speed::fastest)::value
+ &&
+ mln_is_simple_neighborhood(N)::value
+ };
+ return video_dispatch(metal::bool_<test>(),
+ input, nbh, nlabels,
+ functor);
+ }
+
+
+ } // end of namespace mln::canvas::internal
+
+
+
+ // Facades.
+
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ video(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nlabels, F& functor)
+ {
+ trace::entering("canvas::video");
+
+ internal::labeling_tests(input, nbh, nlabels, functor);
+
+ mln_ch_value(I, L) output;
+ output = internal::video_dispatch(input, nbh, nlabels,
+ functor);
+
+ trace::exiting("canvas::video");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::canvas::labeling
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CANVAS_LABELING_VIDEO_HH
diff --git a/milena/mln/labeling/flat_zones.hh b/milena/mln/labeling/flat_zones.hh
index cab9dc8..66bc44d 100644
--- a/milena/mln/labeling/flat_zones.hh
+++ b/milena/mln/labeling/flat_zones.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -32,7 +33,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/canvas/labeling.hh>
+# include <mln/canvas/labeling/video.hh>
namespace mln
@@ -118,7 +119,8 @@ namespace mln
// Call the labeling canvas.
typedef impl::flat_zones_functor<I> F;
F f(input);
- mln_ch_value(I, L) output = canvas::labeling_video(input, nbh, nlabels, f);
+ mln_ch_value(I, L)
+ output = canvas::labeling::video(input, nbh, nlabels, f);
trace::exiting("labeling::flat_zones");
return output;
diff --git a/milena/mln/labeling/regional_maxima.hh b/milena/mln/labeling/regional_maxima.hh
index 824c5e9..a3c12eb 100644
--- a/milena/mln/labeling/regional_maxima.hh
+++ b/milena/mln/labeling/regional_maxima.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -32,7 +33,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/canvas/labeling.hh>
+# include <mln/canvas/labeling/sorted.hh>
# include <mln/data/fill.hh>
# include <mln/data/sort_psites.hh>
@@ -137,8 +138,8 @@ namespace mln
typedef impl::regional_maxima_functor<I> F;
F f(exact(input));
- mln_ch_value(I, L) output = canvas::labeling_sorted(input, nbh, nlabels,
- f, true);
+ mln_ch_value(I, L)
+ output = canvas::labeling::sorted(input, nbh, nlabels, f, true);
trace::exiting("labeling::regional_maxima");
return output;
diff --git a/milena/mln/labeling/regional_minima.hh b/milena/mln/labeling/regional_minima.hh
index 7ad798f..ae0e7e9 100644
--- a/milena/mln/labeling/regional_minima.hh
+++ b/milena/mln/labeling/regional_minima.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -32,7 +33,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/canvas/labeling.hh>
+# include <mln/canvas/labeling/sorted.hh>
# include <mln/data/fill.hh>
# include <mln/data/sort_psites.hh>
@@ -136,8 +137,8 @@ namespace mln
template <typename I, typename N, typename L>
mln_ch_value(I, L)
- regional_minima(const Image<I>& input_, const Neighborhood<N>& nbh_,
- L& nlabels)
+ regional_minima(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ L& nlabels)
{
trace::entering("labeling::regional_minima");
@@ -150,8 +151,8 @@ namespace mln
typedef impl::regional_minima_functor<I> F;
F f(exact(input));
- mln_ch_value(I, L) output = canvas::labeling_sorted(input, nbh, nlabels,
- f, false);
+ mln_ch_value(I, L)
+ output = canvas::labeling::sorted(input, nbh, nlabels, f, false);
trace::exiting("labeling::regional_minima");
return output;
diff --git a/milena/mln/labeling/value.hh b/milena/mln/labeling/value.hh
index 1495570..5a16ca4 100644
--- a/milena/mln/labeling/value.hh
+++ b/milena/mln/labeling/value.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -32,7 +33,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/canvas/labeling.hh>
+# include <mln/canvas/labeling/video.hh>
# include <mln/data/fill.hh>
@@ -139,8 +140,8 @@ namespace mln
template <typename I, typename N, typename L>
mln_ch_value(I, L)
- value(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
- L& nlabels)
+ value(const Image<I>& input, const mln_value(I)& val,
+ const Neighborhood<N>& nbh, L& nlabels)
{
trace::entering("labeling::value");
@@ -148,7 +149,7 @@ namespace mln
mln_ch_value(I, L) output;
impl::value_functor<I> f(input, val);
- output = canvas::labeling_video(input, nbh, nlabels, f);
+ output = canvas::labeling::video(input, nbh, nlabels, f);
trace::exiting("labeling::value");
return output;
diff --git a/milena/tests/labeling/flat_zones.cc b/milena/tests/labeling/flat_zones.cc
index 5a05ebc..6b4b37e 100644
--- a/milena/tests/labeling/flat_zones.cc
+++ b/milena/tests/labeling/flat_zones.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -67,16 +68,16 @@ int main()
labeling::impl::flat_zones_functor<I> f(lena);
unsigned nlabels_generic, nlabels_fastest;
- mln_assertion(canvas::impl::generic::labeling(lena,
- c4(),
- nlabels_generic,
- lena.domain(),
- f)
+ mln_assertion(canvas::labeling::impl::generic::labeling(lena,
+ c4(),
+ nlabels_generic,
+ lena.domain(),
+ f)
==
- canvas::impl::labeling_video_fastest(lena,
- c4(),
- nlabels_fastest,
- f));
+ canvas::labeling::impl::video_fastest(lena,
+ c4(),
+ nlabels_fastest,
+ f));
mln_assertion(nlabels_generic == nlabels_fastest);
}
diff --git a/milena/tests/labeling/foreground.cc b/milena/tests/labeling/foreground.cc
index 8f95ffd..acdecb6 100644
--- a/milena/tests/labeling/foreground.cc
+++ b/milena/tests/labeling/foreground.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -56,9 +57,9 @@ int main()
labeling::impl::value_functor<I> f(pic, true);
unsigned n_;
- ref = canvas::impl::generic::labeling(pic, nbh, n_,
- pic.domain(),
- f);
+ ref = canvas::labeling::impl::generic::labeling(pic, nbh, n_,
+ pic.domain(),
+ f);
mln_invariant(n_ == n);
mln_invariant(ref == out);
}
--
1.5.6.5
1
0
* mln/trait/functions.hh: Remove extra ";" l207 after "}" of compute.
---
trunk/milena/ChangeLog | 6 ++++++
trunk/milena/mln/trait/functions.hh | 2 +-
2 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/trunk/milena/ChangeLog b/trunk/milena/ChangeLog
index 01266d5..1d495c1 100644
--- a/trunk/milena/ChangeLog
+++ b/trunk/milena/ChangeLog
@@ -1,3 +1,9 @@
+2009-08-21 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
+ Remove extra ";" to compile.
+
+ * mln/trait/functions.hh: Remove extra ";" l207 after "}" of compute.
+
2009-08-19 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
* mln/make/edge_image.hh: Add a new overload.
diff --git a/trunk/milena/mln/trait/functions.hh b/trunk/milena/mln/trait/functions.hh
index ee1a611..01b8330 100644
--- a/trunk/milena/mln/trait/functions.hh
+++ b/trunk/milena/mln/trait/functions.hh
@@ -204,7 +204,7 @@ namespace mln
type compute(const U& p)
{
return def::compute(p);
- };
+ }
};
--
1.5.6.5
1
0
* green/histo1d/histo1d.hh : Improve documentation aspect.
---
trunk/milena/sandbox/ChangeLog | 6 +++++
trunk/milena/sandbox/green/histo1d/histo1d.hh | 30 +++++++++++++++++-------
2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog
index d432853..171e75b 100644
--- a/trunk/milena/sandbox/ChangeLog
+++ b/trunk/milena/sandbox/ChangeLog
@@ -1,3 +1,9 @@
+2009-08-17 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
+ Improve documentation.
+
+ * green/histo1d/histo1d.hh : Improve documentation aspect.
+
2009-08-17 Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Some fixes.
diff --git a/trunk/milena/sandbox/green/histo1d/histo1d.hh b/trunk/milena/sandbox/green/histo1d/histo1d.hh
index 23e230b..5b845c8 100644
--- a/trunk/milena/sandbox/green/histo1d/histo1d.hh
+++ b/trunk/milena/sandbox/green/histo1d/histo1d.hh
@@ -32,7 +32,10 @@
///
/// \brief Define an histogram as an accumulator which returns an image1d .
///
-/// It based on image to allow collecting statistics on it.
+/// This implementation is the very easiest. It's the discrete one. What about
+/// a continue version ? How finding the correct bin number ?? What about the
+/// subsampling process ?? Shall we estimate the density ?? In this case, which
+/// method shall we choose, kernel version or k-neareast-neighbours ??
///
#include <iostream>
@@ -95,8 +98,7 @@ namespace mln
{
namespace stat
- {
-
+ {
/// \brief Define an histogram which returns an image1d .
///
@@ -116,14 +118,14 @@ namespace mln
/// Constructors
/// \{
- /// \brief Nothing to do
+ /// \brief Initialize the size of the resulting image1d.
histo1d();
/// \}
/// Manipulators.
/// \{
- /// \brief Initialize the bounding box of the resulting image.
+ /// \brief Initialize the histogram with zero value.
void init();
@@ -139,11 +141,12 @@ namespace mln
/// Accessors.
/// \{
+ /// \brief Return the histogram as an image1d.
result to_result() const;
operator result () const;
/// \}
- /// Check whethever this accumulator is able to return a result.
+ /// \brief Check whethever this accumulator is able to return a result.
/// Always in a safe state and then always return true;
bool is_valid() const;
@@ -151,6 +154,10 @@ namespace mln
result count_;
};
+ /// \brief Check wethever an histogram is equal to an other one.
+ /// The comparaison states that all the bins share the same value.
+ /// \param[in] histo1 the first histogram to compare with.
+ /// \param[in] histo2 the second histogram.
template <typename V>
bool operator==(const histo1d<V>& histo1, const histo1d<V>& histo2);
@@ -165,9 +172,12 @@ namespace mln
{
trace::entering("mln::accu::stat::histo1d<V>::histo1d");
typedef mln_trait_value_comp(V,0) comp;
-
- count_.init_(box1d(point1d(mln_min(comp)), // -> 0
- point1d(mln_max(comp)))); // -> 2^n-1
+
+ // comp keep a trace of the dimension of the theorical image.
+ // mln_min(comp) --> 0
+ // mln_max(comp) --> 2^(n-1) [127 for n=7][255 for n=8] ...
+ count_.init_(box1d(point1d(mln_min(comp)),
+ point1d(mln_max(comp))));
trace::exiting("mln::accu::stat::histo1d<V>::histo1d");
}
@@ -188,6 +198,8 @@ namespace mln
{
trace::entering("mln::accu::stat::histo1d<V>::take");
+ // Just convert a greyscale value (int_u8 like) to a position for an
+ // iterator on the resulting image.
++count_(point1d(t));
trace::exiting("mln::accu::stat::histo1d<V>::take");
--
1.5.6.5
1
0
---
milena/ChangeLog | 4 +++
milena/mln/make/edge_image.hh | 58 +++++++++++++++++++++++++++++++++++++++-
2 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 6d3f30a..01266d5 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2009-08-19 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ * mln/make/edge_image.hh: Add a new overload.
+
+2009-08-19 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Improve graph images.
* mln/core/concept/graph.hh: Move is_valid() and invalidate()...
diff --git a/milena/mln/make/edge_image.hh b/milena/mln/make/edge_image.hh
index 884b687..b0d0465 100644
--- a/milena/mln/make/edge_image.hh
+++ b/milena/mln/make/edge_image.hh
@@ -91,7 +91,7 @@ namespace mln
///
/// \return an edge image.
//
- template <typename P, typename V, typename G, typename FP, typename FV>
+ template <typename P, typename V, typename G, typename FP, typename
mln::edge_image<mln_result(FP),mln_result(FV),G>
edge_image(const mln::vertex_image<P,V,G>& v_ima_,
const p_edges<G,FP> pe,
@@ -102,7 +102,7 @@ namespace mln
/// Construct an edge image.
///
/// \param[in] v_ima_ A vertex image.
- /// \param[in] fv_ A function mapping two vertex ids to a value.
+ /// \param[in] fv_ A function mapping two vertices ids to a value.
/// The result is associated to the corresponding edge.
///
/// \return an edge image without localization information mapped to
@@ -114,11 +114,27 @@ namespace mln
const Function_vv2v<FV>& fv_);
+ /// Construct an edge image.
+ ///
+ /// \param[in] v_ima_ A vertex image.
+ /// \param[in] fv_ A function mapping a vertex ids to a value.
+ /// The result is associated to the corresponding edge.
+ ///
+ /// \return an edge image without localization information mapped to
+ /// graph elements.
+ //
+ template <typename P, typename V, typename G, typename F>
+ mln::edge_image<void,bool,G>
+ edge_image(const mln::vertex_image<P,V,G>& v_ima_,
+ const Function_v2b<F>& fv_);
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename V, typename G>
+ inline
mln::edge_image<void,V,G>
edge_image(const Graph<G>& g, const fun::i2v::array<V>& fv)
{
@@ -156,6 +172,7 @@ namespace mln
template <typename FP, typename FV, typename G>
+ inline
mln::edge_image<mln_result(FP),mln_result(FV),G>
edge_image(const Graph<G>& g_,
const Function_v2v<FP>& fp,
@@ -175,6 +192,7 @@ namespace mln
template <typename P, typename V, typename G, typename FP, typename FV>
+ inline
mln::edge_image<mln_result(FP),mln_result(FV),G>
edge_image(const mln::vertex_image<P,V,G>& v_ima_,
const p_edges<G,FP> pe,
@@ -200,6 +218,7 @@ namespace mln
template <typename P, typename V, typename G, typename FV>
+ inline
mln::edge_image<void,mln_result(FV),G>
edge_image(const mln::vertex_image<P,V,G>& v_ima_,
const Function_vv2v<FV>& fv_)
@@ -223,6 +242,41 @@ namespace mln
}
+ template <typename P, typename V, typename G, typename F>
+ inline
+ mln::edge_image<void,bool,G>
+ edge_image(const mln::vertex_image<P,V,G>& v_ima_,
+ const Function_v2b<F>& fv_)
+ {
+ trace::entering("make::edge_image");
+
+ const F& fv = exact(fv_);
+ typedef mln::vertex_image<P,V,G> v_ima_t;
+ const v_ima_t& v_ima = exact(v_ima_);
+ mln_precondition(v_ima.is_valid());
+
+
+ p_edges<G> pe(v_ima.domain().graph());
+ typedef mln::edge_image<void,bool,G> edge_ima_t;
+ edge_ima_t ima_e(pe);
+ data::fill(ima_e, true);
+
+ mln_piter(v_ima_t) p(v_ima.domain());
+ for_all(p)
+ if (!fv(v_ima(p)))
+ {
+ typename v_ima_t::edge_win_t win;
+ mln_qiter(v_ima_t::edge_win_t) q(win, p);
+ for_all(q)
+ std::cout << q << std::endl;
+// ima_e(q) = false;
+ }
+
+ trace::exiting("make::edge_image");
+ return ima_e;
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
--
1.5.6.5
1
0