Olena
Threads by month
- ----- 2025 -----
- 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
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2002 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
March 2004
- 15 participants
- 44 discussions
Index: olena/ChangeLog
from Giovanni Palma <giovanni(a)lrde.epita.fr>
* oln/morpho/attribute_closing_opening.hh: Make the
opening/closing choice at compile time.
* oln/morpho/attribute_union_find.hh: Likewise.
* oln/utils/histogram.hh: Add a distrib sort functor.
Index: NEWS
--- NEWS Tue, 10 Feb 2004 15:35:04 +0100 palma_g (oln/0_NEWS 1.18 640)
+++ NEWS Tue, 10 Feb 2004 17:19:37 +0100 palma_g (oln/0_NEWS 1.18 640)
@@ -11,7 +11,7 @@
rectangle, volume, height, maxvalue, minvalue).
* Change the color conversion system
- - CIE RGB is the main color system e.g. it can be converted
+ - CIE RGB is the main color system i.e. it can be converted
directly into any other color system.
- Conversion between 2 color systems should pass by the RGB one.
Index: olena/oln/utils/histogram.hh
--- olena/oln/utils/histogram.hh Fri, 06 Feb 2004 16:02:37 +0100 palma_g (oln/10_histogram. 1.6.1.14.1.4 640)
+++ olena/oln/utils/histogram.hh Tue, 10 Feb 2004 17:13:39 +0100 palma_g (oln/10_histogram. 1.6.1.14.1.4 640)
@@ -523,6 +523,30 @@
*(ptr[unsigned(im[p] - ntg_min_val(val))]++) = p;
}
+ // to select staticly the good distrib_sort
+ template <bool reverse>
+ struct select_distrib_sort
+ {
+ template <class I>
+ void
+ operator ()(const oln::abstract::image<I>& im,
+ std::vector<oln_point_type(I)> &v)
+ {
+ distrib_sort_inv(im, v);
+ }
+ };
+
+ template <>
+ struct select_distrib_sort<true>
+ {
+ template <class I>
+ void
+ operator ()(const oln::abstract::image<I>& im,
+ std::vector<oln_point_type(I)> &v)
+ {
+ distrib_sort(im, v);
+ }
+ };
} // end of namespace utils
} // end of namespace oln
Index: olena/oln/morpho/attribute_closing_opening.hh
--- olena/oln/morpho/attribute_closing_opening.hh Mon, 09 Feb 2004 18:57:03 +0100 palma_g (oln/q/49_attribute_ 1.12 640)
+++ olena/oln/morpho/attribute_closing_opening.hh Tue, 10 Feb 2004 16:52:24 +0100 palma_g (oln/q/49_attribute_ 1.12 640)
@@ -43,9 +43,10 @@
const abstract::neighborhood<N>& Ng,
const attr_lambda_type(A) &lambda)
{
+ typedef N toto;
typedef tarjan::tarjan_set<oln_concrete_type(I), A > tarjan_set_type;
- tarjan_set_type area_closing(input.exact(), attr_env_type(A)());
- return area_closing.get_comptute(lambda, Ng, true);
+ tarjan_set_type attr_closing(input.exact(), attr_env_type(A)());
+ return attr_closing.template get_comptute<true>(lambda, Ng);
}
// attribute opening
@@ -56,8 +57,8 @@
const attr_lambda_type(A) &lambda)
{
typedef tarjan::tarjan_set<oln_concrete_type(I), A > tarjan_set_type;
- tarjan_set_type area_opening(input.exact(), attr_env_type(A)());
- return area_opening.get_comptute(lambda , Ng, false);
+ tarjan_set_type attr_opening(input.exact(), attr_env_type(A)());
+ return attr_opening.template get_comptute<false>(lambda, Ng);
}
} // !internal
Index: olena/oln/morpho/attribute_union_find.hh
--- olena/oln/morpho/attribute_union_find.hh Mon, 09 Feb 2004 18:57:03 +0100 palma_g (oln/q/50_attribute_ 1.10 640)
+++ olena/oln/morpho/attribute_union_find.hh Tue, 10 Feb 2004 17:15:02 +0100 palma_g (oln/q/50_attribute_ 1.10 640)
@@ -171,20 +171,16 @@
// bool closing = true -> a closing is performed,
// an opening otherwise.
- template<class N>
+ template<bool closing, class N>
image_type
get_comptute(const lambda_type & lambda,
- const abstract::neighborhood<N>& Ng,
- const bool closing)
+ const abstract::neighborhood<N>& Ng)
{
lambda_ = λ
std::vector<point_type> I(input_.npoints());
- if (closing)
- oln::utils::distrib_sort(input_, I);
- else
- oln::utils::distrib_sort_inv(input_, I);
+ oln::utils::select_distrib_sort<closing>()(input_, I);
level::fill(aux_data_, ntg_sup_val(lambda_type));
aux_data_.border_adapt_assign(Ng.delta(), ntg_sup_val(lambda_type));
--
Giovanni Palma
EPITA - promo 2005 - membre d'EpX - LRDE
Mob. : +33 (0)6 60 97 31 74
2
1
Index: olena/ChangeLog
from Niels Van Vliet <niels(a)lrde.epita.fr>
* oln/morpho/attribute_closing_opening_map.hh: Add file.
Attribute closing and opening using std::map.
* oln/morpho/attribute_closing_opening_map.hxx: Add file.
* oln/utils/special_points.hh: Add file. Point used as a state.
* tests/morpho/attributes: Add file. Add tests on attribute
closing and opening.
Index: olena/oln/morpho/attribute_closing_opening_map.hxx
--- olena/oln/morpho/attribute_closing_opening_map.hxx Tue, 10 Feb 2004
19:47:05 +0100 van-vl_n ()
+++ olena/oln/morpho/attribute_closing_opening_map.hxx Tue, 10 Feb 2004
19:18:13 +0100 van-vl_n (oln/j/48_attribute_ 644)
@@ -0,0 +1,194 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library 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 this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library 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.
+
+
+namespace oln
+{
+ namespace morpho
+ {
+ template <class I, class D, class Env>
+ template <class N>
+ f_tarjan_map<I, D, Env>::f_tarjan_map(bool is_closing,
+ const typename f_tarjan_map<I, D, Env>::input_type& input,
+ const abstract::neighborhood<N>& ng,
+ const typename f_tarjan_map<I, D, Env>::lambda_type& lambda,
+ const Env & env) :
+ is_closing(is_closing),
+ input(input),
+ lambda(lambda),
+ parent(input.size()),
+ is_proc(input.size()),
+ output(input.size()),
+ env(env)
+ {
+ // init S and parent
+ typedef typename std::vector<point_type> vector_type;
+ vector_type S(input.npoints());
+ if (is_closing)
+ utils::distrib_sort(input, S);
+ else
+ utils::distrib_sort_inv(input, S);
+
+ level::fill(parent, inactive());
+ level::fill(is_proc, false);
+
+ // array S contains sorted pixel list
+ make_set(S[0]);
+ is_proc[S[0]] = true;
+
+ for (int ip = 1; ip < int(S.size()); ++ip)
+ {
+ point_type p = S[ip];
+
+ // p_ is the pixel just processed before p
+ point_type p_ = S[ip - 1];
+ if (input[p] != input[p_])
+ {
+ // for all the previous layer
+ for (int iq = ip - 1; iq >= 0; --iq)
+ {
+ point_type q = S[iq];
+ if (input[q] != input[p_])
+ break;
+ // if the attribute is 'reached', we do not need
+ // it anymore
+ if (parent[q] == active() && !(auxdata[q] < lambda))
+ {
+ parent[q] = inactive();
+ auxdata.erase(q);
+ }
+ }
+ }
+ make_set(p);
+
+ oln_neighb_type(N) n(ng, p);
+ for_all(n)
+ if (input.hold(n) && is_proc[n])
+ do_union(n, p);
+
+ is_proc[p] = true;
+ }
+
+ // resolving phase in reverse sort order
+
+ for (int ip = int(S.size()) - 1; ip >= 0; --ip)
+ {
+ point_type p = S[ip];
+ if (parent[p] == active() || parent[p] == inactive())
+ output[p] = input[p];
+ else
+ output[p] = output[parent[p]];
+ }
+ }
+
+ template <class I, class D, class Env>
+ const typename f_tarjan_map<I, D, Env>::point_type
+ f_tarjan_map<I, D, Env>::inactive()
+ {
+ static const point_type it =
utils::internal::mk_point_looking_like<point_type>(-2);
+ return it;
+ }
+
+ template <class I, class D, class Env>
+ const typename f_tarjan_map<I, D, Env>::point_type
+ f_tarjan_map<I, D, Env>::active()
+ {
+ static const point_type it =
utils::internal::mk_point_looking_like<point_type>(-1);
+ return it;
+ }
+
+ template <class I, class D, class Env>
+ void
+ f_tarjan_map<I, D, Env>::make_set(const typename f_tarjan_map<I, D,
Env>::point_type& x)
+ {
+ precondition(parent[x] == inactive());
+ parent[x] = active();
+ auxdata[x] = D(input, x, env);
+ }
+
+ template <class I, class D, class Env>
+ void
+ f_tarjan_map<I, D, Env>::link(const typename f_tarjan_map<I, D,
Env>::point_type& x,
+ const typename f_tarjan_map<I, D, Env>::point_type& y)
+ {
+ if (parent[x] == active() && parent[y] == active())
+ {
+ auxdata[y] += auxdata[x];
+ auxdata.erase(x);
+ }
+ else
+ if (parent[x] == active())
+ auxdata.erase(x);
+ else
+ {
+ parent[y] = inactive();
+ auxdata.erase(y);
+ }
+ parent[x] = y;
+ }
+
+ template <class I, class D, class Env>
+ typename f_tarjan_map<I, D, Env>::point_type
+ f_tarjan_map<I, D, Env>::find_root(const typename f_tarjan_map<I,
D, Env>::point_type& x)
+ {
+ if (parent[x] != active() && parent[x] != inactive())
+ {
+ parent[x] = find_root(parent[x]);
+ return parent[x];
+ }
+ return x;
+ }
+
+ template <class I, class D, class Env>
+ bool
+ f_tarjan_map<I, D, Env>::equiv(const typename f_tarjan_map<I, D,
Env>::point_type& x,
+ const typename f_tarjan_map<I, D, Env>::point_type& y) const
+ {
+ return input[x] == input[y] || parent[x] == active();
+ }
+
+ template <class I, class D, class Env>
+ void
+ f_tarjan_map<I, D, Env>::do_union(const typename f_tarjan_map<I, D,
Env>::point_type& n,
+ const typename f_tarjan_map<I, D, Env>::point_type& p)
+ {
+ point_type r = find_root(n);
+ if (r != p)
+ {
+ if (equiv(r, p))
+ link(r, p);
+ else
+ if (parent[p] == active())
+ {
+ parent[p] = inactive();
+ auxdata.erase(p);
+ }
+ }
+ }
+ } // end of namespace morpho
+} // end of namespace oln
+
Index: olena/oln/morpho/attribute_closing_opening_map.hh
--- olena/oln/morpho/attribute_closing_opening_map.hh Tue, 10 Feb 2004
19:47:05 +0100 van-vl_n ()
+++ olena/oln/morpho/attribute_closing_opening_map.hh Tue, 10 Feb 2004
19:18:13 +0100 van-vl_n (oln/j/49_attribute_ 644)
@@ -0,0 +1,151 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library 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 this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library 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 OLENA_MORPHO_ATTRIBUTE_CLOSING_OPENING_MAP
+# define OLENA_MORPHO_ATTRIBUTE_CLOSING_OPENING_MAP
+# include <oln/morpho/attributes.hh>
+# include <oln/level/fill.hh>
+# include <oln/basics2d.hh>
+# include <ntg/int.hh>
+# include <oln/utils/histogram.hh>
+# include <oln/utils/special_points.hh>
+
+# include <iterator>
+# include <vector>
+# include <map>
+# include <algorithm>
+# include <utility>
+
+
+namespace oln
+{
+ namespace morpho
+ {
+
+ /*! Attribute closing using map. Smaller memory usage, but
+ * slower computation than the attribute_closing_opening
+ *
+ * See "Fast morphological attribute operations using Tarjan's
union-find
+ * algorithm" by Michael H. F. Wilkinson and Jos B. T. M. Roerdink
+ */
+ template <class I, class D, class Env = morpho::tarjan::NullEnv>
+ struct f_tarjan_map
+ {
+ public:
+ typedef abstract::image<I> input_type;
+ typedef oln_concrete_type(I) img_type;
+
+ typedef oln_point_type(input_type) point_type;
+ typedef oln_value_type(input_type) value_type;
+ typedef typename mute<input_type, point_type>::ret parent_type;
+ typedef typename mute<input_type, bool>::ret is_proc_type;
+ typedef typename D::lambda_type lambda_type;
+
+ // e.g.,
+ // when I is image2d<int_u8> and D is area_type, we've got:
+ // +--------------+------------------+
+ // | input_type | image2d<int_u8> |
+ // | point_type | point2d |
+ // | parent_type | image2d<point2d> |
+ // | is_proc_type | image2d<bool> |
+ // | lambda_type | int |
+ // +--------------+------------------+
+
+ template <class N>
+ f_tarjan_map(bool is_closing,
+ const input_type& input,
+ const abstract::neighborhood<N>& ng,
+ const lambda_type& lambda,
+ const Env & env = Env());
+
+ template<typename DestValue>
+ typename mute<I, DestValue>::ret
+ res()
+ {
+ return output;
+ }
+ protected:
+
+ static const point_type
+ inactive();
+
+ static const point_type
+ active();
+
+ void
+ make_set(const point_type& x);
+
+ void
+ link(const point_type& x, const point_type& y);
+
+ point_type
+ find_root(const point_type& x);
+
+ bool
+ equiv(const point_type& x, const point_type& y) const;
+
+ void
+ do_union(const point_type& n, const point_type& p);
+
+ const bool is_closing;
+ const input_type& input;
+ lambda_type lambda;
+ parent_type parent;
+ is_proc_type is_proc;
+ img_type output;
+ std::map<point_type, D, oln::internal::default_less<point_type> >
auxdata;
+ Env env;
+ };
+
+
+ /*! Attribute closing using map. Smaller memory usage, but
+ * slower computation than the attribute_closing_opening
+ *
+ * See "Fast morphological attribute operations using Tarjan's
union-find
+ * algorithm" by Michael H. F. Wilkinson and Jos B. T. M. Roerdink
+ */
+ template <typename DestValue, class I, class D, class Env, class N>
+ typename mute<I, DestValue>::ret
+ tarjan_map(bool is_closing,
+ const abstract::image<I>& input,
+ const abstract::neighborhood<N>& ng,
+ const typename D::lambda_type& lambda,
+ const Env & env = Env())
+ {
+ oln::morpho::f_tarjan_map<I, D, Env > t(is_closing,
+ input,
+ ng,
+ lambda,
+ env);
+ return t. template res<DestValue>();
+ }
+ } // end of namespace morpho
+} // end of namespace oln
+
+#include "attribute_closing_opening_map.hxx"
+
+#endif
Index: olena/oln/utils/special_points.hh
--- olena/oln/utils/special_points.hh Tue, 10 Feb 2004 19:47:05 +0100
van-vl_n ()
+++ olena/oln/utils/special_points.hh Tue, 10 Feb 2004 19:18:14 +0100
van-vl_n (oln/j/50_special_po 644)
@@ -0,0 +1,58 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library 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 this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library 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 OLENA_UTILS_SPECIAL_POINTS_HH
+# define OLENA_UTILS_SPECIAL_POINTS_HH
+
+# include <oln/core/abstract/point.hh>
+
+namespace oln {
+
+ namespace utils {
+
+ namespace internal {
+ /*! Creates a point that is used as a state.
+ *
+ * This function should be called with a value unreachable
+ * for example a negative one.
+ */
+ template <class P>
+ P
+ mk_point_looking_like(coord value)
+ {
+ P p;
+ p.nth(0) = value;
+ return p;
+ }
+
+ } // end of namespace internal
+
+ } // end of namespace utils
+
+} // end of namespace oln
+
+#endif // ! OLENA_UTILS_SPECIAL_POINTS_HH
Index: olena/tests/morpho/tests/attribute
--- olena/tests/morpho/tests/attribute Tue, 10 Feb 2004 19:47:05 +0100
van-vl_n ()
+++ olena/tests/morpho/tests/attribute Tue, 10 Feb 2004 19:18:00 +0100
van-vl_n (oln/j/51_attribute 644)
@@ -0,0 +1,109 @@
+// -*- c++ -*-
+
+#include <oln/basics2d.hh>
+#include <oln/morpho/attribute_closing_opening.hh>
+#include <oln/morpho/attribute_closing_opening_map.hh>
+#include <oln/level/compare.hh>
+#include <ntg/all.hh>
+#include <oln/morpho/extrema_killer.hh>
+
+#include "check.hh"
+#include "data.hh"
+
+using namespace oln;
+using namespace ntg;
+
+#define OK_OR_FAIL \
+ std::cout << "OK" << std::endl; \
+ else \
+ { \
+ std::cout << "FAIL" << std::endl; \
+ fail = true; \
+ }
+
+//FIXME some algo are already checked.
+bool
+check_algo()
+{
+ bool fail(false);
+
+ typedef image2d<int_u8> img_type;
+ typedef oln::morpho::tarjan::area_type<unsigned> area_type;
+ const area_type::lambda_type area = 100;
+ const neighborhood2d nb = neighb_c8();
+ const oln::morpho::tarjan::NullEnv env;
+
+ img_type lena = load(rdata("lena.pgm"));
+ img_type lena_sure_closing = oln::morpho::sure_minima_killer(lena,
area, nb);
+ img_type lena_sure_opening = oln::morpho::sure_maxima_killer(lena,
area, nb);
+
+ img_type lena_tst_opening;
+ img_type lena_tst_closing;
+
+ std::cerr << "testing tarjan_map..." << std::endl;
+ lena_tst_closing =
morpho::tarjan_map<ntg::int_u8,img_type,area_type>(true, lena, nb,
area, env);
+ lena_tst_opening=
morpho::tarjan_map<ntg::int_u8,img_type,area_type>(false, lena, nb,
area, env);
+
+
+ fail = fail ||
+ !level::is_equal(lena_sure_closing, lena_tst_closing)||
+ !level::is_equal(lena_sure_opening, lena_tst_opening);
+
+ std::cerr << "fail:" << fail << std::endl;
+
+ std::cerr << "testing fast_minima_killer..." << std::endl;
+ lena_tst_closing = oln::morpho::fast_minima_killer(lena, area, nb);
+
+ fail = fail ||
+ !level::is_equal(lena_sure_closing, lena_tst_closing);
+ std::cerr << "fail:" << fail << std::endl;
+
+ std::cerr << "testing area_closin and area_opeing..." << std::endl;
+ lena_tst_closing = morpho::tarjan::area_closing(lena, nb, area);
+ lena_tst_opening = morpho::tarjan::area_opening(lena, nb, area);
+ fail = fail ||
+ !level::is_equal(lena_sure_closing, lena_tst_closing)||
+ !level::is_equal(lena_sure_opening, lena_tst_opening);
+ std::cerr << "fail:" << fail << std::endl;
+ //FIXME at least 1 other algo should be checked
+
+ return fail;
+}
+
+
+bool
+check_attribute()
+{
+ //FIXME attributes should be checked
+ return false;
+}
+
+
+bool
+check_env()
+{
+ //FIXME env should be checked
+ return false;
+}
+bool
+check()
+{
+ bool fail = false;
+
+ std::cerr << "FIXME: check_attribute and check_env are empty."
+ << std::endl;
+
+ std::cout << "check algo... " << std::flush;
+ if (check_algo() == false)
+ OK_OR_FAIL;
+
+ std::cout << "check attribute... " << std::flush;
+ if (check_attribute() == false)
+ OK_OR_FAIL;
+
+ std::cout << "check env... " << std::flush;
+ if (check_env() == false)
+ OK_OR_FAIL;
+
+ return fail;
+}
2
1
Index: olena/ChangeLog
from Niels Van Vliet <niels(a)lrde.epita.fr>
* oln/core/abstract/image.hh: Remove macro oln_neighb_type.
* oln/core/abstract/neighborhood.hh: Add macro oln_neighb_type.
* oln/core/utils/histogram.hh: Add a FIXME.
+2004-02-10 Niels Van Vliet <niels(a)lrde.epita.fr>
+
* oln/morpho/attribute_closing_opening_map.hh: Add file.
Attribute closing and opening using std::map.
* oln/morpho/attribute_closing_opening_map.hxx: Add file.
Index: olena/oln/core/abstract/neighborhood.hh
--- olena/oln/core/abstract/neighborhood.hh Thu, 07 Aug 2003 02:08:21
+0200 david (oln/c/38_neighborho 1.18 640)
+++ olena/oln/core/abstract/neighborhood.hh Wed, 11 Feb 2004 09:11:56
+0100 van-vl_n (oln/c/38_neighborho 1.18 640)
@@ -1,4 +1,4 @@
-// Copyright (C) 2001, 2002, 2003 EPITA Research and Development
Laboratory
+// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development
Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -175,6 +175,9 @@
return win;
}
+# define oln_neighb_type(Neighbable) \
+typename Neighbable::neighb_type
+
} // end of oln
Index: olena/oln/utils/histogram.hh
--- olena/oln/utils/histogram.hh Tue, 10 Feb 2004 17:32:17 +0100 palma_g
(oln/10_histogram. 1.6.1.14.1.5 640)
+++ olena/oln/utils/histogram.hh Wed, 11 Feb 2004 09:15:27 +0100
van-vl_n (oln/10_histogram. 1.6.1.14.1.5 640)
@@ -84,6 +84,9 @@
namespace abstract
{
+ // FIXME: An image is inside the histogram. This is incorrect
+ // because it is not exactly an image (we do not need any
+ // border).
template<class T,
typename CPT,
class Exact = mlc::final>
Index: olena/oln/core/abstract/image.hh
--- olena/oln/core/abstract/image.hh Mon, 01 Sep 2003 20:12:38 +0200
burrus_n (oln/t/25_image.hh 1.19 640)
+++ olena/oln/core/abstract/image.hh Wed, 11 Feb 2004 09:11:57 +0100
van-vl_n (oln/t/25_image.hh 1.19 640)
@@ -1,4 +1,4 @@
-// Copyright (C) 2001, 2003 EPITA Research and Development Laboratory
+// Copyright (C) 2001, 2003, 2004 EPITA Research and Development
Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -209,9 +209,6 @@
# define oln_dpoint_type(DPointable) \
mlc_exact_type(DPointable)::dpoint_type
-# define oln_neighb_type(Neighbable) \
-typename Neighbable::neighb_type
-
} // end of namespace oln
#endif // ! OLENA_CORE_ABSTRACT_IMAGE_HH
1
0
Index: olena/ChangeLog
from Giovanni Palma <giovanni(a)lrde.epita.fr>
* tests/morpho/tests/attribute: Fix function call problems.
* tests/morpho/tests/attr_op_cl: Add attribute opening/closing
tests.
* oln/morpho/attribute_closing_opening_map.hh: Add slow
namespace. Correct type problems.
* oln/morpho/attribute_closing_opening_map.hxx: Likewise.
* oln/morpho/attributes.hh: Fix bugs.
* oln/morpho/attribute_union_find.hh: Add fast namespace.
* oln/morpho/attribute_closing_opening.hh: Likewise.
Index: olena/oln/morpho/attribute_closing_opening.hh
--- olena/oln/morpho/attribute_closing_opening.hh Tue, 10 Feb 2004 17:32:17 +0100 palma_g (oln/q/49_attribute_ 1.13 640)
+++ olena/oln/morpho/attribute_closing_opening.hh Mon, 16 Feb 2004 08:38:59 +0100 palma_g (oln/q/49_attribute_ 1.13 640)
@@ -32,8 +32,8 @@
namespace oln {
namespace morpho {
+ namespace fast {
namespace tarjan {
-
namespace internal {
// attribute closing
@@ -43,7 +43,6 @@
const abstract::neighborhood<N>& Ng,
const attr_lambda_type(A) &lambda)
{
- typedef N toto;
typedef tarjan::tarjan_set<oln_concrete_type(I), A > tarjan_set_type;
tarjan_set_type attr_closing(input.exact(), attr_env_type(A)());
return attr_closing.template get_comptute<true>(lambda, Ng);
@@ -62,7 +61,7 @@
}
} // !internal
-
+ } // !tarjan
// macro for some attribute opening/closing declarations
# define xxx_opening_decl(T) \
template<class I, class N> \
@@ -71,7 +70,7 @@
const abstract::neighborhood<N>& Ng, \
const attr_lambda_type(T##_type<unsigned>) &lambda) \
{ \
- return internal::attr_opening_<I, N, T##_type<unsigned> >(input, Ng, lambda); \
+ return tarjan::internal::attr_opening_<I, N, T##_type<unsigned> >(input, Ng, lambda); \
}
# define xxx_closing_decl(T) \
@@ -81,7 +80,7 @@
const abstract::neighborhood<N>& Ng, \
const attr_lambda_type(T##_type<unsigned>) &lambda) \
{ \
- return internal::attr_closing_<I, N, T##_type<unsigned> >(input, Ng, lambda); \
+ return tarjan::internal::attr_closing_<I, N, T##_type<unsigned> >(input, Ng, lambda); \
}
@@ -93,7 +92,7 @@
const abstract::neighborhood<N>& Ng, \
const attr_lambda_type(T##_type<I>) &lambda) \
{ \
- return internal::attr_opening_<I, N, T##_type<I> >(input, Ng, lambda); \
+ return tarjan::internal::attr_opening_<I, N, T##_type<I> >(input, Ng, lambda); \
}
# define xxx_closing_im_decl(T) \
@@ -103,7 +102,7 @@
const abstract::neighborhood<N>& Ng, \
const attr_lambda_type(T##_type<I>) &lambda) \
{ \
- return internal::attr_closing_<I, N, T##_type<I> >(input, Ng, lambda); \
+ return tarjan::internal::attr_closing_<I, N, T##_type<I> >(input, Ng, lambda); \
}
/*=processing area_closing
@@ -124,7 +123,7 @@
* exi: lena256.pgm
* exo: out.pgm
=*/
- xxx_closing_decl(area)
+ xxx_closing_decl(area);
/*=processing area_opening
* ns: morpho
@@ -144,27 +143,27 @@
* exi: lena256.pgm
* exo: out.pgm
=*/
- xxx_opening_decl(area)
-
- xxx_opening_decl(volume)
- xxx_closing_decl(volume)
- xxx_opening_decl(height)
- xxx_closing_decl(height)
- xxx_opening_decl(maxvalue)
- xxx_closing_decl(maxvalue)
- xxx_opening_decl(minvalue)
- xxx_closing_decl(minvalue)
- xxx_opening_im_decl(disk)
- xxx_closing_im_decl(disk)
- xxx_opening_im_decl(dist)
- xxx_closing_im_decl(dist)
- xxx_closing_im_decl(square)
- xxx_opening_im_decl(square)
- xxx_closing_im_decl(rectangle)
- xxx_opening_im_decl(rectangle)
+ xxx_opening_decl(area);
- }
- }
-}
+ xxx_opening_decl(volume);
+ xxx_closing_decl(volume);
+ xxx_opening_decl(height);
+ xxx_closing_decl(height);
+ xxx_opening_decl(maxvalue);
+ xxx_closing_decl(maxvalue);
+ xxx_opening_decl(minvalue);
+ xxx_closing_decl(minvalue);
+ xxx_opening_im_decl(disk);
+ xxx_closing_im_decl(disk);
+ xxx_opening_im_decl(dist);
+ xxx_closing_im_decl(dist);
+ xxx_closing_im_decl(square);
+ xxx_opening_im_decl(square);
+ xxx_closing_im_decl(rectangle);
+ xxx_opening_im_decl(rectangle);
+
+ } // !fast
+ } // !morpho
+} // !oln
#endif
Index: olena/oln/morpho/attribute_union_find.hh
--- olena/oln/morpho/attribute_union_find.hh Tue, 10 Feb 2004 17:32:17 +0100 palma_g (oln/q/50_attribute_ 1.11 640)
+++ olena/oln/morpho/attribute_union_find.hh Thu, 12 Feb 2004 14:14:57 +0100 palma_g (oln/q/50_attribute_ 1.11 640)
@@ -38,6 +38,7 @@
namespace oln {
namespace morpho {
+ namespace fast {
namespace tarjan {
template< class T>
@@ -231,7 +232,8 @@
const lambda_type *lambda_;
const env_type env_;
};
- }
- }
-}
+ } // !tarjan
+ } // !fast
+ } // !morph
+} // !oln
#endif
Index: olena/oln/morpho/attributes.hh
--- olena/oln/morpho/attributes.hh Tue, 10 Feb 2004 15:35:04 +0100 palma_g (oln/j/45_attributes 1.3 644)
+++ olena/oln/morpho/attributes.hh Mon, 16 Feb 2004 18:57:01 +0100 palma_g (oln/j/45_attributes 1.3 644)
@@ -31,9 +31,9 @@
# include <vector>
// attribute dedicated macros
-# define attr_lambda_type(T) typename attr_traits<T>::lambda_type
-# define attr_env_type(T) typename attr_traits<T>::env_type
-# define attr_value_type(T) typename attr_traits<T>::value_type
+# define attr_lambda_type(T) typename oln::morpho::attr_traits<T>::lambda_type
+# define attr_env_type(T) typename oln::morpho::attr_traits<T>::env_type
+# define attr_value_type(T) typename oln::morpho::attr_traits<T>::value_type
# define attr_type_decl(slef_type) \
typedef mlc_exact_vt_type(self_type, Exact) exact_type; \
@@ -43,7 +43,6 @@
namespace oln {
namespace morpho {
- namespace tarjan {
namespace tools {
// should be moved elsewhere
template <class T>
@@ -51,8 +50,8 @@
{
return v1 > v2 ? v1 - v2 : v2 - v1;
}
+ } // !tools
- }
// environment herarchy
// not used yet
template <class Exact>
@@ -265,7 +264,10 @@
{
};
- height_type(const lambda_type &lambda): value_(lambda)
+ height_type(const lambda_type &lambda):
+ value_(lambda),
+ min_(ntg_zero_val(value_type)),
+ max_(lambda)
{
};
@@ -273,25 +275,38 @@
height_type(const abstract::image<I> &input,
const oln_point_type(I) &p,
const env_type&):
- reflevel_(input[p]),
- value_(ntg_zero_val(value_type))
+ value_(ntg_zero_val(value_type)),
+ min_(input[p]),
+ max_(input[p])
{
};
- const value_type &getReflevel() const
+
+ const value_type &getMin() const
{
- mlc_dispatch(getReflevel)();
+ mlc_dispatch(getMin)();
};
+ const value_type &getMax() const
+ {
+ mlc_dispatch(getMax)();
+ };
// impl part
- const value_type &getReflevel_impl() const
+ const value_type &getMin_impl() const
{
- return reflevel_;
+ return min_;
+ };
+
+ const value_type &getMax_impl() const
+ {
+ return max_;
};
void pe_impl(const height_type &rhs)
{
- value_ = tools::diffabs(reflevel_, rhs.getReflevel());
+ min_ = ntg::min(min_, rhs.getMin());
+ max_ = ntg::max(max_, rhs.getMax());
+ value_ = max_ - min_;
};
bool less_impl(const lambda_type &lambda) const
@@ -305,8 +320,9 @@
};
protected:
- value_type reflevel_;
value_type value_;
+ value_type min_;
+ value_type max_;
};
@@ -413,7 +429,7 @@
bool less_impl(const lambda_type &lambda) const
{
- return value_ < lambda;
+ return value_ > lambda;
};
bool ne_impl(const lambda_type &lambda) const
@@ -452,17 +468,27 @@
};
disk_type(const im_type&, const point_type &p, const env_type &) :
- value_(1), pts_()
+ value_(ntg_zero_val(value_type)), pts_()
+
{
pts_.push_back(p);
};
+ const value_type &getValue() const
+ {
+ mlc_dispatch(getValue)();
+ };
+
const pts_type &getPts() const
{
mlc_dispatch(getPts)();
};
// impl
+ const value_type &getValue_impl() const
+ {
+ return value_;
+ };
const pts_type &getPts_impl() const
{
@@ -471,7 +497,10 @@
void pe_impl(const disk_type &rhs)
{
- std::copy(rhs.getPts().begin(), rhs.getPts().end(), std::back_inserter(pts_));
+ value_type last = value_;
+ std::copy(rhs.getPts().begin(),
+ rhs.getPts().end(),
+ std::back_inserter(pts_));
value_ = ntg_zero_val(value_type);
for (cst_iter_type p1 = pts_.begin(); p1 != pts_.end(); ++p1)
for (cst_iter_type p2 = pts_.begin(); p2 != pts_.end(); ++p2)
@@ -484,6 +513,8 @@
value_ = d;
}
value_ /= 2;
+ value_ = ntg::max(value_, last);
+ value_ = ntg::max(value_, rhs.getValue());
};
bool less_impl(const lambda_type &lambda) const
@@ -530,6 +561,11 @@
{
};
+ const value_type &getValue() const
+ {
+ mlc_dispatch(getValue)();
+ };
+
dist_type(const lambda_type lambda): value_(lambda)
{
};
@@ -545,14 +581,22 @@
return center_;
};
+ const value_type &getValue_impl() const
+ {
+ return value_;
+ };
+
void pe_impl(const dist_type &rhs)
{
+ value_type last = value_;
dpoint_type p = center_ - rhs.getCenter();
value_ = ntg_zero_val(value_type);
for (int i = 0; i < point_traits<point_type>::dim; ++i)
value_ += p.nth(i) * p.nth(i);
value_ = sqrt(value_);
+ value_ = ntg::max(value_, last);
+ value_ = ntg::max(value_, rhs.getValue());
};
bool less_impl(const lambda_type &lambda) const
@@ -841,9 +885,8 @@
typedef ntg::vec<I::dim, value_type, mlc::final> lambda_type;
typedef NullEnv env_type;
};
- }
- }
-}
+ } // !morpho
+} //!oln
/*-----------*
| diamond |
Index: olena/oln/morpho/attribute_closing_opening_map.hxx
--- olena/oln/morpho/attribute_closing_opening_map.hxx Tue, 10 Feb 2004 19:49:03 +0100 van-vl_n (oln/j/48_attribute_ 1.1 644)
+++ olena/oln/morpho/attribute_closing_opening_map.hxx Thu, 12 Feb 2004 14:05:43 +0100 palma_g (oln/j/48_attribute_ 1.1 644)
@@ -30,6 +30,8 @@
{
namespace morpho
{
+ namespace slow
+ {
template <class I, class D, class Env>
template <class N>
f_tarjan_map<I, D, Env>::f_tarjan_map(bool is_closing,
@@ -189,6 +191,7 @@
}
}
}
+ } // end of namespace slow
} // end of namespace morpho
} // end of namespace oln
Index: olena/oln/morpho/attribute_closing_opening_map.hh
--- olena/oln/morpho/attribute_closing_opening_map.hh Tue, 10 Feb 2004 19:49:03 +0100 van-vl_n (oln/j/49_attribute_ 1.1 600)
+++ olena/oln/morpho/attribute_closing_opening_map.hh Mon, 16 Feb 2004 08:39:58 +0100 palma_g (oln/j/49_attribute_ 1.1 600)
@@ -33,6 +33,7 @@
# include <ntg/int.hh>
# include <oln/utils/histogram.hh>
# include <oln/utils/special_points.hh>
+# include <oln/morpho/attributes.hh>
# include <iterator>
# include <vector>
@@ -45,14 +46,15 @@
{
namespace morpho
{
-
+ namespace slow
+ {
/*! Attribute closing using map. Smaller memory usage, but
* slower computation than the attribute_closing_opening
*
* See "Fast morphological attribute operations using Tarjan's union-find
* algorithm" by Michael H. F. Wilkinson and Jos B. T. M. Roerdink
*/
- template <class I, class D, class Env = morpho::tarjan::NullEnv>
+ template <class I, class D, class Env = morpho::NullEnv>
struct f_tarjan_map
{
public:
@@ -63,7 +65,7 @@
typedef oln_value_type(input_type) value_type;
typedef typename mute<input_type, point_type>::ret parent_type;
typedef typename mute<input_type, bool>::ret is_proc_type;
- typedef typename D::lambda_type lambda_type;
+ typedef attr_lambda_type(D) lambda_type;
// e.g.,
// when I is image2d<int_u8> and D is area_type, we've got:
@@ -82,8 +84,7 @@
const lambda_type& lambda,
const Env & env = Env());
- template<typename DestValue>
- typename mute<I, DestValue>::ret
+ oln_concrete_type(I)
res()
{
return output;
@@ -128,21 +129,92 @@
* See "Fast morphological attribute operations using Tarjan's union-find
* algorithm" by Michael H. F. Wilkinson and Jos B. T. M. Roerdink
*/
- template <typename DestValue, class I, class D, class Env, class N>
- typename mute<I, DestValue>::ret
+ template <class D, class I, class N>
+ oln_concrete_type(I)
tarjan_map(bool is_closing,
const abstract::image<I>& input,
const abstract::neighborhood<N>& ng,
- const typename D::lambda_type& lambda,
- const Env & env = Env())
+ const attr_lambda_type(D)& lambda,
+ const attr_env_type(D)& env/* = Env()*/)
{
- oln::morpho::f_tarjan_map<I, D, Env > t(is_closing,
+ oln::morpho::slow::f_tarjan_map<I, D, attr_env_type(D) > t(is_closing,
input,
ng,
lambda,
env);
- return t. template res<DestValue>();
+ return t.res();
+ }
+
+ /*! Some macro to declare friendly function for different attributes
+ * opening/closing
+ */
+# define xxx_opening_map_decl(T) \
+template <class I, class N> \
+oln_concrete_type(I) \
+T##_opening(const abstract::image<I>& input, \
+ const abstract::neighborhood<N>& ng, \
+ const attr_lambda_type(T##_type<>)& lambda) \
+ { \
+ return tarjan_map<T##_type<>, I, N>(false, input, ng, lambda, \
+ attr_env_type(T##_type<>)()); \
+ }
+
+ // same but attribute take care of the image type
+# define xxx_opening_im_map_decl(T) \
+template <class I, class N> \
+oln_concrete_type(I) \
+T##_opening(const abstract::image<I>& input, \
+ const abstract::neighborhood<N>& ng, \
+ const attr_lambda_type(T##_type<I>)& lambda) \
+ { \
+ return tarjan_map<T##_type<I>, I, N>(false, input, ng, lambda, \
+ attr_env_type(T##_type<I>)()); \
}
+
+ //return input;
+ // return tarjan_map<T##_type, I, N>(false, input, ng, lambda, attr_env_type(T##_type<>)());
+# define xxx_closing_map_decl(T) \
+template <class I, class N> \
+oln_concrete_type(I) \
+T##_closing(const abstract::image<I>& input, \
+ const abstract::neighborhood<N>& ng, \
+ const attr_lambda_type(T##_type<>)& lambda) \
+ { \
+ return tarjan_map<T##_type<>, I, N>(true, input, ng, lambda, attr_env_type(T##_type<>)()); \
+ }
+
+ // same but attribute take care of the image type
+# define xxx_closing_im_map_decl(T) \
+template <class I, class N> \
+oln_concrete_type(I) \
+T##_closing(const abstract::image<I>& input, \
+ const abstract::neighborhood<N>& ng, \
+ const attr_lambda_type(T##_type<I>)& lambda) \
+ { \
+ return tarjan_map<T##_type<I>, I, N>(true, input, ng, lambda, attr_env_type(T##_type<I>)()); \
+ }
+
+ xxx_opening_map_decl(area);
+ xxx_closing_map_decl(area);
+ xxx_opening_map_decl(volume);
+ xxx_closing_map_decl(volume);
+ xxx_opening_map_decl(height);
+ xxx_closing_map_decl(height);
+ xxx_opening_map_decl(maxvalue);
+ xxx_closing_map_decl(maxvalue);
+ xxx_opening_map_decl(minvalue);
+ xxx_closing_map_decl(minvalue);
+ xxx_opening_im_map_decl(disk);
+ xxx_closing_im_map_decl(disk);
+ xxx_opening_im_map_decl(dist);
+ xxx_closing_im_map_decl(dist);
+ xxx_closing_im_map_decl(square);
+ xxx_opening_im_map_decl(square);
+ xxx_closing_im_map_decl(rectangle);
+ xxx_opening_im_map_decl(rectangle);
+
+
+ } // end of namespace slow
} // end of namespace morpho
} // end of namespace oln
Index: olena/tests/morpho/tests/attribute
--- olena/tests/morpho/tests/attribute Tue, 10 Feb 2004 19:49:03 +0100 van-vl_n (oln/j/51_attribute 1.1 644)
+++ olena/tests/morpho/tests/attribute Mon, 16 Feb 2004 08:40:49 +0100 palma_g (oln/j/51_attribute 1.1 644)
@@ -28,10 +28,10 @@
bool fail(false);
typedef image2d<int_u8> img_type;
- typedef oln::morpho::tarjan::area_type<unsigned> area_type;
+ typedef oln::morpho::area_type<unsigned> area_type;
const area_type::lambda_type area = 100;
const neighborhood2d nb = neighb_c8();
- const oln::morpho::tarjan::NullEnv env;
+ // const oln::morpho::NullEnv env;
img_type lena = load(rdata("lena.pgm"));
img_type lena_sure_closing = oln::morpho::sure_minima_killer(lena, area, nb);
@@ -41,9 +41,10 @@
img_type lena_tst_closing;
std::cerr << "testing tarjan_map..." << std::endl;
- lena_tst_closing = morpho::tarjan_map<ntg::int_u8,img_type,area_type>(true, lena, nb, area, env);
- lena_tst_opening= morpho::tarjan_map<ntg::int_u8,img_type,area_type>(false, lena, nb, area, env);
-
+// lena_tst_closing = morpho::slow::tarjan_map<area_type,ntg::int_u8,img_type>(true, lena, nb, area, env);
+// lena_tst_opening= morpho::slow::tarjan_map<area_type,ntg::int_u8,img_type>(false, lena, nb, area, env);
+ lena_tst_closing = morpho::slow::area_closing(lena, nb, area);
+ lena_tst_opening = morpho::slow::area_opening(lena, nb, area);
fail = fail ||
!level::is_equal(lena_sure_closing, lena_tst_closing)||
@@ -59,8 +60,8 @@
std::cerr << "fail:" << fail << std::endl;
std::cerr << "testing area_closin and area_opeing..." << std::endl;
- lena_tst_closing = morpho::tarjan::area_closing(lena, nb, area);
- lena_tst_opening = morpho::tarjan::area_opening(lena, nb, area);
+ lena_tst_closing = morpho::fast::area_closing(lena, nb, area);
+ lena_tst_opening = morpho::fast::area_opening(lena, nb, area);
fail = fail ||
!level::is_equal(lena_sure_closing, lena_tst_closing)||
!level::is_equal(lena_sure_opening, lena_tst_opening);
@@ -70,12 +71,13 @@
return fail;
}
-
bool
check_attribute()
{
+ bool fail = false;
+
//FIXME attributes should be checked
- return false;
+ return fail;
}
Index: olena/tests/morpho/tests/attr_op_cl
--- olena/tests/morpho/tests/attr_op_cl Mon, 16 Feb 2004 19:05:52 +0100 palma_g ()
+++ olena/tests/morpho/tests/attr_op_cl Mon, 16 Feb 2004 18:48:30 +0100 palma_g (oln/k/0_attr_op_cl 644)
@@ -0,0 +1,77 @@
+// -*- c++ -*-
+
+#include <oln/basics2d.hh>
+#include <oln/morpho/attribute_closing_opening.hh>
+#include <oln/morpho/attribute_closing_opening_map.hh>
+#include <oln/level/compare.hh>
+#include <ntg/all.hh>
+
+#include "check.hh"
+#include "data.hh"
+
+using namespace oln;
+using namespace ntg;
+
+#define OK_OR_FAIL \
+ std::cout << "OK" << std::endl; \
+ else \
+ { \
+ std::cout << "FAIL" << std::endl; \
+ fail = true; \
+ }
+
+# define test_op_cl(T, A, im, lambda) \
+{ \
+ bool last_fail = fail; \
+ fail = false; \
+ { \
+ image2d<T> im2 = oln::morpho::slow::A##_opening(im, neighb_c4(), lambda); \
+ image2d<T> im1 = oln::morpho::fast::A##_opening(im, neighb_c4(), lambda); \
+ image2d<T>::iter_type it(lena); \
+ std::cout << #A << " opening: "; \
+ for_all(it) \
+ { \
+ if (im1[it] != im2[it]) \
+ fail = true; \
+ } \
+ if (!fail) \
+ OK_OR_FAIL \
+ } \
+ { \
+ image2d<T> im2 = oln::morpho::slow::A##_closing(im, neighb_c4(), lambda); \
+ image2d<T> im1 = oln::morpho::fast::A##_closing(im, neighb_c4(), lambda); \
+ image2d<T>::iter_type it(lena); \
+ std::cout << #A <<" closing: "; \
+ for_all(it) \
+ { \
+ if (im1[it] != im2[it]) \
+ fail = true; \
+ } \
+ if (!fail) \
+ OK_OR_FAIL \
+ } \
+ fail = last_fail || fail; \
+}
+
+
+bool
+check()
+{
+ bool fail = false;
+
+ image2d<int_u8> lena(rdata("lena256.pgm"));
+ std::cout << std::endl;
+ test_op_cl(int_u8, area, lena, 200)
+ test_op_cl(int_u8, volume, lena, 200)
+ test_op_cl(int_u8, height, lena, 4)
+ test_op_cl(int_u8, maxvalue, lena, 100)
+ test_op_cl(int_u8, minvalue, lena, 100)
+ test_op_cl(int_u8, dist, lena, 100)
+ test_op_cl(int_u8, disk, lena, 100)
+ test_op_cl(int_u8, square, lena, 50)
+
+ ntg::vec<2, unsigned, mlc::final> lambda;
+ test_op_cl(int_u8, rectangle, lena, lambda)
+
+ return fail;
+}
--
Giovanni Palma
EPITA - promo 2005 - membre d'EpX - LRDE
Mob. : +33 (0)6 60 97 31 74
1
0
* problemes des namespaces.
* la doc
1
0
Oleneux, Oleneux
Il faudrait que chacun mette à jour sa section de la page assignement
du twiki, de manière à la rendre beaucoup plus précise qu'elle ne l'est
actuellement. L'idéal serait qu'y figure notre travail hebdomadaire.
http://www.lrde.epita.fr/cgi-bin/twiki/view/Projects/OlenaAssignments
--
Simon Odou
simon(a)lrde.epita.fr
1
0
Index: ChangeLog
from Giovanni Palma <giovanni(a)lrde.epita.fr>
* NEWS: Describe color and attributes improvement.
Index: integre/ChangeLog
from Giovanni Palma <giovanni(a)lrde.epita.fr>
* ntg/vect/vec.hh: Add sup() function to vec traits.
Index: metalic/ChangeLog
from Giovanni Palma <giovanni(a)lrde.epita.fr>
* mlc/type.hh: Add some useful macros.
Index: olena/ChangeLog
from Giovanni Palma <giovanni(a)lrde.epita.fr>
* oln/morpho/attributes.hh: Add new attributes. Correct the olders.
* oln/morpho/attribute_union_find.hh: Change lambda type from ref
to pointer.
* oln/morpho/attribute_closing_opening.hh: Fix some argument
types. Add new declarations.
Index: NEWS
--- NEWS Fri, 08 Aug 2003 16:27:13 +0200 david (oln/0_NEWS 1.16 640)
+++ NEWS Mon, 09 Feb 2004 18:44:40 +0100 palma_g (oln/0_NEWS 1.16 640)
@@ -1,3 +1,13 @@
+Olena 0.10 Not yet
+
+ * Attribute opening/closing enhancement
+ - Make the algothim more generic.
+ - Add a lot of attributes.
+
+ * Change the color conversion system
+ - CIE RGB is the main color system.
+ - Conversion between 2 color systems should pass by the RGB one.
+
Olena 0.9 August 8, 2003
* New static hierarchy paradigm
Index: metalic/mlc/type.hh
--- metalic/mlc/type.hh Fri, 07 Nov 2003 17:19:10 +0100 burrus_n (oln/c/21_type.hh 1.27 640)
+++ metalic/mlc/type.hh Mon, 09 Feb 2004 18:14:34 +0100 palma_g (oln/c/21_type.hh 1.27 640)
@@ -237,6 +237,13 @@
# define mlc_exact_type(T) typename mlc::exact< T >::ret
# define mlc_exact_type_(T) mlc::exact< T >::ret
+// Return the exact virtual type of two given types (inheritance determination).
+
+# define mlc_exact_vt_type(T, Exact) typename mlc::exact_vt<T, Exact>::ret
+# define mlc_2_exact_vt_type(self, T, Exact) typename mlc::exact_vt<self<T, Exact>, Exact>::ret
+# define mlc_exact_vt_type_(T, Exact) mlc::exact_vt<T, Exact>::ret
+# define mlc_2_exact_vt_type_(self, T, Exact) mlc::exact_vt<self<T, Exact>, Exact>::ret
+
namespace mlc
{
@@ -299,4 +306,10 @@
# define mlc_init_static_hierarchy(Exact)
+/*---------.
+| dispatch |
+`---------*/
+
+# define mlc_dispatch(Fun) return exact().Fun##_impl
+
#endif // ! METALIC_TYPE_HH
Index: olena/oln/morpho/attribute_closing_opening.hh
--- olena/oln/morpho/attribute_closing_opening.hh Fri, 06 Feb 2004 16:02:37 +0100 palma_g (oln/q/49_attribute_ 1.11 640)
+++ olena/oln/morpho/attribute_closing_opening.hh Fri, 06 Feb 2004 17:44:37 +0100 palma_g (oln/q/49_attribute_ 1.11 640)
@@ -41,7 +41,7 @@
oln_concrete_type(I)
attr_closing_(const abstract::non_vectorial_image<I>& input,
const abstract::neighborhood<N>& Ng,
- const attr_lambda_type(A) lambda)
+ const attr_lambda_type(A) &lambda)
{
typedef tarjan::tarjan_set<oln_concrete_type(I), A > tarjan_set_type;
tarjan_set_type area_closing(input.exact(), attr_env_type(A)());
@@ -53,7 +53,7 @@
oln_concrete_type(I)
attr_opening_(const abstract::non_vectorial_image<I>& input,
const abstract::neighborhood<N>& Ng,
- const attr_lambda_type(A) lambda)
+ const attr_lambda_type(A) &lambda)
{
typedef tarjan::tarjan_set<oln_concrete_type(I), A > tarjan_set_type;
tarjan_set_type area_opening(input.exact(), attr_env_type(A)());
@@ -68,7 +68,7 @@
oln_concrete_type(I) \
T##_opening(const abstract::non_vectorial_image<I>& input, \
const abstract::neighborhood<N>& Ng, \
- const attr_lambda_type(T##_type<unsigned>) lambda) \
+ const attr_lambda_type(T##_type<unsigned>) &lambda) \
{ \
return internal::attr_opening_<I, N, T##_type<unsigned> >(input, Ng, lambda); \
}
@@ -78,7 +78,7 @@
oln_concrete_type(I) \
T##_closing(const abstract::non_vectorial_image<I>& input, \
const abstract::neighborhood<N>& Ng, \
- const attr_lambda_type(T##_type<unsigned>) lambda) \
+ const attr_lambda_type(T##_type<unsigned>) &lambda) \
{ \
return internal::attr_closing_<I, N, T##_type<unsigned> >(input, Ng, lambda); \
}
@@ -90,7 +90,7 @@
oln_concrete_type(I) \
T##_opening(const abstract::non_vectorial_image<I>& input, \
const abstract::neighborhood<N>& Ng, \
- const attr_lambda_type(T##_type<I>) lambda) \
+ const attr_lambda_type(T##_type<I>) &lambda) \
{ \
return internal::attr_opening_<I, N, T##_type<I> >(input, Ng, lambda); \
}
@@ -100,7 +100,7 @@
oln_concrete_type(I) \
T##_closing(const abstract::non_vectorial_image<I>& input, \
const abstract::neighborhood<N>& Ng, \
- const attr_lambda_type(T##_type<I>) lambda) \
+ const attr_lambda_type(T##_type<I>) &lambda) \
{ \
return internal::attr_closing_<I, N, T##_type<I> >(input, Ng, lambda); \
}
@@ -159,6 +159,9 @@
xxx_closing_im_decl(dist)
xxx_closing_im_decl(square)
xxx_opening_im_decl(square)
+ xxx_closing_im_decl(rectangle)
+ xxx_opening_im_decl(rectangle)
+
}
}
}
Index: olena/oln/morpho/attribute_union_find.hh
--- olena/oln/morpho/attribute_union_find.hh Fri, 06 Feb 2004 16:02:37 +0100 palma_g (oln/q/50_attribute_ 1.9 640)
+++ olena/oln/morpho/attribute_union_find.hh Fri, 06 Feb 2004 17:55:37 +0100 palma_g (oln/q/50_attribute_ 1.9 640)
@@ -150,7 +150,7 @@
{
precondition((parent_[x] == ACTIVE()) || (parent_[x] == INACTIVE()));
precondition((parent_[y] == ACTIVE()) || (parent_[y] == INACTIVE()));
- return ( (input_[x] == input_[y]) || (aux_data_[x] < lambda_));
+ return ( (input_[x] == input_[y]) || (aux_data_[x] < *lambda_));
}
void
@@ -165,7 +165,7 @@
}
else
{
- aux_data_[p] = lambda_;
+ aux_data_[p] = *lambda_;
}
}
@@ -177,7 +177,7 @@
const abstract::neighborhood<N>& Ng,
const bool closing)
{
- lambda_ = lambda;
+ lambda_ = λ
std::vector<point_type> I(input_.npoints());
@@ -232,7 +232,7 @@
const image_type & input_;
typename mute<T, point_type>::ret parent_;
typename mute<T, ATTRIBUTE>::ret aux_data_;
- lambda_type lambda_;
+ const lambda_type *lambda_;
const env_type env_;
};
}
Index: integre/ntg/vect/vec.hh
--- integre/ntg/vect/vec.hh Thu, 27 Nov 2003 11:26:27 +0100 burrus_n (oln/t/18_vec.hh 1.7.1.1 640)
+++ integre/ntg/vect/vec.hh Mon, 09 Feb 2004 18:32:07 +0100 palma_g (oln/t/18_vec.hh 1.7.1.1 640)
@@ -105,6 +105,23 @@
typedef self base_type;
typedef T storage_type[N];
typedef typename typetraits<T>::cumul_type cumul_type[N];
+
+ static const self &sup()
+ {
+ static self tmp = mkSup();
+
+ return tmp;
+ };
+
+ protected:
+ static self mkSup()
+ {
+ self tmp;
+
+ for (unsigned i = 0; i < N; ++i)
+ tmp[i] = ntg_sup_val(T);
+ return tmp;
+ };
};
} // end of internal.
Index: olena/oln/morpho/attributes.hh
--- olena/oln/morpho/attributes.hh Fri, 06 Feb 2004 16:02:37 +0100 palma_g (oln/j/45_attributes 1.1 644)
+++ olena/oln/morpho/attributes.hh Mon, 09 Feb 2004 18:37:42 +0100 palma_g (oln/j/45_attributes 1.1 644)
@@ -27,12 +27,15 @@
#ifndef ATTRIBUTES_HH
# define ATTRIBUTES_HH
+# include <mlc/type.hh>
+# include <vector>
+
// some usefull macros
// those macros should be moved into mlc
-# define oln_exact_vt_type(T, Exact) typename mlc::exact_vt<T, Exact>::ret
-# define oln_2_exact_vt_type(self, T, Exact) typename mlc::exact_vt<self<T, Exact>, Exact>::ret
-# define dispatch(Fun) return exact().Fun##_impl
+// # define mlc_exact_vt_type(T, Exact) typename mlc::exact_vt<T, Exact>::ret
+// # define oln_2_exact_vt_type(self, T, Exact) typename mlc::exact_vt<self<T, Exact>, Exact>::ret
+// # define dispatch(Fun) return exact().Fun##_impl
// attribute dedicated macros
# define attr_lambda_type(T) typename attr_traits<T>::lambda_type
@@ -40,38 +43,23 @@
# define attr_value_type(T) typename attr_traits<T>::value_type
# define attr_type_decl(slef_type) \
- typedef oln_exact_vt_type(self_type, Exact) exact_type; \
+ typedef mlc_exact_vt_type(self_type, Exact) exact_type; \
typedef attr_value_type(exact_type) value_type; \
typedef attr_env_type(exact_type) env_type; \
typedef attr_lambda_type(exact_type) lambda_type
-
-
-// misc
-namespace my {
-
- int diffabs(int v1, int v2)
+namespace oln {
+ namespace morpho {
+ namespace tarjan {
+ namespace tools {
+ // should be moved elsewhere
+ template <class T>
+ T diffabs(const T &v1, const T &v2)
{
return v1 > v2 ? v1 - v2 : v2 - v1;
}
- template <class T>
- T max(T v1, T v2)
- {
- return v1 > v2 ? v1 : v2;
}
-
- template <class T>
- T min(T v1, T v2)
- {
- return v1 < v2 ? v1 : v2;
- }
-
-} // end of namespace my
-
-namespace oln {
- namespace morpho {
- namespace tarjan {
// environment herarchy
// not used yet
template <class Exact>
@@ -104,22 +92,28 @@
void operator+=(const exact_type& rhs)
{
- dispatch(pe)(rhs);
+ mlc_dispatch(pe)(rhs);
};
- void operator=(lambda_type lambda)
+ bool operator>=(const lambda_type &lambda) const
{
- dispatch(equal)(lambda);
+ mlc_dispatch(ge)(lambda);
};
bool operator<(const lambda_type& lambda) const
{
- dispatch(less)(lambda);
+ mlc_dispatch(less)(lambda);
};
bool operator!=(const lambda_type& lambda) const
{
- dispatch(ne)(lambda);
+ mlc_dispatch(ne)(lambda);
+ };
+
+ // impl
+ bool ge_impl(const lambda_type &lambda) const
+ {
+ return !(*this < lambda);
};
protected:
@@ -131,9 +125,9 @@
| area |
*-----------*/
- template <class T, class Exact = mlc::final>
+ template <class T = unsigned, class Exact = mlc::final>
class area_type:
- public attribute<oln_2_exact_vt_type(area_type, T, Exact)>
+ public attribute<mlc_2_exact_vt_type(area_type, T, Exact)>
{
public:
typedef area_type<T, Exact> self_type;
@@ -160,11 +154,6 @@
value_ += rhs.value_;
};
- void equal_impl(lambda_type lambda)
- {
- value_ = lambda;
- };
-
bool less_impl(const lambda_type& lambda) const
{
return value_ < lambda;
@@ -186,9 +175,9 @@
| volume |
*-----------*/
- template <class T, class Exact = mlc::final>
+ template <class T = unsigned, class Exact = mlc::final>
class volume_type:
- public attribute<oln_2_exact_vt_type(volume_type, T, Exact)>
+ public attribute<mlc_2_exact_vt_type(volume_type, T, Exact)>
{
public:
typedef volume_type<T, Exact> self_type;
@@ -216,17 +205,17 @@
// interface part
const value_type &getValue() const
{
- dispatch(getValue)();
+ mlc_dispatch(getValue)();
};
const value_type &getReflevel() const
{
- dispatch(getReflevel)();
+ mlc_dispatch(getReflevel)();
};
const value_type &getArea() const
{
- dispatch(getArea)();
+ mlc_dispatch(getArea)();
};
// impl part
@@ -245,14 +234,9 @@
return area_;
};
- void equal_impl(lambda_type lambda)
- {
- value_ = lambda;
- };
-
void pe_impl(const volume_type& rhs)
{
- value_ += rhs.getValue() + area_ * my::diffabs(reflevel_, rhs.getReflevel());
+ value_ += rhs.getValue() + area_ * tools::diffabs(reflevel_, rhs.getReflevel());
area_ += rhs.getArea();
};
@@ -276,9 +260,9 @@
| height |
*-----------*/
- template <class T, class Exact = mlc::final>
+ template <class T = unsigned, class Exact = mlc::final>
class height_type:
- public attribute<oln_2_exact_vt_type(height_type, T, Exact)>
+ public attribute<mlc_2_exact_vt_type(height_type, T, Exact)>
{
public:
typedef height_type<T, Exact> self_type;
@@ -297,13 +281,13 @@
const oln_point_type(I)& p,
const env_type&):
reflevel_(input[p]),
- value_(0)
+ value_(ntg_zero_val(value_type))
{
};
const value_type &getReflevel() const
{
- dispatch(getReflevel)();
+ mlc_dispatch(getReflevel)();
};
// impl part
@@ -312,14 +296,9 @@
return reflevel_;
};
- void equal_impl(lambda_type lambda)
- {
- value_ = lambda;
- };
-
void pe_impl(const height_type& rhs)
{
- value_ = my::diffabs(reflevel_, rhs.getReflevel());
+ value_ = tools::diffabs(reflevel_, rhs.getReflevel());
};
bool less_impl(const lambda_type& lambda) const
@@ -342,9 +321,9 @@
| maxvalue |
*-----------*/
- template <class T, class Exact = mlc::final>
+ template <class T = unsigned, class Exact = mlc::final>
class maxvalue_type:
- public attribute<oln_2_exact_vt_type(maxvalue_type, T, Exact)>
+ public attribute<mlc_2_exact_vt_type(maxvalue_type, T, Exact)>
{
public:
typedef maxvalue_type<T, Exact> self_type;
@@ -368,7 +347,7 @@
const value_type &getValue() const
{
- dispatch(getValue)();
+ mlc_dispatch(getValue)();
};
const value_type &getValue_impl() const
@@ -378,7 +357,7 @@
void pe_impl(const maxvalue_type& rhs)
{
- value_ = my::max(value_, rhs.getValue());
+ value_ = ntg::max(value_, rhs.getValue());
};
bool less_impl(const lambda_type& lambda) const
@@ -400,9 +379,9 @@
| minvalue |
*-----------*/
- template <class T, class Exact = mlc::final>
+ template <class T = unsigned, class Exact = mlc::final>
class minvalue_type:
- public attribute<oln_2_exact_vt_type(minvalue_type, T, Exact)>
+ public attribute<mlc_2_exact_vt_type(minvalue_type, T, Exact)>
{
public:
typedef minvalue_type<T, Exact> self_type;
@@ -426,7 +405,7 @@
const value_type &getValue() const
{
- dispatch(getValue)();
+ mlc_dispatch(getValue)();
};
const value_type &getValue_impl() const
@@ -436,7 +415,7 @@
void pe_impl(const minvalue_type& rhs)
{
- value_ = my::min(value_, rhs.getValue());
+ value_ = ntg::min(value_, rhs.getValue());
};
bool less_impl(const lambda_type& lambda) const
@@ -460,7 +439,7 @@
template <class I, class Exact = mlc::final>
class disk_type:
- public attribute<oln_2_exact_vt_type(disk_type, I, Exact)>
+ public attribute<mlc_2_exact_vt_type(disk_type, I, Exact)>
{
public:
typedef disk_type<I, Exact> self_type;
@@ -487,7 +466,7 @@
const pts_type &getPts() const
{
- dispatch(getPts)();
+ mlc_dispatch(getPts)();
};
// impl
@@ -500,7 +479,7 @@
void pe_impl(const disk_type& rhs)
{
std::copy(rhs.getPts().begin(), rhs.getPts().end(), std::back_inserter(pts_));
- value_ = 0;
+ value_ = ntg_zero_val(value_type);
for (cst_iter_type p1 = pts_.begin(); p1 != pts_.end(); ++p1)
for (cst_iter_type p2 = pts_.begin(); p2 != pts_.end(); ++p2)
{
@@ -537,7 +516,7 @@
template <class I, class Exact = mlc::final>
class dist_type:
- public attribute<oln_2_exact_vt_type(dist_type, I, Exact)>
+ public attribute<mlc_2_exact_vt_type(dist_type, I, Exact)>
{
public:
typedef dist_type<I, Exact> self_type;
@@ -546,9 +525,6 @@
typedef oln_point_type(im_type) point_type;
typedef oln_dpoint_type(im_type) dpoint_type;
-// typedef float value_type;
-// typedef value_type lambda_type;
-
dist_type()
{
};
@@ -556,7 +532,7 @@
dist_type(const im_type&,
const point_type& p,
const env_type &) :
- value_(0),
+ value_(ntg_zero_val(value_type)),
center_(p)
{
};
@@ -567,7 +543,7 @@
const point_type &getCenter() const
{
- dispatch(getCenter)();
+ mlc_dispatch(getCenter)();
};
// impl
@@ -580,7 +556,7 @@
{
dpoint_type p = center_ - rhs.getCenter();
- value_ = 0;
+ value_ = ntg_zero_val(value_type);
for (int i = 0; i < point_traits<point_type>::dim; ++i)
value_ += p.nth(i) * p.nth(i);
value_ = sqrt(value_);
@@ -610,7 +586,7 @@
template <class I, class Exact = mlc::final>
class square_type:
- public attribute<oln_2_exact_vt_type(square_type, I, Exact)>
+ public attribute<mlc_2_exact_vt_type(square_type, I, Exact)>
{
public:
typedef square_type<I, Exact> self_type;
@@ -619,139 +595,177 @@
typedef oln_point_type(im_type) point_type;
typedef oln_dpoint_type(im_type) dpoint_type;
-// typedef unsigned value_type;
-// typedef value_type lambda_type;
+ enum {dim = point_traits<point_type>::dim};
square_type()
{
}
- square_type(const lambda_type &lambda) : value_(lambda)
+ square_type(const lambda_type &lambda):
+ mins_(dim),
+ maxs_(dim),
+ value_(lambda)
+ {
+ for (int i = 0; i < point_traits<point_type>::dim; ++i)
{
+ maxs_[i] = lambda;
+ mins_[i] = ntg_zero_val(coord);
+ }
};
square_type(const im_type&,
const point_type& p,
const env_type &) :
- value_(0)
+ mins_(dim), maxs_(dim), value_(ntg_zero_val(value_type))
{
- min_row_ = max_row_ = p.row();
- min_col_ = max_col_ = p.col();
+ for (int i = 0; i < dim; ++i)
+ mins_[i] = maxs_[i] = p.nth(i);
}
- int getMinRow() const
+ int getMin(int i) const
{
- dispatch(getMinRow)();
+ mlc_dispatch(getMin)(i);
};
- int getMaxRow() const
+ int getMax(int i) const
{
- dispatch(getMaxRow)();
+ mlc_dispatch(getMax)(i);
};
- int getMaxCol() const
+ // impl
+ int getMin_impl(int i) const
{
- dispatch(getMaxCol)();
+ precondition(i < dim);
+ return mins_[i];
};
- int getMinCol() const
+ int getMax_impl(int i) const
{
- dispatch(getMinCol)();
+ precondition(i < dim);
+ return maxs_[i];
};
- // impl
- int getMinRow_impl() const
+ void pe_impl(const square_type &rhs)
+ {
+ for (int i = 0; i < dim; ++i)
+ {
+ mins_[i] = ntg::min(mins_[i], rhs.getMin(i));
+ maxs_[i] = ntg::max(maxs_[i], rhs.getMax(i));
+ }
+ value_ = maxs_[0] - mins_[0];
+ for (int i = 1; i < dim; ++i)
+ if (value_ < value_type(maxs_[i] - mins_[i]))
+ value_ = maxs_[i] - mins_[i];
+ }
+
+ bool less_impl(const lambda_type &lambda) const
+ {
+ return value_ < lambda;
+ }
+
+ bool ne_impl(const lambda_type &lambda) const
{
- return min_row_;
+ return value_ != lambda;
};
- int getMaxRow_impl() const
+ protected:
+ std::vector<coord> mins_;
+ std::vector<coord> maxs_;
+ value_type value_;
+ };
+
+
+
+ /*-----------*
+ | rectangle |
+ *-----------*/
+ template <class I, class Exact = mlc::final>
+ class rectangle_type:
+ public attribute<mlc_2_exact_vt_type(rectangle_type, I, Exact)>
{
- return max_row_;
+ public:
+ typedef rectangle_type<I, Exact> self_type;
+ attr_type_decl(self_type);
+ typedef abstract::image<mlc_exact_type(I)> im_type;
+ typedef oln_point_type(im_type) point_type;
+ typedef oln_dpoint_type(im_type) dpoint_type;
+ enum {dim = point_traits<point_type>::dim };
+
+ rectangle_type(const lambda_type &lambda): maxs_(dim), mins_(dim)
+ {
+ for (int i = 0; i < dim; ++i)
+ {
+ mins_[i] = ntg_zero_val(value_type);
+ maxs_[i] = lambda[i];
+ }
};
- int getMaxCol_impl() const
+ rectangle_type()
+ {
+ }
+
+ rectangle_type(const im_type&, const point_type &p, const env_type &): maxs_(dim), mins_(dim)
+ {
+ for (int i = 0; i < dim; ++i)
+ mins_[i] = maxs_[i] = p.nth(i);
+ }
+
+ value_type getMin(int i) const
{
- return max_col_;
+ mlc_dispatch(getMin)(i);
};
- int getMinCol_impl() const
+ value_type getMax(int i) const
{
- return min_col_;
+ mlc_dispatch(getMax)(i);
};
- void pe_impl(const square_type& rhs)
+ // impl
+ value_type getMin_impl(int i) const
+ {
+ precondition(i < point_traits<point_type>::dim);
+ return mins_[i];
+ };
+
+ value_type getMax_impl(int i) const
+ {
+ precondition(i < point_traits<point_type>::dim);
+ return maxs_[i];
+ };
+
+ void pe_impl(const rectangle_type &rhs)
+ {
+ for (int i = 0; i < dim; ++i)
{
- min_row_ = my::min(min_row_, rhs.getMinRow());
- min_col_ = my::min(min_col_, rhs.getMinCol());
- max_row_ = my::max(max_row_, rhs.getMaxRow());
- max_col_ = my::max(max_col_, rhs.getMaxCol());
- value_ = my::max(max_row_ - min_row_, max_col_ - min_col_);
+ mins_[i] = ntg::min(mins_[i], rhs.getMin(i));
+ maxs_[i] = ntg::max(maxs_[i], rhs.getMax(i));
+ }
}
bool less_impl(const lambda_type& lambda) const
{
- return value_ < lambda;
+ for (int i = 0; i < dim; ++i)
+ if ((maxs_[i] - mins_[i]) >= lambda[i])
+ return false;
+ return true;
}
bool ne_impl(const lambda_type &lambda) const
{
- return value_ != lambda;
+ for (int i = 0; i < dim; ++i)
+ if ((maxs_[i] - mins_[i]) == lambda[i])
+ return false;
+ return true;
};
protected:
- value_type value_;
- int min_row_;
- int max_row_;
- int min_col_;
- int max_col_;
+ std::vector<value_type> maxs_;
+ std::vector<value_type> mins_;
};
-
-
-// /*-----------*
-// | rectangle |
-// *-----------*/
-// template <class I, class Exact = mlc::final>
-// struct rectangle_type
-// {
-// typedef unsigned value_type;
-// typedef std::pair<value_type,value_type> lambda_type;
-
-// value_type drow, dcol;
-// int min_row, max_row, min_col, max_col;
-
-// rectangle_type()
-// {
-// }
-
-// template <class T>
-// rectangle_type(const image2d<T>&, const point2d& p) :
-// drow(0),
-// dcol(0)
-// {
-// min_row = max_row = p.row();
-// min_col = max_col = p.col();
-// }
-
-// void operator+=(const rectangle_type& rhs)
-// {
-// min_row = my::min(min_row, rhs.min_row);
-// min_col = my::min(min_col, rhs.min_col);
-// max_row = my::max(max_row, rhs.max_row);
-// max_col = my::max(max_col, rhs.max_col);
-// drow = max_row - min_row;
-// dcol = max_col - min_col;
-// }
-
-// bool operator>=(const lambda_type& lambda) const
-// {
-// return drow >= lambda.first || dcol >= lambda.second;
-// }
-// };
-
-
-// traits specialisations
+ /*-------------------------
+ | traits specialisations |
+ \------------------------*/
// volume traits
@@ -826,16 +840,18 @@
typedef NullEnv env_type;
};
-// // rectangle traits
-// tempalte <class Exact>
-// typedef unsigned value_type;
-// typedef std::pair<value_type,value_type> lambda_type;
-
+ // rectangle traits
+ template <class I, class Exact>
+ struct attr_traits<rectangle_type<I, Exact> >
+ {
+ typedef unsigned value_type;
+ typedef ntg::vec<I::dim, value_type, mlc::final> lambda_type;
+ typedef NullEnv env_type;
+ };
}
}
}
-
/*-----------*
| diamond |
*-----------*/
--
Giovanni Palma
EPITA - promo 2005 - membre d'EpX - LRDE
Mob. : +33 (0)6 60 97 31 74
2
3
Index: ChangeLog
from Giovanni Palma <giovanni(a)lrde.epita.fr>
* NEWS: Describe behavior hierarchy.
Index: olena/ChangeLog
from Giovanni Palma <giovanni(a)lrde.epita.fr>
* oln/core/abstract/behavior.hh: Add behavior hierarchy (abstract
part).
* oln/core/behavior.hh: Add behavior hierarchy content.
* oln/morpho/attributes.hh: Correct 'ifndef' macros.
* tests/convol/tests/uniform_gauss: Improve tests.
* oln/convol/fast_gaussian.hh: Make the gaussian take care of the
behavior hierarchy.
* oln/convol/fast_gaussian.hxx: Likewise.
Index: NEWS
--- NEWS Mon, 09 Feb 2004 18:57:03 +0100 palma_g (oln/0_NEWS 1.17 640)
+++ NEWS Tue, 10 Feb 2004 15:25:07 +0100 palma_g (oln/0_NEWS 1.17 640)
@@ -1,11 +1,18 @@
Olena 0.10 Not yet
+ * Border behavior can be controlled with the behavior hierarchy.
+ If an algorithm support it, you can choose the way the image
+ border will be seen. Three behaviors are available: mirror,
+ replicate or user defined value.
+
* Attribute opening/closing enhancement
- - Make the algothim more generic.
- - Add a lot of attributes.
+ - Make the algorithm more generic.
+ - Add a lot of attributes (area, disk, square, dist,
+ rectangle, volume, height, maxvalue, minvalue).
* Change the color conversion system
- - CIE RGB is the main color system.
+ - CIE RGB is the main color system e.g. it can be converted
+ directly into any other color system.
- Conversion between 2 color systems should pass by the RGB one.
Olena 0.9 August 8, 2003
Index: olena/oln/convol/fast_gaussian.hh
--- olena/oln/convol/fast_gaussian.hh Thu, 07 Aug 2003 02:08:21 +0200 david (oln/26_fast_gauss 1.6.1.6.1.3 640)
+++ olena/oln/convol/fast_gaussian.hh Tue, 10 Feb 2004 14:56:04 +0100 palma_g (oln/26_fast_gauss 1.6.1.6.1.3 640)
@@ -31,7 +31,7 @@
# include <oln/basics.hh>
# include <oln/convert/basics.hh>
# include <ntg/float.hh>
-
+# include <oln/core/behavior.hh>
//
// Gaussian filter implementation from
// "Recursively implementing the gaussian and its derivatives"
@@ -44,39 +44,66 @@
// FIXME: add tests!
- template <class C, class B, class I>
+ template <class C, class B, class I, class BE>
typename mute<I, typename convoutput<C, B, oln_value_type(I)>::ret>::ret
gaussian(const convert::abstract::conversion<C, B>& input_conv,
- const abstract::image<I>& in, ntg::float_s sigma);
+ const abstract::image<I>& in, ntg::float_s sigma,
+ const abstract::behavior<BE> &behavior);
- template <class C, class B, class I>
+ template <class C, class B, class I, class BE>
typename mute<I, typename convoutput<C, B, oln_value_type(I)>::ret>::ret
gaussian_derivative(const convert::abstract::conversion<C, B>& input_conv,
- const abstract::image<I>& in, ntg::float_s sigma);
- template <class C, class B, class I>
+ const abstract::image<I>& in, ntg::float_s sigma,
+ const abstract::behavior<BE> &behavior);
+ template <class C, class B, class I, class BE>
typename mute<I, typename convoutput<C, B, oln_value_type(I)>::ret>::ret
gaussian_second_derivative(const convert::abstract::conversion<C, B>& input_conv,
const abstract::image<I>& in,
- ntg::float_s sigma);
+ ntg::float_s sigma,
+ const abstract::behavior<BE> &behavior);
/* Same functions, with a default conversion. */
+ template <class I, class BE> inline
+ oln_concrete_type(I)
+ gaussian(const abstract::image<I>& in, ntg::float_s sigma,
+ const abstract::behavior<BE> &behavior)
+ { return gaussian(convert::force<oln_value_type(I)>(), in, sigma,
+ behavior); }
+
+ template <class I, class BE> inline
+ oln_concrete_type(I)
+ gaussian_derivative(const abstract::image<I>& in, ntg::float_s sigma,
+ const abstract::behavior<BE> &behavior)
+ { return gaussian_derivative(convert::force<oln_value_type(I)>(), in, sigma,
+ behavior); }
+
+ template <class I, class BE> inline
+ oln_concrete_type(I)
+ gaussian_second_derivative(const abstract::image<I>& in,
+ ntg::float_s sigma,
+ const abstract::behavior<BE> &behavior = mirror_behavior<>())
+ { return gaussian_second_derivative(convert::force<oln_value_type(I)>(),
+ in, sigma, behavior); }
+
+ /* Same functions, with a default behavior (mirror_behavior). */
template <class I> inline
oln_concrete_type(I)
gaussian(const abstract::image<I>& in, ntg::float_s sigma)
- { return gaussian(convert::force<oln_value_type(I)>(), in, sigma); }
+ { return gaussian(convert::force<oln_value_type(I)>(), in, sigma,
+ mirror_bhv()); }
template <class I> inline
oln_concrete_type(I)
gaussian_derivative(const abstract::image<I>& in, ntg::float_s sigma)
- { return gaussian_derivative(convert::force<oln_value_type(I)>(), in, sigma); }
+ { return gaussian_derivative(convert::force<oln_value_type(I)>(), in, sigma,
+ mirror_bhv()); }
template <class I> inline
oln_concrete_type(I)
- gaussian_second_derivative(const abstract::image<I>& in,
- ntg::float_s sigma)
- { return gaussian_second_derivative(convert::force<oln_value_type(I)>(),
- in, sigma); }
+ gaussian_second_derivative(const abstract::image<I>& in, ntg::float_s sigma)
+ { return gaussian_second_derivative(convert::force<oln_value_type(I)>(), in, sigma,
+ mirror_bhv()); }
}
}
}
Index: olena/oln/convol/fast_gaussian.hxx
--- olena/oln/convol/fast_gaussian.hxx Wed, 28 Jan 2004 16:28:44 +0100 palma_g (oln/25_fast_gauss 1.7.1.8.1.5 640)
+++ olena/oln/convol/fast_gaussian.hxx Tue, 10 Feb 2004 13:09:29 +0100 palma_g (oln/25_fast_gauss 1.7.1.8.1.5 640)
@@ -230,12 +230,13 @@
}
};
- template <class C, class B, class I, class F>
+ template <class C, class B, class I, class F, class BE>
typename mute<I, typename convoutput<C,B,oln_value_type(I)>::ret>::ret
gaussian_common_(const convert::abstract::conversion<C,B>& c,
const abstract::image<I>& in,
const F& coef,
- ntg::float_s sigma)
+ ntg::float_s sigma,
+ const abstract::behavior<BE> &behavior)
{
typename mute<I, ntg::float_s>::ret work_img(in.size());
@@ -247,7 +248,7 @@
be linear, so when sigma is big enougth, the signal may
be parasitized by the non signal values.
*/
- work_img.border_adapt_mirror(ntg::cast::round<coord>(5 * sigma));
+ behavior.adapt_border(work_img, ntg::cast::round<coord>(5 * sigma));
gaussian_<I::dim>::doit(work_img, coef);
@@ -265,10 +266,11 @@
} // internal
- template <class C, class B, class I>
+ template <class C, class B, class I, class BE>
typename mute<I, typename convoutput<C,B,oln_value_type(I)>::ret>::ret
gaussian(const convert::abstract::conversion<C,B>& c,
- const abstract::image<I>& in, ntg::float_s sigma)
+ const abstract::image<I>& in, ntg::float_s sigma,
+ const abstract::behavior<BE> &behavior)
{
internal::recursivefilter_coef_<float>
coef(1.68f, 3.735f,
@@ -278,13 +280,14 @@
sigma,
internal::recursivefilter_coef_<float>::DericheGaussian);
- return internal::gaussian_common_(c, in, coef, sigma);
+ return internal::gaussian_common_(c, in, coef, sigma, behavior);
}
- template <class C, class B, class I>
+ template <class C, class B, class I, class BE>
typename mute<I, typename convoutput<C,B,oln_value_type(I)>::ret>::ret
gaussian_derivative(const convert::abstract::conversion<C,B>& c,
- const abstract::image<I>& in, ntg::float_s sigma)
+ const abstract::image<I>& in, ntg::float_s sigma,
+ const abstract::behavior<BE> &behavior)
{
internal::recursivefilter_coef_<float>
coef(-0.6472f, -4.531f,
@@ -295,13 +298,14 @@
internal::recursivefilter_coef_<float>
::DericheGaussianFirstDerivative);
- return internal::gaussian_common_(c, in, coef, sigma);
+ return internal::gaussian_common_(c, in, coef, sigma, behavior);
}
- template <class C, class B, class I>
+ template <class C, class B, class I, class BE>
typename mute<I, typename convoutput<C,B,oln_value_type(I)>::ret>::ret
gaussian_second_derivative(const convert::abstract::conversion<C,B>& c,
- const abstract::image<I>& in, ntg::float_s sigma)
+ const abstract::image<I>& in, ntg::float_s sigma,
+ const abstract::behavior<BE> &behavior)
{
internal::recursivefilter_coef_<float>
coef(-1.331f, 3.661f,
@@ -312,7 +316,7 @@
internal::recursivefilter_coef_<float>
::DericheGaussianSecondDerivative);
- return internal::gaussian_common_(c, in, coef, sigma);
+ return internal::gaussian_common_(c, in, coef, sigma, behavior);
}
} // fast
Index: olena/tests/convol/tests/uniform_gauss
--- olena/tests/convol/tests/uniform_gauss Fri, 30 Jan 2004 10:25:13 +0100 palma_g (oln/j/41_uniform_ga 1.1 644)
+++ olena/tests/convol/tests/uniform_gauss Tue, 10 Feb 2004 15:17:49 +0100 palma_g (oln/j/41_uniform_ga 1.1 644)
@@ -23,9 +23,10 @@
for_all(it)
img[it] = 42;
image2d<int_u8> img2 = convol::fast::gaussian(img, 5);
+ image2d<int_u8> img3 = convol::fast::gaussian(img, 5, replicate_bhv());
for_all(it)
- if (img[it] != img2[it])
+ if ((img[it] != img2[it]) || (img[it] != img3[it]))
return true;
return false;
}
Index: olena/oln/morpho/attributes.hh
--- olena/oln/morpho/attributes.hh Mon, 09 Feb 2004 18:57:03 +0100 palma_g (oln/j/45_attributes 1.2 644)
+++ olena/oln/morpho/attributes.hh Tue, 10 Feb 2004 14:59:24 +0100 palma_g (oln/j/45_attributes 1.2 644)
@@ -25,18 +25,11 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef ATTRIBUTES_HH
-# define ATTRIBUTES_HH
+#ifndef OLN_MORPHO_ATTRIBUTES_HH
+# define OLN_MORPHO_ATTRIBUTES_HH
# include <mlc/type.hh>
# include <vector>
-// some usefull macros
-
-// those macros should be moved into mlc
-// # define mlc_exact_vt_type(T, Exact) typename mlc::exact_vt<T, Exact>::ret
-// # define oln_2_exact_vt_type(self, T, Exact) typename mlc::exact_vt<self<T, Exact>, Exact>::ret
-// # define dispatch(Fun) return exact().Fun##_impl
-
// attribute dedicated macros
# define attr_lambda_type(T) typename attr_traits<T>::lambda_type
# define attr_env_type(T) typename attr_traits<T>::env_type
@@ -859,5 +852,5 @@
// FIXME: to be written...
-#endif // ndef ATTRIBUTES_HH
+#endif // !OLN_MORPHO_ATTRIBUTES
Index: olena/oln/core/abstract/behavior.hh
--- olena/oln/core/abstract/behavior.hh Tue, 10 Feb 2004 15:33:34 +0100 palma_g ()
+++ olena/oln/core/abstract/behavior.hh Tue, 10 Feb 2004 14:54:58 +0100 palma_g (oln/j/46_behavior.h 644)
@@ -0,0 +1,57 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library 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 this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library 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 OLENA_CORE_ABSTRACT_BEHAVIOR_HH
+# define OLENA_CORE_ABSTRACT_BEHAVIOR_HH
+# include <mlc/type.hh>
+# include <oln/core/abstract/image.hh>
+# include <oln/core/coord.hh>
+
+namespace oln {
+ namespace abstract {
+ // behavior hierarchy
+ //the aim of this one is to describe how an algorithm should work
+ //on borders
+ template <class Exact>
+ class behavior: public mlc_hierarchy::any<Exact>
+ {
+ public:
+ typedef behavior<Exact> self_type;
+ typedef mlc_exact_vt_type(self_type, Exact) exact_type;
+
+ template <class I>
+ void adapt_border(oln::abstract::image<I> &im, coord border_size) const
+ {
+ mlc_dispatch(adapt_border)(im, border_size);
+ };
+ protected:
+ behavior() {};
+ };
+ } // !abstract
+}
+
+#endif // !OLENA_CORE_ABSTRACT_BEHAVIOR_HH
Index: olena/oln/core/behavior.hh
--- olena/oln/core/behavior.hh Tue, 10 Feb 2004 15:33:34 +0100 palma_g ()
+++ olena/oln/core/behavior.hh Tue, 10 Feb 2004 15:12:48 +0100 palma_g (oln/j/47_behavior.h 644)
@@ -0,0 +1,108 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library 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 this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library 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 OLENA_CORE_BEHAVIOR_HH
+# define OLENA_CORE_BEHAVIOR_HH
+# include <oln/core/abstract/behavior.hh>
+# include <mlc/type.hh>
+
+namespace oln {
+ // mirror the image content into the border
+ template <class Exact = mlc::final>
+ class mirror_behavior:
+ public abstract::behavior<mlc_exact_vt_type(mirror_behavior<Exact>, Exact)>
+ {
+ public:
+ typedef mirror_behavior<Exact> self_type;
+ typedef mlc_exact_vt_type(self_type, Exact) exact_type;
+
+ template <class I>
+ void adapt_border_impl(oln::abstract::image<I> &im, coord border_size) const
+ {
+ im.border_adapt_mirror(border_size);
+ };
+ };
+
+ // set the border to a specific value
+ template <class T, class Exact = mlc::final>
+ class value_behavior:
+ public abstract::behavior<mlc_2_exact_vt_type(value_behavior, T, Exact)>
+ {
+ public:
+ typedef value_behavior<T, Exact> self_type;
+ typedef mlc_exact_vt_type(self_type, Exact) exact_type;
+ typedef T value_type;
+
+ explicit value_behavior(value_type value): value_(value)
+ {
+ };
+
+ template <class I>
+ void adapt_border_impl(abstract::image<I> &im, coord border_size) const
+ {
+ im.border_adapt_assign(border_size, ntg::cast::force<oln_value_type(I)>(value_));
+ };
+
+ protected:
+ value_type value_;
+ };
+
+ // replicate the border
+ template <class Exact = mlc::final>
+ class replicate_behavior:
+ public abstract::behavior<mlc_exact_vt_type(replicate_behavior<Exact>, Exact)>
+ {
+ public:
+ typedef replicate_behavior<Exact> self_type;
+ typedef mlc_exact_vt_type(self_type, Exact) exact_type;
+
+ template <class I>
+ void adapt_border_impl(abstract::image<I> &im, coord border_size) const
+ {
+ im.border_adapt_copy(border_size);
+ };
+ };
+
+ // tools to call ctors with type inference
+ inline mirror_behavior<> mirror_bhv()
+ {
+ return mirror_behavior<>();
+ }
+
+ template <class T>
+ inline value_behavior<T> value_bhv(const T &value)
+ {
+ return value_behavior<T>(value);
+ }
+
+ inline replicate_behavior<> replicate_bhv()
+ {
+ return replicate_behavior<>();
+ }
+} // !oln
+
+#endif // !OLN_CORE_BEHAVIOR_HH
--
Giovanni Palma
EPITA - promo 2005 - membre d'EpX - LRDE
Mob. : +33 (0)6 60 97 31 74
2
1
.
--
Geoffroy Fouquier
Geoffroy.Fouquier(a)lrde.epita.fr
1
0
et hop.
--
Geoffroy Fouquier
Geoffroy.Fouquier(a)lrde.epita.fr
1
0