Index: olena/ChangeLog
from Giovanni Palma <giovanni(a)lrde.epita.fr>
* oln/topo/tarjan/tarjan.hh: Add comments.
* oln/topo/tarjan/tarjan_with_attr.hh: Add comments. Correct the code.
* oln/topo/combinatorial-map/cmap.hh: Make cmap use the good flat_zone.
* oln/topo/tarjan/flat-zone.hh: Add new version of flat_zone.
* oln/topo/tarjan/union.hh: Correct comments.
* tests/topo/tests/cmap: Make the test use the good flat_zone.
Index: olena/tests/topo/tests/cmap
--- olena/tests/topo/tests/cmap Sun, 03 Aug 2003 21:08:04 +0200 burrus_n (oln/r/28_test-cmap. 1.8 640)
+++ olena/tests/topo/tests/cmap Fri, 02 Apr 2004 16:36:54 +0200 palma_g (oln/r/28_test-cmap. 1.8 640)
@@ -34,7 +34,7 @@
interpixel<input_t> ip(src);
- flat_zone<input_t> cc(src);
+ obsolete::flat_zone<input_t> cc(src);
cmap<input_t> cm(src, ip, cc);
Index: olena/oln/topo/tarjan/union.hh
--- olena/oln/topo/tarjan/union.hh Mon, 15 Mar 2004 17:40:54 +0100 van-vl_n (oln/r/33_union.hh 1.11 640)
+++ olena/oln/topo/tarjan/union.hh Fri, 02 Apr 2004 16:48:26 +0200 palma_g (oln/r/33_union.hh 1.11 640)
@@ -43,10 +43,7 @@
/*! Tarjan set.
**
- ** \todo FIXME: a similar class is defined in
- ** oln/morpho/attribute_union_find.hh (oln::morpho::tarjan::tarjan_set).
- ** The one in morpho is more general. I think that this class should
- ** be removed.
+ ** \todo FIXME: Obsolete since only obsolete::flat_zone use it.
*/
template< class I, class aux_data_type>
struct tarjan_set
Index: olena/oln/topo/tarjan/flat-zone.hh
--- olena/oln/topo/tarjan/flat-zone.hh Mon, 15 Mar 2004 15:32:27 +0100 van-vl_n (oln/r/35_flat-zone. 1.12 640)
+++ olena/oln/topo/tarjan/flat-zone.hh Fri, 02 Apr 2004 16:47:01 +0200 palma_g (oln/r/35_flat-zone. 1.12 640)
@@ -1,12 +1,13 @@
-// Copyright (C) 2001, 2002, 2003, 2004 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
// 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
+// 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.
//
@@ -28,9 +29,10 @@
#ifndef OLENA_TOPO_TARJAN_FLAT_ZONE_HH
# define OLENA_TOPO_TARJAN_FLAT_ZONE_HH
-# include <oln/basics2d.hh>
+# include <oln/basics.hh>
+# include <oln/topo/tarjan/tarjan_with_attr.hh>
# include <oln/topo/tarjan/union.hh>
-
+# include <oln/morpho/attributes.hh>
# include <map>
namespace oln {
@@ -41,7 +43,10 @@
/*! Create an image of label of the flat zones.
**
- ** \todo FIXME: many assertions are missing.
+ ** \param T Type of he input image.
+ ** \param DestType Data type of the output image (label type).
+ ** \param A Attribute you want to compute.
+ ** \param Exact Exact type of the class.
**
** \code
** #include <oln/basics2d.hh>
@@ -53,6 +58,153 @@
** typedef oln::image2d<ntg::int_u8> img_type;
** img_type in = oln::load(IMG_IN "test-cmap.pgm");
** oln::topo::tarjan::flat_zone<img_type> z(in);
+ ** save(oln::convert::stretch_balance<ntg::int_u8>(z.get_compute(oln::neighb_c4()), 0, 255),
+ ** IMG_OUT "oln_topo_flat_zone.pgm");
+ ** }
+ ** \endcode
+ ** \image html test-cmap_pgm.png "input image"
+ ** \image latex test-cmap_pgm.png "input image"
+ ** =>
+ ** \image html oln_topo_flat_zone.png "output image"
+ ** \image latex oln_topo_flat_zone.png "output image"
+ */
+ template<class T,
+ class DestType = unsigned,
+ class A = oln::morpho::attr::card_type<>,
+ class Exact = mlc::final>
+ struct flat_zone:
+ public abstract::tarjan_with_attr<typename mlc::exact_vt<flat_zone<T, DestType, A, Exact>,
+ Exact>::ret>
+ {
+
+ typedef oln_point_type(T) point_type; ///< Type of input image.
+ typedef oln_value_type(T) data_type; ///< Data type of the input image.
+ typedef oln_concrete_type(T) image_type; ///< Concrete type of the input image.
+
+ typedef DestType comp_type; ///< Type of components.
+
+ typedef flat_zone<T, DestType, A, Exact> self_type; ///< Self type of the class.
+ typedef mlc_exact_vt_type(self_type, Exact) exact_type; ///< Exact type of the class.
+ typedef abstract::tarjan_with_attr<exact_type> super_type; ///< Type of parent class.
+
+ friend class super_type;
+ friend class super_type::super_type;
+ /*!
+ ** \brief Constructor.
+ **
+ ** \arg ima Input image.
+ ** \arg env Environment to use to compute the attributes.
+ */
+ flat_zone(const image_type &ima,
+ const attr_env_type(A) &env = attr_env_type(A)()): super_type(ima, env)
+ {
+ }
+
+ std::vector<point_type>
+ get_processing_order_impl()
+ {
+ std::vector<point_type> res;
+ oln_iter_type(image_type) it(input_);
+
+ res.reserve(input_.npoints());
+ for_all(it)
+ res.push_back(it);
+ return res;
+ }
+
+ protected:
+
+ /*!
+ ** \brief Implementation of mark_set().
+ **
+ ** \arg x Root of the new component.
+ **
+ ** \warning Do not call this method, use mark_set() instead.
+ */
+ void
+ mark_set_impl(const point_type &x)
+ {
+ if (parent_.size() == parent_.capacity())
+ {
+ capacity = parent_.capacity() + capacity_chunk;
+ parent_.reserve(capacity);
+ comp_value_.reserve(capacity);
+ }
+ to_comp_[x] = ncomps_ + 1;
+ data_.push_back(A(input_, x, env_));
+ parent_.push_back(ncomps_ + 1);
+ comp_value_.push_back(ncomps_ + 1);
+ }
+
+ /*!
+ ** \brief Implementation of uni().
+ **
+ ** \arg n A point of the first component.
+ ** \arg p A point of the second component.
+ **
+ ** \warning Do not call this method, use uni() instead.
+ */
+ void
+ uni_impl(const point_type& n, const point_type& p)
+ {
+ comp_type r = find_root(to_comp_[n]);
+ precondition(to_comp_[n] <= ncomps_);
+ precondition(to_comp_[p] <= (ncomps_ + 1));
+ if (r != to_comp_[p])
+ if (input_[n] == input_[p])
+ {
+ if (to_comp_[p] == (ncomps_ + 1)) // first merge of p component
+ {
+ precondition(r < comp_value_.capacity());
+ data_[r] += data_[to_comp_[p]];
+ precondition(r <= ncomps_);
+ to_comp_[p] = r;
+ }
+ else
+ {
+ precondition(r < parent_.capacity());
+ data_[parent_[to_comp_[p]]] += data_[parent_[r]];
+ parent_[r] = parent_[to_comp_[p]];
+
+ }
+ }
+ }
+ };
+
+ /*!
+ ** \brief Traits specialization for flat_zone.
+ **
+ ** \param T Type of he input image.
+ ** \param DestType Data type of the output image (label type).
+ ** \param A Attribute you want to compute.
+ ** \param Exact Exact type of the flat_zone class.
+ */
+ template <typename T, typename DestType, typename A, typename Exact>
+ struct tarjan_traits<flat_zone<T, DestType, A, Exact> >
+ {
+ typedef T input_type; ///< Type of the input image.
+ typedef typename mute<T, DestType>::ret output_type; ///< Type of the output image.
+ typedef A attr_type; ///< Type of attribute to use.
+ };
+
+ /*!
+ ** \brief Namespace containing obsolete implementation of flat zone.
+ */
+ namespace obsolete {
+ /*! Create an image of label of the flat zones.
+ **
+ ** \todo FIXME: many assertions are missing.
+ **
+ ** \code
+ ** #include <oln/basics2d.hh>
+ ** #include <oln/topo/tarjan/flat-zone.hh>
+ ** #include <oln/convert/stretch.hh>
+ **
+ ** int main()
+ ** {
+ ** typedef oln::image2d<ntg::int_u8> img_type;
+ ** img_type in = oln::load(IMG_IN "test-cmap.pgm");
+ ** oln::topo::tarjan::obsolete::flat_zone<img_type> z(in);
** save(oln::convert::stretch_balance<ntg::int_u8>(z.label, 0, 255),
** IMG_OUT "oln_topo_flat_zone.pgm");
** }
@@ -230,6 +382,8 @@
};
+ } // end of namespace obsolete
+
} // end of namespace tarjan
} // end of namespace topo
Index: olena/oln/topo/combinatorial-map/cmap.hh
--- olena/oln/topo/combinatorial-map/cmap.hh Mon, 15 Mar 2004 15:32:27 +0100 van-vl_n (oln/r/36_cmap.hh 1.13 640)
+++ olena/oln/topo/combinatorial-map/cmap.hh Fri, 02 Apr 2004 16:46:39 +0200 palma_g (oln/r/36_cmap.hh 1.13 640)
@@ -44,6 +44,7 @@
** FIXME: The documentation is not good enough.\n
** FIXME: Real test are missing.
** FIXME: Some part of this file are inside "#if 0" comments.
+** FIXME: This file force to keep an obsolete version of flat-zone.
*/
namespace oln {
@@ -72,7 +73,7 @@
public:
cmap(const I& input,
const inter_pixel::interpixel<I>& ip,
- tarjan::flat_zone<I>& cc) :
+ tarjan::obsolete::flat_zone<I>& cc) :
ndarts_(0),
zeta_(input.nrows() + 1, input.ncols() + 1),
cc_(cc),
@@ -358,7 +359,7 @@
private:
unsigned ndarts_;
zeta_type zeta_;
- tarjan::flat_zone<I> & cc_;
+ tarjan::obsolete::flat_zone<I> &cc_;
internal::level<unsigned> level_;
internal::beta<unsigned> beta_;
Index: olena/oln/topo/tarjan/tarjan_with_attr.hh
--- olena/oln/topo/tarjan/tarjan_with_attr.hh Wed, 31 Mar 2004 19:11:41 +0200 palma_g (oln/m/46_tarjan_wit 1.1 644)
+++ olena/oln/topo/tarjan/tarjan_with_attr.hh Fri, 02 Apr 2004 15:57:02 +0200 palma_g (oln/m/46_tarjan_wit 1.1 644)
@@ -1,12 +1,12 @@
-// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory
+// 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
+// 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.
//
@@ -42,22 +42,57 @@
namespace topo {
/// \brief Implementation of tarjan set.
namespace tarjan {
+
/// Abstract classes for tarjan based algorithms.
namespace abstract {
+ /*!
+ ** \brief Abstract class to perform a tarjan algorithm on an
+ ** image with attribute computing .
+ **
+ ** \param Exact Exact type of the class.
+ */
template<class Exact>
struct tarjan_with_attr: public tarjan<mlc_exact_vt_type(tarjan_with_attr<Exact>, Exact) >
{
- typedef oln_tarjan_input_type(Exact) input_type;
- typedef oln_point_type(input_type) point_type;
- typedef oln_value_type(input_type) data_type;
-
- typedef oln_concrete_type(input_type) image_type;
- typedef oln_tarjan_output_type(Exact) image_out_type;
- typedef oln_tarjan_attr_type(Exact) attr_type;
- typedef attr_env_type(attr_type) env_type;
- typedef oln_value_type(image_out_type) comp_type;
+ typedef oln_tarjan_input_type(Exact) input_type; ///< Type of input image.
+ typedef oln_point_type(input_type) point_type; ///< Point type of image to process.
+ typedef oln_value_type(input_type) data_type; ///< Data type of the input image.
+
+ typedef oln_concrete_type(input_type) image_type; ///< Concrete type of the input image.
+ typedef oln_tarjan_output_type(Exact) image_out_type; ///< Type of output image.
+ typedef oln_tarjan_attr_type(Exact) attr_type; ///< Type of attribute to use.
+ typedef attr_env_type(attr_type) env_type; ///< Environment associated to attribute type.
+ typedef oln_value_type(image_out_type) comp_type; ///< Type of components.
+
+ typedef mlc_exact_vt_type(tarjan_with_attr<Exact>,
+ Exact) exact_type; ///< Exact type of the class.
+ typedef tarjan<exact_type> super_type; ///< Type of parent class.
+
+ // Make parent class able to call implementations.
+ friend class super_type;
+
+ /*!
+ ** \brief Return the attribute value associated to a
+ ** component \a i.
+ */
+ const attr_type &get_attr(const comp_type &i) const
+ {
+ return data_[find_root(i)];
+ }
+
+ protected:
+ /*! \brief Constructor.
+ **
+ ** Initialization of data structures.
+ **
+ ** \arg ima Image to process.
+ ** \arg env Environment to use.
+ **
+ ** \warning This constructor is protected, because this
+ ** class is abstract.
+ */
tarjan_with_attr(const image_type &ima,
const env_type &env):
capacity_chunk((ima.npoints() < 100) ? ima.npoints() : (ima.npoints() / 100)),
@@ -73,30 +108,26 @@
data_.reserve(capacity);
}
- // abstract methods
- std::vector<point_type> get_processing_order()
- {
- mlc_dispatch(get_processing_order)();
- }
-
- void
- mark_set(const point_type &x)
- {
- mlc_dispatch(mark_set)(x);
- }
-
- void
- uni(const point_type& n, const point_type& p)
- {
- mlc_dispatch(uni)(n, p);
- }
-
- // tells if a point has been proceded
- bool is_proc(const point_type &p) const
+ /*!
+ ** \brief Implementation of is_proc().
+ **
+ ** \arg p Point you want to check.
+ **
+ ** \warning Do not call this method, use is_proc() instead.
+ */
+ bool is_proc_impl(const point_type &p) const
{
return to_comp_[p] != ntg_sup_val(comp_type);
};
+ /*!
+ ** \brief Implementation of find_root().
+ **
+ ** \arg x The component you want to find the root.
+ **
+ ** \warning Do not call this method, use find_root()
+ ** instead.
+ */
comp_type
find_root(const comp_type& x) const
{
@@ -105,11 +136,17 @@
return x;
}
- // bool closing = true -> a closing is performed,
- // an opening otherwise.
+ /*!
+ ** \brief Implementation of get_compute().
+ **
+ ** \arg Ng Neighborhood to use.
+ **
+ ** \warning Do not call this method, use get_compute()
+ ** instead.
+ */
template<class N>
image_out_type
- get_compute(const oln::abstract::neighborhood<N> &Ng)
+ get_compute_impl(const oln::abstract::neighborhood<N> &Ng)
{
std::vector<point_type> I(get_processing_order());
@@ -167,20 +204,16 @@
return output;
}
- // access to attributes
- // i index of component
- const attr_type &get_attr(const comp_type &i) const
- {
- return data_[find_root(i)];
- }
-
- comp_type ncomps() const
+ /*!
+ ** \brief Implementation of ncomps_impl().
+ **
+ ** \warning Do not call this method, use ncomps() instead.
+ */
+ comp_type ncomps_impl() const
{
return ncomps_;
}
- protected:
-
unsigned capacity_chunk;
unsigned capacity;
const image_type &input_;
@@ -193,99 +226,6 @@
};
} // !abstract
-
-
- template<class T, class DestType, class A, class Exact = mlc::final>
- struct cc:
- public abstract::tarjan_with_attr<typename mlc::exact_vt<cc<T, DestType, A, Exact>,
- Exact>::ret>
- {
-
- typedef oln_point_type(T) point_type;
- typedef oln_value_type(T) data_type;
- // typedef abstract::image<T> image_type;
- typedef oln_concrete_type(T) image_type;
-
- typedef unsigned comp_type;
-
- typedef cc<T, DestType, A, Exact> self_type; /*< Self type of the class.*/
- typedef mlc_exact_vt_type(self_type, Exact) exact_type;
- typedef abstract::tarjan_with_attr<exact_type> super_type;
-
- cc(const image_type &ima,
- const attr_env_type(A) &env): super_type(ima, env)
- {
- }
-
- std::vector<point_type> get_processing_order_impl()
- {
- std::vector<point_type> res;
- oln_iter_type(image_type) it(input_);
-
- res.reserve(input_.npoints());
- for_all(it)
- res.push_back(it);
- return res;
- }
-
- void
- mark_set_impl(const point_type &x)
- {
- if (parent_.size() == parent_.capacity())
- {
- capacity = parent_.capacity() + capacity_chunk;
- parent_.reserve(capacity);
- comp_value_.reserve(capacity);
- }
- to_comp_[x] = ncomps_ + 1;
- data_.push_back(A(input_, x, env_));
- parent_.push_back(ncomps_ + 1);
- //comp_value_.push_back(input_[x]);
- comp_value_.push_back(ncomps_ + 1);
- }
-
- void
- uni_impl(const point_type& n, const point_type& p)
- {
- comp_type r = find_root(to_comp_[n]);
- precondition(to_comp_[n] <= ncomps_);
- precondition(to_comp_[p] <= (ncomps_ + 1));
- if (r != to_comp_[p])
- if (input_[n] == input_[p])
- {
- if (to_comp_[p] == (ncomps_ + 1)) // first merge of p component
- {
- precondition(r < comp_value_.capacity());
- //comp_value_[r] = input_[p];
- // comp_value_[to_comp_[p]] = comp_value_[r];
- data_[r] += data_[to_comp_[p]];
- precondition(r <= ncomps_);
- to_comp_[p] = r;
- }
- else
- {
- precondition(r < parent_.capacity());
- data_[parent_[to_comp_[p]]] += data_[parent_[r]];
- // comp_value_[parent_[to_comp_[p]]] = ntg::min(comp_value_[parent_[r]],
- // comp_value_[parent_[to_comp_[p]]]);
- parent_[r] = parent_[to_comp_[p]];
-
- }
- }
- // precondition(comp_value_[parent_[r]] <= 255);
- }
- };
-
- // traits specialization
- template <typename T, typename DestType, typename A, typename Exact>
- struct tarjan_traits<cc<T, DestType, A, Exact> >
- {
- typedef T input_type;
- typedef typename mute<T, DestType>::ret output_type;
- typedef A attr_type;
- };
-
-
} // end of namespace tarjan
} // end of namespace topo
Index: olena/oln/topo/tarjan/tarjan.hh
--- olena/oln/topo/tarjan/tarjan.hh Wed, 31 Mar 2004 19:11:41 +0200 palma_g (oln/m/47_tarjan.hh 1.1 644)
+++ olena/oln/topo/tarjan/tarjan.hh Thu, 01 Apr 2004 13:49:48 +0200 palma_g (oln/m/47_tarjan.hh 1.1 644)
@@ -1,12 +1,12 @@
-// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory
+// 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
+// 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.
//
@@ -45,6 +45,7 @@
namespace topo {
/// \brief Implementation of tarjan set.
namespace tarjan {
+
/// Forward declaration for tarjan traits.
template <typename Exact>
struct tarjan_traits;
@@ -61,10 +62,10 @@
template <typename Exact>
struct tarjan: public mlc_hierarchy::any<Exact>
{
- typedef oln_tarjan_input_type(Exact) input_type;
- typedef oln_tarjan_output_type(Exact) image_out_type;
- typedef oln_value_type(image_out_type) comp_type;
- typedef oln_point_type(input_type) point_type;
+ typedef oln_tarjan_input_type(Exact) input_type; ///< Type of input image.
+ typedef oln_tarjan_output_type(Exact) image_out_type; ///< Type of output image.
+ typedef oln_value_type(image_out_type) comp_type; ///< Type of components.
+ typedef oln_point_type(input_type) point_type; ///< Point type of image to process.
/*!
** \brief Run the algorithm.
--
Giovanni Palma
EPITA - promo 2005 - membre d'EpX - LRDE
Mob. : +33 (0)6 60 97 31 74
Index: olena/ChangeLog
from Giovanni Palma <giovanni(a)lrde.epita.fr>
* oln/convert/stretch.hh: Add header inclusion.
* oln/topo/tarjan/tarjan.hh: Add file.
* oln/topo/tarjan/tarjan_with_attr.hh: Add file.
* oln/morpho/attributes.hh: Add new attribute.
Index: olena/oln/convert/stretch.hh
--- olena/oln/convert/stretch.hh Sun, 14 Mar 2004 19:03:34 +0100 van-vl_n (oln/f/51_stretch.hh 1.17 600)
+++ olena/oln/convert/stretch.hh Tue, 30 Mar 2004 12:00:36 +0200 palma_g (oln/f/51_stretch.hh 1.17 640)
@@ -30,6 +30,8 @@
# include <mlc/type.hh>
+# include <oln/basics.hh>
+
# include <ntg/basics.hh>
# include <oln/convert/abstract/conversion.hh>
Index: olena/oln/morpho/attributes.hh
--- olena/oln/morpho/attributes.hh Sat, 27 Mar 2004 15:56:32 +0100 van-vl_n (oln/j/45_attributes 1.11 600)
+++ olena/oln/morpho/attributes.hh Tue, 30 Mar 2004 13:55:31 +0200 palma_g (oln/j/45_attributes 1.11 644)
@@ -138,6 +138,17 @@
};
/*!
+ ** \brief "<" operator
+ **
+ ** This is a static dispatcher for the "<" operator.
+ ** This method is abstract.
+ */
+ bool operator<(const exact_type &x) const
+ {
+ mlc_dispatch(less2)(x);
+ };
+
+ /*!
** \brief != operator
**
** This is a static dispatcher for the != operator.
@@ -149,6 +160,16 @@
};
/*!
+ ** \brief conversion to lambda type.
+ **
+ ** \warning Virtual method.
+ */
+ const lambda_type &toLambda() const
+ {
+ mlc_dispatch(toLambda)();
+ };
+
+ /*!
** \brief >= operator implementation.
**
** This is an implementation of the >= operator. Override this
@@ -160,6 +181,20 @@
return !(*this < lambda);
};
+ /*!
+ ** \brief "<" operator implementation.
+ **
+ ** This is an implementation of the < operator. Override this
+ ** method to provide a new implementation of this operator.
+ ** \warning This method SHOULDN'T be called.
+ */
+ bool less2_impl(const exact_type &x) const
+ {
+ return *this < x.toLambda();
+ };
+
+
+
protected:
attribute() {};
@@ -249,14 +284,70 @@
return lambda != value_;
};
+ /*!
+ ** \brief conversion to lambda type implementation.
+ **
+ ** This is an implementation of the toLambda() method.
+ ** Override this method to provide a new implementation.
+ ** \warning This method SHOULDN'T be called .
+ */
+ const lambda_type &toLambda_impl() const
+ {
+ return value_;
+ };
+
protected:
value_type value_; /*!< Value used inside the class. */
};
+ /*-------------------------------*
+ | card with info on other image |
+ *------------------------------*/
+ template <class I, class T = unsigned, class Exact = mlc::final>
+ class card_full_type: public card_type<T,
+ typename mlc::exact_vt<card_full_type<I,
+ T,
+ Exact>,
+ Exact>::ret>
+ {
+ public:
+ typedef card_full_type<I, T, Exact> self_type; /*!< Self type of the class. */
+ attr_type_decl(self_type);
+ typedef card_type<T, exact_type> super_type; ///< Parent class type.
+
+ /*!
+ ** \brief Basic Ctor.
+ **
+ ** \warning After this call, the object is only instantiated
+ ** (not initialized).
+ */
+ card_full_type(): super_type()
+ {
+ };
+
+ /*!
+ ** \brief Ctor from a lambda_type value.
+ */
+ card_full_type(const lambda_type &lambda): super_type(lambda)
+ {
+ };
- /*-----------*
+ /*!
+ ** \brief Ctor from a point and an image.
+ **
+ ** Every parameters are useless.
+ */
+ template <class I2>
+ card_full_type(const abstract::image<I2> &im,
+ const oln_point_type(I2) &p,
+ const env_type &env): super_type(im, p, env)
+ {
+ };
+ };
+
+ /*--------------*
| integral |
- *-----------*/
+ *------------*/
/*!
** \brief Integral attribute.
@@ -1701,6 +1792,17 @@
};
/*!
+ ** \brief Trait specialization for card_full attribute.
+ */
+ template <class I, class T, class Exact>
+ struct attr_traits<card_full_type<I, T, Exact> >
+ {
+ typedef T value_type; ///< Type of data.
+ typedef value_type lambda_type; ///< Type of lambda.
+ typedef env::OtherImageEnv<I> env_type; ///< Type of environment.
+ };
+
+ /*!
** \brief Trait specialization for the maxvalue attribute.
*/
template <class T, class Exact>
Index: olena/oln/topo/tarjan/tarjan_with_attr.hh
--- olena/oln/topo/tarjan/tarjan_with_attr.hh Wed, 31 Mar 2004 19:11:06 +0200 palma_g ()
+++ olena/oln/topo/tarjan/tarjan_with_attr.hh Wed, 31 Mar 2004 18:50:19 +0200 palma_g (oln/m/46_tarjan_wit 644)
@@ -0,0 +1,295 @@
+// 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
+// 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_TOPO_TARJAN_TARJAN_WITH_ATTR_HH
+# define OLENA_TOPO_TARJAN_TARJAN_WITH_ATTR_HH
+
+# include <oln/topo/tarjan/tarjan.hh>
+# include <oln/morpho/attributes.hh>
+# include <ntg/basics.hh>
+# include <oln/level/fill.hh>
+# include <oln/utils/histogram.hh>
+
+# include <vector>
+# include <map>
+
+namespace oln {
+
+ namespace topo {
+ /// \brief Implementation of tarjan set.
+ namespace tarjan {
+ /// Abstract classes for tarjan based algorithms.
+ namespace abstract {
+
+ template<class Exact>
+ struct tarjan_with_attr: public tarjan<mlc_exact_vt_type(tarjan_with_attr<Exact>, Exact) >
+ {
+ typedef oln_tarjan_input_type(Exact) input_type;
+ typedef oln_point_type(input_type) point_type;
+ typedef oln_value_type(input_type) data_type;
+
+ typedef oln_concrete_type(input_type) image_type;
+ typedef oln_tarjan_output_type(Exact) image_out_type;
+ typedef oln_tarjan_attr_type(Exact) attr_type;
+ typedef attr_env_type(attr_type) env_type;
+ typedef oln_value_type(image_out_type) comp_type;
+
+ tarjan_with_attr(const image_type &ima,
+ const env_type &env):
+ capacity_chunk((ima.npoints() < 100) ? ima.npoints() : (ima.npoints() / 100)),
+ capacity(capacity_chunk),
+ input_(ima),
+ parent_(),
+ to_comp_(ima.size()),
+ comp_value_(),
+ env_(env)
+ {
+ parent_.reserve(capacity);
+ comp_value_.reserve(capacity);
+ data_.reserve(capacity);
+ }
+
+ // abstract methods
+ std::vector<point_type> get_processing_order()
+ {
+ mlc_dispatch(get_processing_order)();
+ }
+
+ void
+ mark_set(const point_type &x)
+ {
+ mlc_dispatch(mark_set)(x);
+ }
+
+ void
+ uni(const point_type& n, const point_type& p)
+ {
+ mlc_dispatch(uni)(n, p);
+ }
+
+ // tells if a point has been proceded
+ bool is_proc(const point_type &p) const
+ {
+ return to_comp_[p] != ntg_sup_val(comp_type);
+ };
+
+ comp_type
+ find_root(const comp_type& x) const
+ {
+ if (parent_[x] != x)
+ return parent_[x] = find_root(parent_[x]);
+ return x;
+ }
+
+ // bool closing = true -> a closing is performed,
+ // an opening otherwise.
+ template<class N>
+ image_out_type
+ get_compute(const oln::abstract::neighborhood<N> &Ng)
+ {
+ std::vector<point_type> I(get_processing_order());
+
+ level::fill(to_comp_, ntg_sup_val(comp_type));
+ to_comp_.border_adapt_assign(Ng.delta(), ntg_sup_val(comp_type));
+ ncomps_ = 0;
+ parent_.push_back(0);
+ comp_value_.push_back(0);
+ data_.push_back(attr_type());
+
+ // We are ready to perform stuff
+ for (unsigned int p = 0; p < I.size(); ++p)
+ {
+ point_type p_p = I[p];
+ mark_set(p_p);
+
+ oln_neighb_type(N) Q_prime(Ng, p_p);
+ for_all (Q_prime)
+ if (is_proc(Q_prime))
+ uni(Q_prime.cur(), p_p);
+ if (to_comp_[p_p] == (ncomps_ + 1)) // new component
+ ++ncomps_;
+ else
+ {
+ comp_value_.pop_back();
+ parent_.pop_back();
+ data_.pop_back();
+ }
+ }
+
+ // Resolving phase
+ std::map<comp_type, comp_type> cmps;
+ comp_type nc = 0;
+ ncomps_ = 0;
+ // unsigned i = 0;
+ for (int p = I.size() - 1; p >= 0; --p)
+ {
+ point_type p_p = I[p];
+ if (cmps.find(comp_value_[find_root(to_comp_[p_p])]) == cmps.end())
+ {
+ ++ncomps_;
+ // ++i;
+ // std::cout << "new component\n";
+ cmps[comp_value_[find_root(to_comp_[p_p])]] = nc;
+ comp_value_[find_root(to_comp_[p_p])] = nc++;
+ }
+ }
+ // std::cout << i << " components\n";
+ image_out_type output(input_.size());
+ for (int p = I.size() - 1; p >= 0; --p)
+ {
+ point_type p_p = I[p];
+ output[p_p] = comp_value_[find_root(to_comp_[p_p])];
+ }
+ return output;
+ }
+
+ // access to attributes
+ // i index of component
+ const attr_type &get_attr(const comp_type &i) const
+ {
+ return data_[find_root(i)];
+ }
+
+ comp_type ncomps() const
+ {
+ return ncomps_;
+ }
+
+ protected:
+
+ unsigned capacity_chunk;
+ unsigned capacity;
+ const image_type &input_;
+ mutable std::vector<comp_type> parent_;
+ typename oln::mute<input_type, comp_type>::ret to_comp_;// comp number from a point
+ comp_type ncomps_;
+ std::vector<oln_value_type(image_out_type)> comp_value_;
+ std::vector<attr_type> data_;
+ env_type env_;
+ };
+ } // !abstract
+
+
+
+ template<class T, class DestType, class A, class Exact = mlc::final>
+ struct cc:
+ public abstract::tarjan_with_attr<typename mlc::exact_vt<cc<T, DestType, A, Exact>,
+ Exact>::ret>
+ {
+
+ typedef oln_point_type(T) point_type;
+ typedef oln_value_type(T) data_type;
+ // typedef abstract::image<T> image_type;
+ typedef oln_concrete_type(T) image_type;
+
+ typedef unsigned comp_type;
+
+ typedef cc<T, DestType, A, Exact> self_type; /*< Self type of the class.*/
+ typedef mlc_exact_vt_type(self_type, Exact) exact_type;
+ typedef abstract::tarjan_with_attr<exact_type> super_type;
+
+ cc(const image_type &ima,
+ const attr_env_type(A) &env): super_type(ima, env)
+ {
+ }
+
+ std::vector<point_type> get_processing_order_impl()
+ {
+ std::vector<point_type> res;
+ oln_iter_type(image_type) it(input_);
+
+ res.reserve(input_.npoints());
+ for_all(it)
+ res.push_back(it);
+ return res;
+ }
+
+ void
+ mark_set_impl(const point_type &x)
+ {
+ if (parent_.size() == parent_.capacity())
+ {
+ capacity = parent_.capacity() + capacity_chunk;
+ parent_.reserve(capacity);
+ comp_value_.reserve(capacity);
+ }
+ to_comp_[x] = ncomps_ + 1;
+ data_.push_back(A(input_, x, env_));
+ parent_.push_back(ncomps_ + 1);
+ //comp_value_.push_back(input_[x]);
+ comp_value_.push_back(ncomps_ + 1);
+ }
+
+ void
+ uni_impl(const point_type& n, const point_type& p)
+ {
+ comp_type r = find_root(to_comp_[n]);
+ precondition(to_comp_[n] <= ncomps_);
+ precondition(to_comp_[p] <= (ncomps_ + 1));
+ if (r != to_comp_[p])
+ if (input_[n] == input_[p])
+ {
+ if (to_comp_[p] == (ncomps_ + 1)) // first merge of p component
+ {
+ precondition(r < comp_value_.capacity());
+ //comp_value_[r] = input_[p];
+ // comp_value_[to_comp_[p]] = comp_value_[r];
+ data_[r] += data_[to_comp_[p]];
+ precondition(r <= ncomps_);
+ to_comp_[p] = r;
+ }
+ else
+ {
+ precondition(r < parent_.capacity());
+ data_[parent_[to_comp_[p]]] += data_[parent_[r]];
+ // comp_value_[parent_[to_comp_[p]]] = ntg::min(comp_value_[parent_[r]],
+ // comp_value_[parent_[to_comp_[p]]]);
+ parent_[r] = parent_[to_comp_[p]];
+
+ }
+ }
+ // precondition(comp_value_[parent_[r]] <= 255);
+ }
+ };
+
+ // traits specialization
+ template <typename T, typename DestType, typename A, typename Exact>
+ struct tarjan_traits<cc<T, DestType, A, Exact> >
+ {
+ typedef T input_type;
+ typedef typename mute<T, DestType>::ret output_type;
+ typedef A attr_type;
+ };
+
+
+ } // end of namespace tarjan
+
+ } // end of namespace topo
+
+} // end of namespace oln
+
+#endif // ! OLENA_TOPO_TARJAN_TARJAN_WITH_ATTR_HH
Index: olena/oln/topo/tarjan/tarjan.hh
--- olena/oln/topo/tarjan/tarjan.hh Wed, 31 Mar 2004 19:11:06 +0200 palma_g ()
+++ olena/oln/topo/tarjan/tarjan.hh Wed, 31 Mar 2004 18:42:56 +0200 palma_g (oln/m/47_tarjan.hh 644)
@@ -0,0 +1,153 @@
+// 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
+// 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_TOPO_TARJAN_TARJAN_HH
+# define OLENA_TOPO_TARJAN_TARJAN_HH
+# include <oln/basics.hh>
+
+// Macros for extract information on tarjan algorithms.
+# define oln_tarjan_input_type(T) typename oln::topo::tarjan::tarjan_traits<T>::input_type
+# define oln_tarjan_output_type(T) typename oln::topo::tarjan::tarjan_traits<T>::output_type
+# define oln_tarjan_attr_type(T) typename oln::topo::tarjan::tarjan_traits<T>::attr_type
+
+
+// # define oln_tarjan_input_type(T) typename oln::topo::tarjan::tarjan_traits<mlc_exact_type(T)>::input_type
+// # define oln_tarjan_output_type(T) typename oln::topo::tarjan::tarjan_traits<mlc_exact_type(T)>::output_type
+// # define oln_tarjan_attr_type(T) typename oln::topo::tarjan::tarjan_traits<mlc_exact_type(T)>::attr_type
+
+
+namespace oln {
+
+ namespace topo {
+ /// \brief Implementation of tarjan set.
+ namespace tarjan {
+ /// Forward declaration for tarjan traits.
+ template <typename Exact>
+ struct tarjan_traits;
+
+ /// Abstract classes for tarjan based algorithms.
+ namespace abstract {
+ /*!
+ ** \brief Top of tarjan hierarchy.
+ **
+ ** \param I Type of image to process.
+ ** \param D Type of data of the wanted image.
+ ** \param Exact Exact type of the class.
+ */
+ template <typename Exact>
+ struct tarjan: public mlc_hierarchy::any<Exact>
+ {
+ typedef oln_tarjan_input_type(Exact) input_type;
+ typedef oln_tarjan_output_type(Exact) image_out_type;
+ typedef oln_value_type(image_out_type) comp_type;
+ typedef oln_point_type(input_type) point_type;
+
+ /*!
+ ** \brief Run the algorithm.
+ **
+ **
+ ** \warning Implement get_compute_impl to be able to use
+ ** this method.
+ */
+ template<class N>
+ image_out_type
+ get_compute(const oln::abstract::neighborhood<N> &Ng)
+ {
+ mlc_dispatch(get_compute)(Ng);
+ }
+
+ /*!
+ ** \brief Give the number of component found.
+ **
+ ** \warning Implement ncomps_impl to be able to use
+ ** this method.
+ */
+ comp_type ncomps() const
+ {
+ mlc_dispatch(ncomps)();
+ }
+
+ protected:
+ /*!
+ ** \brief Abstract method to get the processing order.
+ **
+ ** \warning Implement get_processing_order_impl to be able
+ ** to use this method.
+ */
+ std::vector<point_type>
+ get_processing_order()
+ {
+ mlc_dispatch(get_processing_order)();
+ }
+
+ /*!
+ ** \brief Mark a point as a new component.
+ **
+ ** \warning Implement mark_set_impl to be able to use this
+ ** method.
+ */
+ void
+ mark_set(const point_type &x)
+ {
+ mlc_dispatch(mark_set)(x);
+ }
+
+ /*!
+ ** \brief Perform an union between two components.
+ **
+ ** \warning Implement uni_impl to be able to use this
+ ** method.
+ */
+ void
+ uni(const point_type& n, const point_type& p)
+ {
+ mlc_dispatch(uni)(n, p);
+ }
+
+ /*!
+ ** \brief tell if a point has already been processed.
+ **
+ **
+ ** \warning Implement is_proc_impl to be able to use this
+ ** method.
+ */
+ bool is_proc(const point_type &p) const
+ {
+ mlc_dispatch(is_proc)(p);
+ };
+
+ /*!
+ ** \brief Make the class abstract.
+ */
+ tarjan() {}
+ };
+ } // end of namespace abstract
+ } // end of namespace tarjan
+ } // end of namespace topo
+} // end of namespace oln
+
+#endif // ! OLENA_TOPO_TARJAN_TARJAN_HH
--
Giovanni Palma
EPITA - promo 2005 - membre d'EpX - LRDE
Mob. : +33 (0)6 60 97 31 74
Index: integre/ChangeLog
from Niels Van Vliet <niels(a)lrde.epita.fr>
* integre/ntg/core/macros.hh: Add macros ntg_if_vectorial_nb_comp and
ntg_compare_nb_comp.
* integre/tests/types/tests/ntg_compare_nb_comp: Add file.
Index: olena/ChangeLog
from Niels Van Vliet <niels(a)lrde.epita.fr>
* olena/oln/math/macros.hh: Add dot_product.
* olena/oln/utils/se_stat.hh: Add file. Mean and variance using a
structuring element.
* olena/oln/utils/se_stat.hxx: Add file.
* olena/oln/convol/nagao.hh: Add file. Nagao filter.
* olena/oln/convol/nagao.hxx: Add file.
* olena/tests/convol/tests/nagao : Add file.
Index: olena/oln/math/macros.hh
--- olena/oln/math/macros.hh Mon, 15 Mar 2004 17:40:54 +0100 van-vl_n
(oln/b/21_macros.hh 1.6.1.14 600)
+++ olena/oln/math/macros.hh Fri, 26 Mar 2004 19:15:36 +0100 van-vl_n
(oln/b/21_macros.hh 1.6.1.14 600)
@@ -85,6 +85,68 @@
return f(val);
}
+ /// Internal purpose only.
+ namespace internal {
+ /// Dot product for non-vectorial types.
+ template<typename DestValue, typename I, typename J>
+ struct f_dot_product_nv
+ {
+ typedef typename ntg_is_a(I, ntg::non_vectorial)::ensure_type t;
+
+ static DestValue
+ product(const I &i, const J &j)
+ {
+ return i * j;
+ }
+ };
+
+ /// Dot product for vectorial types.
+ template<typename DestValue, typename I, typename J>
+ struct f_dot_product_v
+ {
+ typedef typename ntg_is_a(I, ntg::vectorial)::ensure_type t;
+ //typedef typename mlc::eq<ntg_nb_comp(I), ntg_nb_comp(J)>::ensure_type t;
+
+ static DestValue
+ product(const I &i, const J &j)
+ {
+ DestValue d(ntg_zero_val(DestValue));
+
+ for (unsigned k = 0; k < ntg_nb_comp(I); ++k)
+ d += i[k] * j[k];
+ return d;
+ }
+ };
+ }
+
+ /*! \brief Dot product.
+ **
+ ** \code
+ ** #include <oln/math/macros.hh>
+ ** #include <ntg/all.hh>
+ ** int main()
+ ** {
+ ** ntg::int_u8 i(3), j(4);
+ ** // Print "12"
+ ** std::cout << oln::math::dot_product<ntg::float_s>(i, j) <<
std::endl;
+ **
+ ** ntg::rgb_8 blue(0, 0, 200), yellow(0, 30, 10);
+ ** // Print "2000"
+ ** std::cout << oln::math::dot_product<ntg::float_s>(blue, yellow)
+ ** << std::endl;
+ ** }
+ ** \endcode
+ */
+ template<typename DestValue, typename I, typename J>
+ DestValue
+ dot_product(const I &i, const J &j)
+ {
+ typedef typename mlc::if_<ntg_is_a(I, ntg::vectorial)::ret,
+ internal::f_dot_product_v<DestValue, I, J>,
+ internal::f_dot_product_nv<DestValue, I, J> >::ret fctor;
+ return fctor::product(i, j);
+ }
+
} // end of math
} // end of oln
Index: integre/ntg/core/macros.hh
--- integre/ntg/core/macros.hh Fri, 19 Mar 2004 15:52:57 +0100 palma_g
(oln/s/19_macros.hh 1.10 600)
+++ integre/ntg/core/macros.hh Fri, 26 Mar 2004 20:01:55 +0100 van-vl_n
(oln/s/19_macros.hh 1.10 600)
@@ -160,4 +160,49 @@
`-----*/
#define ntg_nbits(T) ntg::internal::typetraits<T>::size
+
+/*! Return the number of components of T if T is vectorial.
+**
+** If T is non vectorial, the value returned should not be considered.
+*/
+#define ntg_if_vectorial_nb_comp(T) \
+ ntg::type_traits<typename mlc::if_<ntg_is_a(T, ntg::vectorial)::ret, \
+ T, \
+ ntg::vec<42, bool> >::ret>::nb_comp
+
+/*! Same as \a ntg_if_vectorial_nb_comp but without 'typename'
+**
+** \see ntg_if_vectorial_nb_comp
+*/
+#define ntg_if_vectorial_nb_comp_(T) \
+ ntg::type_traits<mlc::if_<ntg_is_a_(T, ntg::vectorial)::ret, \
+ T, \
+ ntg::vec<42, bool> >::ret>::nb_comp
+
+/*! Compare the number of components.
+**
+** - If \a A and \a B are non_vectorial, then
+** \a {ntg_compare_nb_comp(A, B)::ret = true}
+** - If \a A and \a B are vectorial, then
+** \a {ntg_compare_nb_comp(A, B)::ret = (ntg_nb_comp(A) =
ntg_nb_comp(B))}
+** - Otherwise, it returns false
+*/
+#define ntg_compare_nb_comp(A, B) \
+ mlc::if_< \
+ ntg_is_a(A, ntg::non_vectorial)::ret, \
+ ntg_is_a(B, ntg::non_vectorial), \
+ mlc::eq<ntg_if_vectorial_nb_comp(A), \
+ ntg_if_vectorial_nb_comp(B)> >::ret
+
+/*! Same as \a ntg_compare_nb_comp but without 'typename'
+**
+** \see ntg_compare_nb_comp
+*/
+#define ntg_compare_nb_comp_(A, B) \
+ mlc::if_< \
+ ntg_is_a_(A, ntg::non_vectorial)::ret, \
+ ntg_is_a_(B, ntg::non_vectorial), \
+ mlc::eq<ntg_if_vectorial_nb_comp_(A), \
+ ntg_if_vectorial_nb_comp_(B)> >::ret
+
#endif // !NTG_CORE_MACROS_HH
Index: olena/tests/convol/tests/nagao
--- olena/tests/convol/tests/nagao Fri, 26 Mar 2004 20:54:04 +0100
van-vl_n ()
+++ olena/tests/convol/tests/nagao Fri, 26 Mar 2004 20:26:49 +0100
van-vl_n (oln/m/19_nagao 644)
@@ -0,0 +1,37 @@
+// -*-
c++ -*-
+#include <oln/convol/nagao.hh>
+#include <oln/basics2d.hh>
+#include <ntg/all.hh>
+
+#include <oln/utils/md5.hh>
+#include "data.hh"
+#include "check.hh"
+int main()
+{
+ bool fail (false);
+ oln::utils::key::value_type data_key_c[16]
+ = {0x69, 0xa7, 0xce, 0xf0, 0x4b, 0x88, 0x9e, 0xd4, 0x77, 0x63, 0x40,
+ 0xd6, 0x79, 0x42, 0x6a, 0x48};
+ oln::image2d<ntg::rgb_8> imc = oln::load(rdata("lena.ppm"));
+ oln::image2d<ntg::rgb_8> nc = oln::convol::nagao(imc);
+
+ std::cout << oln::utils::md5(nc) << std::endl;
+ fail = fail | (oln::utils::md5(nc) != oln::utils::key(data_key_c));
+
+ oln::utils::key::value_type data_key_g[16]
+ = {0x27, 0xbc, 0xab, 0x48, 0x45, 0x2f, 0xe9, 0xc5, 0x6e, 0x2e, 0x57,
+ 0x27, 0xf, 0x80, 0xfe, 0xaa};
+
+ oln::image2d<ntg::int_u8> im = oln::load(rdata("lena256.pgm"));
+ oln::image2d<ntg::int_u8> ng = oln::convol::nagao(im);
+
+ fail = fail | (oln::utils::md5(ng) != oln::utils::key(data_key_g));
+ if (!fail)
+ std::cout << "OK" << std::endl;
+ else
+ {
+ std::cout << "FAIL" << std::endl;
+ return true;
+ }
+}
+
Index: integre/tests/types/tests/ntg_compare_nb_comp
--- integre/tests/types/tests/ntg_compare_nb_comp Fri, 26 Mar 2004
20:54:04 +0100 van-vl_n ()
+++ integre/tests/types/tests/ntg_compare_nb_comp Fri, 26 Mar 2004
20:49:31 +0100 van-vl_n (oln/m/20_ntg_compar 644)
@@ -0,0 +1,14 @@
+bool should_just_compile;
+should_just_compile = ntg_if_vectorial_nb_comp_(int);
+
+bool fail = false;
+fail = fail || ntg_if_vectorial_nb_comp_(ntg::rgb_8) != 3;
+typedef ntg::vec<3, bool> vec3;
+typedef ntg::vec<4, bool> vec4;
+fail = fail || ntg_if_vectorial_nb_comp_(vec3) != 3;
+fail = fail || ntg_if_vectorial_nb_comp_(vec4) != 4;
+fail = fail || ntg_compare_nb_comp_(int, ntg::rgb_8)::ret != 0;
+fail = fail || ntg_compare_nb_comp_(int, float)::ret != 1;
+fail = fail || ntg_compare_nb_comp_(vec3, ntg::rgb_8)::ret != 1;
+fail = fail || ntg_compare_nb_comp_(vec4, ntg::rgb_8)::ret != 0;
+return fail;
Index: olena/oln/convol/nagao.hxx
--- olena/oln/convol/nagao.hxx Fri, 26 Mar 2004 20:54:04 +0100 van-vl_n ()
+++ olena/oln/convol/nagao.hxx Fri, 26 Mar 2004 20:29:16 +0100 van-vl_n
(oln/m/21_nagao.hxx 644)
@@ -0,0 +1,205 @@
+// 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 OLN_CONVOL_NAGAO_HXX
+# define OLN_CONVOL_NAGAO_HXX
+# include <oln/core/window2d.hh>
+
+namespace oln {
+ namespace convol {
+ namespace internal {
+
+ template<class I, class SE, unsigned Size, typename Sum>
+ inline Sum
+ mean_of_smaller_variance(const oln::abstract::image<I> &im,
+ const oln_point_type(I) &p,
+ const internal::se_array<Size, SE> &w)
+ {
+ ntg_compare_nb_comp(Sum, oln_value_type(I))::ensure();
+
+ precondition(Size > 0);
+ precondition(im.border() >= w.delta());
+
+ typedef typename oln::utils::se_stat<Sum, ntg::float_s> se_stat_type;
+ typedef typename se_stat_type::sum_type sum_type;
+ typedef typename se_stat_type::variance_type variance_type;
+
+ se_stat_type s(im, p, w[0]);
+ variance_type min_variance = s.variance();
+ sum_type mean = s.mean();
+ for (unsigned i = 1; i < Size; ++i)
+ {
+ variance_type tmp = s.compute(im, p, w[i]).variance();
+ if (tmp < min_variance)
+ {
+ min_variance = tmp;
+ mean = s.mean();
+ }
+ }
+ return mean;
+ }
+
+ /*! \brief build 9 windows corresponding to the standard
+ ** 5x5 Nagao filter.
+ */
+ static
+ se_array<9, window2d>
+ mk_nagao_windows_5x5()
+ {
+ se_array<9, window2d> out;
+ //center //.....
+ out[0].add(-1, -1).add(-1, 0).add(-1, 1)//.XXX.
+ .add(0, -1).add(0, 0).add(0, 1) //.XCX.
+ .add(1, -1).add(1, 0).add(1, 1); //.XXX.
+ //.....
+
+ // upper //.XXX.
+ out[1].add(-2, -1).add(-2, 0).add(-2, 1)//.XXX.
+ .add(-1, -1).add(-1, 0).add(-1, 1) //..C..
+ .add(0, 0); //.....
+ //.....
+
+ // right //.....
+ out[2].add(-1, 1).add(-1, 2) //...XX
+ .add(0, 0).add(0, 1).add(0, 2) //..CXX
+ .add(1, 1).add(1, 2); //...XX
+ //.....
+ // bottom //.....
+ out[3].add(2, -1).add(2, 0).add(2, 1) //.....
+ .add(1, -1).add(1, 0).add(1, 1) //..C..
+ .add(0, 0); //.XXX.
+ //.XXX.
+
+ // left //.....
+ out[4].add(-1, -1).add(-1, -2) //XX...
+ .add(0, 0).add(0, -1).add(0, -2) //XXC..
+ .add(1, -1).add(1, -2); //XX...
+ //.....
+
+ // upper-left //XX...
+ out[5].add(-2, -2).add(-2, -1) //XXX..
+ .add(-1, -2).add(-1, -1).add(-1, 0) //.XC..
+ .add(0, -1).add(0, 0); //.....
+ //.....
+
+ // upper-right //...XX
+ out[6].add(-2, 2).add(-2, 1) //..XXX
+ .add(-1, 2).add(-1, 1).add(-1, 0) //..CX.
+ .add(0, 1).add(0, 0); //.....
+ //.....
+
+ // bottom-right //.....
+ out[7].add(2, 2).add(2, 1) //.....
+ .add(1, 2).add(1, 1).add(1, 0) //..CX.
+ .add(0, 1).add(0, 0); //..XXX
+ //...XX
+
+ // bottom-left //.....
+ out[8].add(2, -2).add(2, -1) //.....
+ .add(1, -2).add(1, -1).add(1, 0) //.XC..
+ .add(0, -1).add(0, 0); //XXX..
+ //XX...
+ return out;
+ }
+ } // ! end namespace internal
+
+
+ template <class I, unsigned Size, typename SE, typename Sum>
+ inline oln_concrete_type(I)
+ nagao_generalized(const oln::abstract::image<I>& in,
+ const internal::se_array<Size, SE> &sa)
+ {
+ ntg_compare_nb_comp(Sum, oln_value_type(I))::ensure();
+ in.border_adapt_width(sa.delta());
+ oln_concrete_type(I) out(in.size());
+ oln_iter_type(I) it(out);
+ for_all(it)
+ out[it] = internal::mean_of_smaller_variance<I, SE, Size, Sum>
+ (in, it, sa);
+ return out;
+ }
+
+ /*! Standard Nagao filter 5x5.
+ **
+ ** Apply the 5*5 nagao filter on a non vectorial image.
+ ** \code
+ ** #include <oln/convol/nagao.hh>
+ ** #include <oln/basics2d.hh>
+ ** #include <ntg/all.hh>
+ ** int main()
+ ** {
+ ** oln::image2d<ntg::int_u8> imc = oln::load(IMG_IN "lena256.pgm");
+ ** oln::save(oln::convol::nagao(imc),
+ ** IMG_OUT "oln_convol_nagao_256.pgm");
+ ** }
+ ** \endcode
+ ** \image html lena256_pgm.png
+ ** \image latex lena256_pgm.png
+ ** =>
+ ** \image html oln_convol_nagao_256.png
+ ** \image latex oln_convol_nagao_256.png
+ */
+ template <class I>
+ inline oln_concrete_type(I)
+ nagao(const oln::abstract::non_vectorial_image_with_dim<2, I>& in)
+ {
+ return nagao_generalized<I, 9, window2d, ntg::float_s>
+ (in, internal::mk_nagao_windows_5x5());
+ }
+
+ /*! Standard Nagao filter 5x5.
+ **
+ ** Apply the 5*5 nagao filter on a vectorial image.
+ **
+ ** \code
+ ** #include <oln/convol/nagao.hh>
+ ** #include <oln/basics2d.hh>
+ ** #include <ntg/all.hh>
+ ** int main()
+ ** {
+ ** oln::image2d<ntg::rgb_8> imc = oln::load(IMG_IN "lena.ppm");
+ ** oln::save(oln::convol::nagao(imc), IMG_OUT
"oln_convol_nagao.ppm");
+ ** }
+ ** \endcode
+ ** \image html lena_ppm.png
+ ** \image latex lena_ppm.png
+ ** =>
+ ** \image html oln_convol_nagao.png
+ ** \image latex oln_convol_nagao.png
+ */
+ template <class I>
+ inline oln_concrete_type(I)
+ nagao(const oln::abstract::vectorial_image_with_dim<2, I>& in)
+ {
+ typedef ntg::rgb_8::float_vec_type float_vec_type;
+ return nagao_generalized<I, 9, window2d, float_vec_type>
+ (in, internal::mk_nagao_windows_5x5());
+ }
+ } //! namespace convol
+} //! namespace oln
+
+#endif
Index: olena/oln/convol/nagao.hh
--- olena/oln/convol/nagao.hh Fri, 26 Mar 2004 20:54:04 +0100 van-vl_n ()
+++ olena/oln/convol/nagao.hh Fri, 26 Mar 2004 19:54:47 +0100 van-vl_n
(oln/m/22_nagao.hh 644)
@@ -0,0 +1,157 @@
+// 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 OLN_CONVOL_NAGAO_HH
+# define OLN_CONVOL_NAGAO_HH
+
+# include <oln/utils/se_stat.hh>
+# include <oln/core/abstract/struct_elt.hh>
+# include <oln/core/abstract/image.hh>
+# include <oln/core/image.hh>
+# include <oln/core/abstract/image_with_type_with_dim.hh>
+# include <mlc/array/1d.hh>
+# include <mlc/cmp.hh>
+
+
+namespace oln {
+ namespace convol{
+ namespace internal {
+ /*! array of structuring elements.
+ **
+ ** \param Size Number of structuring elements.
+ ** \param S structuring element type.
+ */
+ template <unsigned Size, class S>
+ struct se_array
+ {
+ /// Type of the struturing elements.
+ typedef mlc_exact_type(oln::abstract::struct_elt<S>) struct_elt_type;
+
+ /// Type of the array.
+ typedef typename mlc::array1d<typename mlc::array1d_info<Size>,
+ struct_elt_type > array_type;
+
+ /// Number of structuring elements.
+ enum {size = Size};
+
+ se_array():delta_(0){}
+
+ /// nth struturing element.
+ struct_elt_type&
+ operator[](int i)
+ {
+ delta_ = -1;
+ precondition(0 <= i < Size);
+ return tab[i];
+ }
+
+ /// nth struturing element.
+ struct_elt_type
+ operator[](int i) const
+ {
+ precondition(0 <= i < Size);
+ return tab[i];
+ }
+
+ /// Maximum of the delta of the structuring elements.
+ coord
+ delta() const
+ {
+ // if not updated, compute the maximum.
+ if (delta_ <= 0)
+ {
+ for (unsigned i = 0; i < Size; ++i)
+ if (tab[i].delta() > delta_)
+ delta_ = tab[i].delta();
+ }
+ postcondition (delta_ >= 0);
+ return delta_;
+ }
+ protected:
+ /// Array of structuring elements.
+ array_type tab;
+ /*! \brief Maximum delta.
+ **
+ ** \note delta_ < 0 means that it must be updated before
+ ** a read access.
+ */
+ mutable coord delta_;
+ };
+
+ /*! Return the mean of the windows that has the smallest variance.
+ **
+ ** \arg im Input image.
+ ** \arg p Origin of the structuring elements.
+ ** \arg w array of structuring elements.
+ **
+ ** \param I Input image type.
+ ** \param SE Structuring element type.
+ ** \param Size Number of windows in the array.
+ ** \param Sum Type use to add values of the input image.
+ **
+ ** \note \a Sum might be a float_s if the image is an image
+ ** of integer, and might be an rgb_8::float_vec_type if I is
+ ** an image of rgb_8.
+ */
+ template<class I, class SE, unsigned Size, typename Sum>
+ inline Sum
+ mean_of_smaller_variance(const oln::abstract::image<I> &im,
+ const oln_point_type(I) &p,
+ const internal::se_array<Size, SE> &w);
+ } // end namespace internal
+
+ /*! A Nagao filter generalized.
+ **
+ ** Each point in the input correspond to the mean of the
+ ** window in which has the smallest variance.
+ **
+ ** \paran in Input image.
+ ** \param sa array of structuring elements.
+ **
+ ** \see oln::convol::nagao
+ */
+ template <class I, unsigned Size, typename SE, typename Sum>
+ inline oln_concrete_type(I)
+ nagao_generalized(const oln::abstract::image<I>& in,
+ const internal::se_array<Size, SE> &sa);
+
+ template <class I>
+ inline oln_concrete_type(I)
+ nagao(const oln::abstract::non_vectorial_image_with_dim<2, I>& in);
+
+
+ template <class I>
+ inline oln_concrete_type(I)
+ nagao(const oln::abstract::vectorial_image_with_dim<2, I>& in);
+ } // end namespace convol
+
+} // end namespace oln
+
+#include "nagao.hxx"
+
+#endif // OLENA_CONVOL_NAGAO_HH
Index: olena/oln/utils/se_stat.hh
--- olena/oln/utils/se_stat.hh Fri, 26 Mar 2004 20:54:04 +0100 van-vl_n ()
+++ olena/oln/utils/se_stat.hh Fri, 26 Mar 2004 19:33:56 +0100 van-vl_n
(oln/m/23_se_stat.hh 644)
@@ -0,0 +1,172 @@
+// 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 OLN_UTILS_SE_STAT_HH
+# define OLN_UTILS_SE_STAT_HH
+
+# include <oln/core/abstract/point.hh>
+# include <oln/core/abstract/image.hh>
+# include <oln/core/abstract/struct_elt.hh>
+
+# include <ntg/core/abstract_hierarchy.hh>
+# include <ntg/all.hh>
+# include <ntg/core/macros.hh>
+# include <oln/math/macros.hh>
+
+namespace oln {
+ namespace utils {
+ namespace internal {
+ /*! This class is used to transform a type to a floating type
equivalent.
+ **
+ ** \todo FIXME: There should be a way to use the standard conversion,
+ ** but I failed to find a good one. The problem is that a color<...>
+ ** derived of vec<..> but the conversion between color and vec
should be
+ ** done through c.to_float(). \n
+ ** Example:
+ ** \verbatim
+ ** rgb_u8::float_vec_type v = rgb_u8(127, 0, 255);
+ ** // v contains 127., 0., 255 but should contain 0.5, 0,1.
+ ** rgb_u8 c = v;
+ ** // c = (255., 255., 255). Error.
+ **
+ ** rgb_u8::float_vec_type v2 = f_to_float_<rgb_u8::float_vec_type>
+ ** rgb_u8(127, 0, 255);
+ ** rgb_u8 c2 = v2;
+ ** // c2 = (127, 0, 255). Ok.
+ ** \endverbatim
+ */
+ template <typename DestT,
+ typename SrcT>
+ struct f_to_float_
+ {
+ static
+ DestT
+ doit(const SrcT& s)
+ {
+ return s;
+ }
+ };
+
+ /// Specialization of the \a f_to_float struct for the colors.
+ template <unsigned ncomps,
+ unsigned qbits,
+ template <unsigned> class color_system>
+ struct f_to_float_<typename ntg::color<ncomps,
+ qbits,
+ color_system>::float_vec_type,
+ ntg::color<ncomps, qbits, color_system> >
+ {
+ static
+ typename ntg::color<ncomps, qbits, color_system>::float_vec_type
+ doit(const ntg::color<ncomps, qbits, color_system>& s)
+ {
+ return s.to_float();
+ }
+ };
+ } // end namespace internal
+
+
+ /*! \brief Compute the variance and the mean within a window.
+ **
+ ** \param Sum type used to compute the sum and the average.
+ ** \param Var type used to compute the variance.
+ **
+ ** \note There is two parameters because for vectorial types the sum
+ ** is usually a vector, and the variance a non vectorial type.
+ */
+ template <typename Sum = ntg::float_s, typename Var = ntg::float_s>
+ class se_stat
+ {
+ public:
+ /// type of used to sum the value (usually floating point values)
+ typedef Sum sum_type;
+ /// type of used for the variance (usually floating point values)
+ typedef Var variance_type;
+
+ /*! Build a se stat.
+ ** \arg im Input image.
+ ** \arg p Origin of the structuring element.
+ ** \arg s Window.
+ */
+ template <class I, class S>
+ se_stat(const oln::abstract::image<I> &im,
+ const oln_point_type(I) &p,
+ const oln::abstract::struct_elt<S> &s)
+ {
+ compute(im, p, s);
+ }
+
+ /// Computes the mean and the variance.
+ template <class I, class S>
+ se_stat &
+ compute(const oln::abstract::image<I> &im,
+ const oln_point_type(I) &p,
+ const oln::abstract::struct_elt<S> &s);
+
+ /// Mean.
+ inline Sum
+ mean() const
+ {
+ return mean_;
+ }
+
+ /// Variance.
+ inline Var
+ variance() const
+ {
+ return variance_;
+ }
+
+ /// Sum.
+ inline Sum
+ sum() const
+ {
+ return sum_;
+ }
+
+ /// Cardinal of the structuring element.
+ inline unsigned
+ card() const
+ {
+ return card_;
+ }
+
+ protected:
+ Var variance_; ///< Variance.
+ Sum mean_; ///< Mean.
+ Sum sum_; ///< Sum.
+ int card_; ///< Card of the input structuring element.
+ };
+
+ } // end namespace utils
+
+} // end namespace oln
+
+#include "se_stat.hxx"
+
+#endif //! OLN_UTILS_SE_STAT_HH
Index: olena/oln/utils/se_stat.hxx
--- olena/oln/utils/se_stat.hxx Fri, 26 Mar 2004 20:54:04 +0100 van-vl_n ()
+++ olena/oln/utils/se_stat.hxx Fri, 26 Mar 2004 19:59:59 +0100 van-vl_n
(oln/m/24_se_stat.hx 644)
@@ -0,0 +1,70 @@
+// 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 OLN_UTILS_SE_STAT_HXX
+# define OLN_UTILS_SE_STAT_HXX
+
+namespace oln {
+ namespace utils {
+
+ /// Computes the mean and the variance.
+ template <typename Sum, typename Var>
+ template <class I, class S>
+ inline se_stat<Sum, Var> &
+ se_stat<Sum, Var>::compute(const oln::abstract::image<I> &im,
+ const oln_point_type(I) &p,
+ const oln::abstract::struct_elt<S> &s)
+ {
+ sum_ = ntg_zero_val(Sum);
+ card_ = s.card();
+ // Compute the mean
+ oln_iter_type(S) it(s);
+ {
+ for_all(it)
+ sum_ += internal::f_to_float_<Sum,
+ oln_value_type(I)>::doit(im[p + it]);
+ mean_ = sum_ / card_;
+ }
+ // Compute the variance
+ {
+ Var sum_2(ntg_zero_val(Var));
+ for_all(it)
+ {
+ Sum tmp = mean_;
+ tmp -= im[p + it];
+ sum_2 += oln::math::dot_product<Var>(tmp, tmp);
+ }
+ variance_ = sum_2 / card_;
+ }
+ return *this;
+ }
+ } // end namespace utils
+
+} // end namespace oln
+
+#endif //! OLN_UTILS_SE_STAT_HXX