Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
April 2009
- 11 participants
- 187 discussions
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Improve vector and matrix interoperability.
* mln/algebra/mat.hh (t): New method to transpose; replace...
(trans): Remove procedure.
(operator*): New overloads to improve interoperatibility
between vectors and matrices.
* mln/registration/get_rot.hh: Update.
* mln/registration/icp.hh: Update.
* mln/algebra/vec.hh (mat<n, 1, U>): New conversion op, ctor,
and assignment; declarations only, definitions are...
* mln/algebra/mat.hh (mat<n, 1, U>): ...new.
* tests/algebra/op_times.cc: New.
* mln/labeling/compute.hh: Disable check to run on int_u.
* mln/accu/sum.hh (take_as_init): New.
* mln/accu/image/take_as_init.hh: New overload for image as arg.
* tests/accu/image/take_as_init.cc: Augment.
mln/accu/image/take_as_init.hh | 110 ++++++++++++++++++++++++++-
mln/accu/sum.hh | 12 ++
mln/algebra/mat.hh | 158 ++++++++++++++++++++++++++++++++++-----
mln/algebra/vec.hh | 18 ++++
mln/labeling/compute.hh | 2
mln/registration/get_rot.hh | 5 -
mln/registration/icp.hh | 4
tests/accu/image/take_as_init.cc | 3
tests/algebra/op_times.cc | 72 +++++++++++++++++
9 files changed, 357 insertions(+), 27 deletions(-)
Index: mln/accu/image/take_as_init.hh
--- mln/accu/image/take_as_init.hh (revision 3690)
+++ mln/accu/image/take_as_init.hh (working copy)
@@ -50,6 +50,11 @@
take_as_init(Image<I>& input,
const mln_deduce(I, value, argument)& v);
+ template <typename I, typename J>
+ void
+ take_as_init(Image<I>& input,
+ const Image<J>& values);
+
# ifndef MLN_INCLUDE_ONLY
@@ -57,7 +62,7 @@
namespace impl
{
- // Generic version.
+ // Generic versions.
namespace generic
{
@@ -79,10 +84,29 @@
trace::exiting("accu::impl::image::generic::take_as_init");
}
+ template <typename I, typename J>
+ void
+ take_as_init(Image<I>& input_,
+ const Image<J>& values_)
+ {
+ trace::entering("accu::impl::image::generic::take_as_init");
+
+ I& input = exact(input_);
+ const I& values = exact(values_);
+ mln_precondition(input.is_valid());
+ mln_precondition(values.is_valid());
+
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ input(p).take_as_init(values(p));
+
+ trace::exiting("accu::impl::image::generic::take_as_init");
+ }
+
} // end of namespace mln::accu::image::impl::generic
- // Fastest version.
+ // Fastest versions.
template <typename I>
void
@@ -101,6 +125,26 @@
trace::exiting("accu::impl::image::take_as_init_fastest");
}
+ template <typename I, typename J>
+ void
+ take_as_init_fastest(Image<I>& input_,
+ const Image<J>& values_)
+ {
+ trace::entering("accu::impl::image::take_as_init_fastest");
+
+ I& input = exact(input_);
+ const I& values = exact(values_);
+ mln_precondition(input.is_valid());
+ mln_precondition(values.is_valid());
+
+ mln_pixter(I) p_in(input);
+ mln_pixter(const J) p_v(values);
+ for_all_2(p_in, p_v)
+ p_in.val().take_as_init(p_v.val());
+
+ trace::exiting("accu::impl::image::take_as_init_fastest");
+ }
+
} // end of namespace mln::accu::image::impl
@@ -110,7 +154,10 @@
namespace internal
{
+ // With a single value.
+
template <typename I, typename V>
+ inline
void
take_as_init_dispatch(trait::image::speed::any,
Image<I>& input, const V& v)
@@ -119,6 +166,7 @@
}
template <typename I, typename V>
+ inline
void
take_as_init_dispatch(trait::image::speed::fastest,
Image<I>& input, const V& v)
@@ -127,6 +175,7 @@
}
template <typename I, typename V>
+ inline
void
take_as_init_dispatch(Image<I>& input, const V& v)
{
@@ -134,12 +183,46 @@
input, v);
}
+ // With an image of values.
+
+ template <typename I, typename J>
+ inline
+ void
+ take_as_init_dispatch(trait::image::speed::any,
+ trait::image::speed::any,
+ Image<I>& input, const Image<J>& values)
+ {
+ impl::generic::take_as_init(input, values);
+ }
+
+ template <typename I, typename J>
+ inline
+ void
+ take_as_init_dispatch(trait::image::speed::fastest,
+ trait::image::speed::fastest,
+ Image<I>& input, const Image<J>& values)
+ {
+ impl::take_as_init_fastest(input, values);
+ }
+
+ template <typename I, typename J>
+ inline
+ void
+ take_as_init_dispatch(Image<I>& input,
+ const Image<J>& values)
+ {
+ take_as_init_dispatch(mln_trait_image_speed(I)(),
+ mln_trait_image_speed(J)(),
+ input, values);
+ }
+
} // end of namespace mln::accu::image::internal
- // Facade.
+ // Facades.
template <typename I>
+ inline
void
take_as_init(Image<I>& input,
const mln_deduce(I, value, argument)& v)
@@ -154,6 +237,27 @@
trace::exiting("accu::image::take_as_init");
}
+ template <typename I, typename J>
+ inline
+ void
+ take_as_init(Image<I>& input,
+ const Image<J>& values)
+ {
+ trace::entering("accu::image::take_as_init");
+
+ typedef mln_value(I) A;
+ mlc_is_a(A, Accumulator)::check();
+ mlc_converts_to(mln_value(J), mln_argument(A))::check();
+
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(exact(values).is_valid());
+ // mln_precondition(exact(values).domain() == exact(input).domain());
+
+ internal::take_as_init_dispatch(input, values);
+
+ trace::exiting("accu::image::take_as_init");
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu::image
Index: mln/accu/sum.hh
--- mln/accu/sum.hh (revision 3690)
+++ mln/accu/sum.hh (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -67,6 +67,7 @@
/// \{
void init();
void take(const argument& t);
+ void take_as_init(const argument& t);
void take(const sum<T,S>& other);
/// \}
@@ -128,6 +129,13 @@
template <typename T, typename S>
inline
+ void sum<T,S>::take_as_init(const argument& t)
+ {
+ s_ = static_cast<S>(t);
+ }
+
+ template <typename T, typename S>
+ inline
void
sum<T,S>::take(const sum<T,S>& other)
{
Index: mln/algebra/mat.hh
--- mln/algebra/mat.hh (revision 3690)
+++ mln/algebra/mat.hh (working copy)
@@ -82,6 +82,7 @@
namespace algebra
{
+
template <unsigned n, unsigned m, typename T>
class mat : public Object< mat<n,m,T> >
{
@@ -118,6 +119,9 @@
static mat identity();
+ /// Return the transpose of the matrix.
+ mat<m,n,T> t() const;
+
private:
T data_[n][m];
};
@@ -229,6 +233,11 @@
mat<n, m, mln_sum_product(T,U)>
operator*(const mat<n,o,T>& lhs, const mat<o,m,U>& rhs);
+ template <unsigned o, typename T,
+ typename U>
+ mln_sum_product(T,U)
+ operator*(const mat<1,o,T>& lhs, const mat<o,1,U>& rhs);
+
// mat * vec
template <unsigned n, unsigned m, typename T,
@@ -236,6 +245,17 @@
vec<n, mln_sum_product(T,U)>
operator*(const mat<n,m,T>& lhs, const vec<m,U>& rhs);
+ template <unsigned m, typename T,
+ typename U>
+ mln_sum_product(T,U) // scalar
+ operator*(const mat<1,m,T>& lhs, const vec<m,U>& rhs);
+
+ // vec * mat
+
+ template <unsigned m, typename T, typename U>
+ mat<m, m, mln_trait_op_times(T,U)>
+ operator*(const vec<m,T>& lhs, const mat<1,m,U>& rhs);
+
// mat * s
template <unsigned n, unsigned m, typename T,
@@ -255,11 +275,6 @@
std::ostream&
operator<<(std::ostream& ostr, const mat<n,m,T>& v);
- // transpose
-
- template<unsigned n, unsigned m, typename T>
- mat<m,n,T>
- trans(const mat<n,m,T>& matrix);
// trace
@@ -267,14 +282,61 @@
float tr(const mat<n,n,T>& m);
+
# ifndef MLN_INCLUDE_ONLY
+
+ // vec -> mat
+
+ template <unsigned n, typename T>
+ template <typename U>
+ inline
+ vec<n,T>::operator mat<n,1,U>() const
+ {
+ mlc_converts_to(T, U)::check();
+ mat<n,1,U> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ tmp(i, 0) = data_[i];
+ return tmp;
+ }
+
+
+ // mat -> vec
+
+ template <unsigned n, typename T>
+ template <typename U>
+ inline
+ vec<n,T>::vec(const mat<n, 1, U>& rhs)
+ {
+ mlc_converts_to(T, U)::check();
+ for (unsigned i = 0; i < n; ++i)
+ data_[i] = rhs(i, 0);
+ }
+
+ template <unsigned n, typename T>
+ template <typename U>
+ inline
+ vec<n,T>&
+ vec<n,T>::operator=(const mat<n, 1, U>& rhs)
+ {
+ mlc_converts_to(T, U)::check();
+ for (unsigned i = 0; i < n; ++i)
+ data_[i] = rhs(i, 0);
+ return *this;
+ }
+
+
+
+ // Id
+
template <unsigned n, unsigned m, typename T>
- const mat<n,m,T> mat<n,m,T>::Id = mat<n,m,T>::identity();
+ const mat<n,m,T>
+ mat<n,m,T>::Id = mat<n,m,T>::identity();
template <unsigned n, unsigned m, typename T>
inline
- mat<n,m,T> mat<n,m,T>::identity()
+ mat<n,m,T>
+ mat<n,m,T>::identity()
{
static mat<n,m,T> id_;
static bool flower = true;
@@ -369,6 +431,18 @@
return n * m;
}
+ template <unsigned n, unsigned m, typename T>
+ inline
+ mat<m,n,T>
+ mat<n,m,T>::t() const
+ {
+ mat<m,n,T> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ for (unsigned j = 0; j < m; ++j)
+ tmp(j,i) = data_[i][j];
+ return tmp;
+ }
+
// Operators.
@@ -421,6 +495,8 @@
return tmp;
}
+ // mat * mat
+
template <unsigned n, unsigned o, typename T,
unsigned m, typename U>
inline
@@ -438,6 +514,20 @@
return tmp;
}
+ template <unsigned o, typename T,
+ typename U>
+ inline
+ mln_sum_product(T,U)
+ operator*(const mat<1,o,T>& lhs, const mat<o,1,U>& rhs)
+ {
+ mln_sum_product(T,U) tmp(literal::zero);
+ for (unsigned k = 0; k < o; ++k)
+ tmp += lhs(0, k) * rhs(k, 0);
+ return tmp;
+ }
+
+ // mat * vec
+
template <unsigned n, unsigned m, typename T,
typename U>
inline
@@ -455,6 +545,35 @@
return tmp;
}
+ template <unsigned m, typename T,
+ typename U>
+ inline
+ mln_sum_product(T,U) // scalar
+ operator*(const mat<1,m,T>& lhs, const vec<m,U>& rhs)
+ {
+ mln_sum_product(T,U) tmp(literal::zero);
+ for (unsigned j = 0; j < m; ++j)
+ tmp += lhs(0, j) * rhs[j];
+ return tmp;
+ }
+
+ // vec * mat
+
+ template <unsigned m, typename T,
+ typename U>
+ inline
+ mat<m, m, mln_trait_op_times(T,U)>
+ operator*(const vec<m,T>& lhs, const mat<1,m,U>& rhs)
+ {
+ mat<m, m, mln_trait_op_times(T,U)> tmp;
+ for (unsigned i = 0; i < m; ++i)
+ for (unsigned j = 0; j < m; ++j)
+ tmp(i, j) = lhs[i] * rhs(0, j);
+ return tmp;
+ }
+
+ // mat * s
+
template <unsigned n, unsigned m, typename T, typename S>
inline
mat<n, m, mln_trait_op_times(T,S)>
@@ -499,16 +618,7 @@
}
- template<unsigned n, unsigned m, typename T>
- mat<m,n,T>
- trans(const mat<n,m,T>& matrix)
- {
- mat<m,n,T> tmp;
- for (unsigned i = 0; i < n; ++i)
- for (unsigned j = 0; j < m; ++j)
- tmp(j,i) = matrix(i,j);
- return tmp;
- }
+ // Trace.
template<unsigned n, typename T> inline
float tr(const mat<n,n,T>& m)
@@ -519,6 +629,20 @@
return f;
}
+
+ // vec methods.
+
+ template <unsigned n, typename T>
+ inline
+ mat<1,n,T>
+ vec<n,T>::t() const
+ {
+ mat<1,n,T> tmp;
+ for (unsigned i = 0; i < n; ++i)
+ tmp(0,i) = data_[i];
+ return tmp;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::algebra
Index: mln/algebra/vec.hh
--- mln/algebra/vec.hh (revision 3690)
+++ mln/algebra/vec.hh (working copy)
@@ -59,6 +59,7 @@
namespace algebra {
template <unsigned n, typename T> class vec;
template <unsigned d, typename C> class h_vec;
+ template <unsigned n, unsigned m, typename T> class mat;
}
namespace literal {
@@ -235,6 +236,9 @@
lower (sic) to zero. */
const vec<n, T>& normalize();
+ /// Transposition.
+ mat<1, n, T> t() const;
+
/// Constructor; coordinates are set by function \p f.
template <typename F>
vec(const Function_i2v<F>& f);
@@ -244,6 +248,19 @@
/// Origin value.
static const vec<n, T> origin;
+
+
+ /// Conversion to a matrix.
+ template <typename U>
+ operator mat<n, 1, U>() const;
+
+ /// Construction from a matrix.
+ template <typename U>
+ vec(const mat<n, 1, U>& rhs);
+
+ /// Assignment from a matrix.
+ template <typename U>
+ vec& operator=(const mat<n, 1, U>& rhs);
};
} // end of namespace mln::algebra
@@ -632,6 +649,7 @@
# include <mln/make/vec.hh>
+# include <mln/algebra/mat.hh>
#endif // ! MLN_ALGEBRA_VEC_HH
Index: mln/registration/get_rot.hh
--- mln/registration/get_rot.hh (revision 3690)
+++ mln/registration/get_rot.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of the Olena Library. This library is free
@@ -35,6 +35,7 @@
# include <mln/algebra/vec.hh>
# include <mln/math/jacobi.hh>
+
namespace mln
{
@@ -97,7 +98,7 @@
{
algebra::vec<3u,float> ci = convert::to< algebra::vec<3u,float> >(c[i]);
algebra::vec<3u,float> xki = convert::to< algebra::vec<3u,float> >(map(ck[i]));
- Mk += make::mat(ci - mu_c) * trans(make::mat(xki - mu_xk));
+ Mk += (ci - mu_c) * (xki - mu_xk).t();
}
Mk /= c.nsites();
Index: mln/registration/icp.hh
--- mln/registration/icp.hh (revision 3690)
+++ mln/registration/icp.hh (working copy)
@@ -78,10 +78,10 @@
# include <mln/io/cloud/save.hh>
+
namespace mln
{
-
namespace registration
{
@@ -530,7 +530,7 @@
vec3d_f P_i = p;
vec3d_f Pk_i = qR.rotate(P_i) + qT;
vec3d_f Yk_i = closest_point(Pk_i);
- Spx += make::mat(P_i - mu_P) * trans(make::mat(Yk_i - mu_Yk));
+ Spx += (P_i - mu_P) * (Yk_i - mu_Yk).t();
}
Spx /= P_.nsites();
Index: mln/labeling/compute.hh
--- mln/labeling/compute.hh (revision 3690)
+++ mln/labeling/compute.hh (working copy)
@@ -145,7 +145,7 @@
{
mln_precondition(exact(input).is_valid());
mln_precondition(exact(label).is_valid());
- mlc_is_a(mln_value(L), mln::value::Symbolic)::check();
+ // mlc_is_a(mln_value(L), mln::value::Symbolic)::check();
(void) a;
(void) input;
(void) label;
Index: tests/accu/image/take_as_init.cc
--- tests/accu/image/take_as_init.cc (revision 3690)
+++ tests/accu/image/take_as_init.cc (working copy)
@@ -45,4 +45,7 @@
accu::image::take_as_init(ima, 3);
debug::println(ima);
+
+ accu::image::take_as_init(ima, ima);
+ debug::println(ima);
}
Index: tests/algebra/op_times.cc
--- tests/algebra/op_times.cc (revision 0)
+++ tests/algebra/op_times.cc (revision 0)
@@ -0,0 +1,72 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+/// \file tests/algebra/op_times.cc
+///
+/// Tests on mln::algebra::operator *.
+
+#include <iostream>
+#include <mln/algebra/mat.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ using algebra::vec;
+ using algebra::mat;
+
+ // Debase tests.
+ {
+ algebra::vec<3, float> v3;
+ algebra::mat<2,3,float> m23;
+ algebra::mat<3,2,float> m32;
+
+ algebra::mat<2,2,float> m22 = m23 * m32;
+ algebra::vec<2, float> v2 = m23 * v3;
+
+ m22 = v2 * v2.t();
+ }
+
+ // Tests with horizontal and/or vertical matrices and/or vectors.
+ {
+ float f;
+ algebra::vec<3, float> v3;
+ algebra::mat<1,3,float> m13;
+ algebra::mat<3,1,float> m31;
+
+ f = m13 * m31;
+ f = m31.t() * m13.t();
+ f = m13 * v3;
+ f = v3.t() * v3;
+
+ v3 = m31;
+ m31 = v3;
+ }
+
+}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-04-20 Vincent Ordy <ordy(a)lrde.epita.fr>
Fix configure.
* configure:
Add rules to Makefile.rules without erasing the old file.
---
configure | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Index: trunk/milena/sandbox/inim/2010/boxes/configure
===================================================================
--- trunk/milena/sandbox/inim/2010/boxes/configure (revision 3689)
+++ trunk/milena/sandbox/inim/2010/boxes/configure (revision 3690)
@@ -19,9 +19,9 @@
touch Makefile.rules
if [ "$debug" ]; then
- echo 'DEBUG = 1' > Makefile.rules
+ echo 'DEBUG = 1' >> Makefile.rules
fi
if [ "$release" ]; then
- echo 'RELEASE = 1' > Makefile.rules
+ echo 'RELEASE = 1' >> Makefile.rules
fi
-echo "MLN_DIR = $MLN_DIR" > Makefile.rules
+echo "MLN_DIR = $MLN_DIR" >> Makefile.rules
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-04-20 Warren Seine <soow(a)lrde.epita.fr>
inim: Fix configure.
* boxes/Makefile: Fix bad include.
* boxes/configure: Add test.
---
Makefile | 2 +-
configure | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
Index: trunk/milena/sandbox/inim/2010/boxes/configure
===================================================================
--- trunk/milena/sandbox/inim/2010/boxes/configure (revision 3688)
+++ trunk/milena/sandbox/inim/2010/boxes/configure (revision 3689)
@@ -10,6 +10,11 @@
fi
done
+if [ x$MLN_DIR == x ]; then
+ echo "MLN_DIR not set" > /dev/stderr
+ exit 1
+fi
+
rm -f Makefile.rules
touch Makefile.rules
Index: trunk/milena/sandbox/inim/2010/boxes/Makefile
===================================================================
--- trunk/milena/sandbox/inim/2010/boxes/Makefile (revision 3688)
+++ trunk/milena/sandbox/inim/2010/boxes/Makefile (revision 3689)
@@ -1,4 +1,4 @@
-include makefile.rules
+include Makefile.rules
TARGET=boxes
boxes_SRC=boxes.cc
--
:: Warren Seine // SooW ::
:: warren.seine @ gmail.com ::
:: EPITA CSI 2010 ::
1
0
19 Apr '09
ChangeLog:
2009-04-19 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Process line: WST from color image using tree component. (BUG).
* edwin/rush/exo2/wst_from_tree.cc: Process line.
* edwin/tree/components.hh: Fix bug related to research of n
components method.
---
rush/exo2/Makefile | 7 -
rush/exo2/wst_from_tree.cc | 235 +++++++++++++++++++++++++++++++++++++++++++++
tree/components.hh | 12 +-
3 files changed, 247 insertions(+), 7 deletions(-)
Index: trunk/milena/sandbox/edwin/tree/components.hh
===================================================================
--- trunk/milena/sandbox/edwin/tree/components.hh (revision 3687)
+++ trunk/milena/sandbox/edwin/tree/components.hh (revision 3688)
@@ -222,7 +222,7 @@
p_array< mln_psite(A) > components;
mln_ch_value(A, bool) activity;
p_array< mln_psite(A) > max_arr = tree.nodes();
- unsigned arr_pos = 0; //position in max_array
+ unsigned arr_pos; //position in max_array
unsigned n = 0;
unsigned* nb_leaves = uses_leaves ? new unsigned(0) : 0;
@@ -237,11 +237,13 @@
p = max_arr[arr_pos];
if (a(p) == 0)
break;
+ //std::cout << p << " " << a(p) << std::endl;
components.insert(p);
morpho::tree::propagate_node_to_descendants(p, tree, activity, false, nb_leaves);
morpho::tree::propagate_node_to_ancestors(p, tree, activity, false);
activity(p) = false;
- mln_assertion(nb_leaves == 0 || *nb_leaves <= n);
+ n++;
+ mln_assertion(nb_leaves == 0 || *nb_leaves < mln_max(unsigned));
}
while (pred(p, n, nb_leaves));
@@ -281,8 +283,10 @@
mln_precondition(tree.f().domain() == a.domain());
mln_precondition(a.is_valid());
- p_array< mln_psite(A) > components =
- internal::get_components(tree, a, internal::pred_n_components(n), false);
+ p_array< mln_psite(A) > components;
+
+ if (n > 0)
+ components = internal::get_components(tree, a, internal::pred_n_components(n), false);
trace::exiting("mln::morpho::tree::get_components");
return components;
Index: trunk/milena/sandbox/edwin/rush/exo2/wst_from_tree.cc
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/wst_from_tree.cc (revision 0)
+++ trunk/milena/sandbox/edwin/rush/exo2/wst_from_tree.cc (revision 3688)
@@ -0,0 +1,235 @@
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+/* core */
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/value/label_16.hh>
+
+/* io */
+#include <mln/io/ppm/load.hh>
+#include <mln/io/ppm/save.hh>
+
+/* Gradient */
+#include "color_internal_gradient.hh"
+
+/* Labeling */
+#include <mln/level/convert.hh>
+#include "color_labeling_mean.hh"
+
+/* WST */
+#include <mln/morpho/watershed/all.hh>
+#include <mln/morpho/elementary/dilation.hh>
+
+/* Tree computation */
+#include <mln/level/sort_psites.hh>
+#include <mln/morpho/tree/data.hh>
+#include "../../tree/propagate.hh"
+#include "../../tree/components.hh"
+
+#include <mln/morpho/tree/compute_attribute_image.hh>
+#include <mln/morpho/attribute/sharpness.hh>
+
+/* pw */
+#include <mln/core/concept/function.hh>
+#include <mln/fun/p2v/ternary.hh>
+#include <mln/pw/all.hh>
+
+//std
+#include <iostream>
+#include <string>
+
+#include <mln/level/stretch.hh>
+#include <mln/io/pgm/save.hh>
+
+namespace mln
+{
+ // Sharpness Attribute -> Height Attribute
+ template <typename P2V>
+ struct height_wrapper_ : Function_p2v< height_wrapper_<P2V> >
+ {
+ typedef unsigned result;
+
+ height_wrapper_(const Function_p2v<P2V>& f) :
+ f_ (exact(f))
+ {
+ mlc_is_a(mln_result(P2V), Accumulator)::check();
+ }
+
+ template <typename P>
+ unsigned operator() (const P& p) const
+ {
+ return f_(p).height();
+ }
+
+ private:
+ const P2V& f_;
+ };
+
+ // meta
+ template <typename P2V>
+ inline
+ height_wrapper_<P2V>
+ height_wrapper(const Function_p2v<P2V>& f)
+ {
+ return height_wrapper_<P2V>(f);
+ }
+}
+
+
+
+
+
+void usage(char** argv)
+{
+ std::cout << "Usage: " << argv[0] << " input.ppm height [-o1 | -o2 | -o3]"
+ << std::endl
+ << "-o1\tSuperpose WS on input image (out: superpose.ppm)" << std::endl
+ << "-o2\tCount number of basins" << std::endl
+ << "-o3\tReplace basin by its mean color on the input (out: mean.ppm)"
+ << std::endl;
+ abort();
+}
+
+
+int main(int argc, char** argv)
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::int_u16;
+ using value::rgb8;
+
+ if (argc < 3)
+ usage(argv);
+
+ int output_ = 0;
+ int lambda_h = std::atoi(argv[2]);
+
+ if (argc == 4)
+ if (std::string(argv[3]) == "-o1")
+ output_ = 1;
+ else if (std::string(argv[3]) == "-o2")
+ output_ = 2;
+ else if (std::string(argv[3]) == "-o3")
+ output_ = 3;
+ else
+ usage(argv);
+
+
+
+ // Load color image.
+ typedef image2d<rgb8> I_;
+
+ I_ input_;
+ io::ppm::load(input_, argv[1]);
+
+ /***************************/
+ /* Preprocessing (gradient)*/
+ /***************************/
+ typedef image2d<int_u8> I;
+
+ I input = color_internal_gradient(input_);
+
+ /***************************/
+ /* Component tree creation */
+ /***************************/
+ typedef p_array<point2d> S;
+ typedef morpho::tree::data<I,S> tree_t;
+
+ S s = level::sort_psites_decreasing(input);
+ tree_t t(input, s, c4());
+
+
+ /******************************/
+ /* Compute Attribute On Image */
+ /******************************/
+ typedef mln_ch_value_(I, double) A;
+ A a;
+ {
+ typedef morpho::attribute::sharpness<I> sharp_t;
+ typedef mln_ch_value_(I, sharp_t) B;
+
+ // Attribute Pruning
+ B a_img;
+ a = morpho::tree::compute_attribute_image(sharp_t (), t, &a_img);
+
+ // Component filtering
+ a = duplicate((fun::p2v::ternary(height_wrapper(pw::value(a_img)) > pw::cst(lambda_h),
+ pw::value(a),
+ pw::cst(0.0))) | a.domain());
+ }
+
+ /************************************************/
+ /* Retrieve Components (Maximising the criteria)*/
+ /************************************************/
+ A component_img;
+ {
+ p_array< mln_psite_(A) > obj_array;
+ I output = level::stretch(int_u8(), a); //adapt to 0-255
+ io::pgm::save(output, "components.pgm");
+
+ obj_array = morpho::tree::get_components(t, a);
+ std::cout << obj_array.nsites() << std::endl;
+
+ component_img = morpho::tree::propagate_components(a, t, obj_array, 1);
+
+ // debug
+ //I output = level::stretch(int_u8(), component_img); //adapt to 0-255
+ //io::pgm::save(output, "components.pgm");
+
+ }
+
+
+ /************************************************/
+ /* WATERSHED */
+ /************************************************/
+ typedef image2d<int_u16> WST;
+ int_u16 n_basins = 0;
+ WST wst = morpho::watershed::flooding(component_img, c4(), n_basins);
+
+ if (!output_ || output_ == 1)
+ {
+ I_ out = morpho::watershed::superpose(input_, wst);
+ io::ppm::save(out, "superpose.pgm");
+ }
+ if (!output_ || output_ == 2)
+ std::cout << "Number of basins: " << n_basins << std::endl;
+
+ if (!output_ || output_ == 3)
+ {
+ typedef image2d<value::label_16> L;
+ L lab = level::convert(value::label_16(),
+ morpho::elementary::dilation(wst, c8()));
+ I_ out = color_labeling_mean(input_, lab, n_basins);
+ io::ppm::save(out, "mean.pgm");
+ }
+}
Index: trunk/milena/sandbox/edwin/rush/exo2/Makefile
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/Makefile (revision 3687)
+++ trunk/milena/sandbox/edwin/rush/exo2/Makefile (revision 3688)
@@ -13,8 +13,10 @@
SRC=
OUT_IMG=superpose.pgm mean.pgm gradient.pgm closing.pgm
+BIN=wst_from_closing wst_from_tree
-all: wst_from_closing
+
+all: $(BIN)
%: %.cc
$(CXX) $(CXXFLAGS) $< -o $@
@@ -22,8 +24,7 @@
clean:
rm -f $(OUT_IMG)
- rm -f wst_from_closing
-
+ rm -f $(BIN)
%.o: %.cc
$(CXX) $(CXXFLAGS) -c $<
\ No newline at end of file
1
0
19 Apr '09
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-04-19 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Process line: watershed from color image after height closing.
* edwin/rush/*,
* edwin/rush/leaves: New directory for leaves export
routines. Move rush/* to rush/leaves.*
* edwin/rush/exo2: New.
* edwin/rush/exo2/color_internal_gradient.hh: Routine that
computes internal gradient from color image.
* edwin/rush/exo2/color_labeling_mean.hh: Routine that
replaces a basin label by its mean color.
* edwin/rush/exo2/wst_from_closing.cc: Process line.
---
exo2/Makefile | 29 +++++++
exo2/color_internal_gradient.hh | 149 ++++++++++++++++++++++++++++++++++++++++
exo2/color_labeling_mean.hh | 70 ++++++++++++++++++
exo2/configure | 21 +++++
exo2/wst_from_closing.cc | 127 ++++++++++++++++++++++++++++++++++
leaves/Makefile | 35 +++++++++
leaves/chain.sh | 34 +++++++++
leaves/configure | 21 +++++
leaves/export_leaves.hh | 115 ++++++++++++++++++++++++++++++
leaves/get_leaves.cc | 65 +++++++++++++++++
leaves/splot.sh | 10 ++
leaves/test/Makefile | 41 +++++++++++
leaves/test/configure | 21 +++++
leaves/test/export.cc | 63 ++++++++++++++++
14 files changed, 801 insertions(+)
Index: trunk/milena/sandbox/edwin/rush/configure (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/rush/get_leaves.cc (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/rush/splot.sh (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/rush/chain.sh (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/rush/Makefile (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/rush/export_leaves.hh (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/rush/leaves/test/configure
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/test/configure (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/test/configure (revision 3687)
@@ -0,0 +1,21 @@
+#! /bin/bash
+
+for arg in "$@"; do
+ if [ "$arg" == "--debug" ]; then
+ debug=1;
+ elif [ "$arg" == "--release" ]; then
+ release=1;
+ elif [ "${arg#--mln_dir=}" ]; then
+ MLN_DIR=${arg#--mln_dir=}
+ fi
+done
+
+rm -f makefile.rules
+touch makefile.rules
+if [ "$debug" ]; then
+ echo 'DEBUG = 1' >> makefile.rules
+fi
+if [ "$release" ]; then
+ echo 'RELEASE = 1' >> makefile.rules
+fi
+echo "MLN_DIR = $MLN_DIR" >> makefile.rules
\ No newline at end of file
Property changes on: trunk/milena/sandbox/edwin/rush/leaves/test/configure
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/leaves/test/export.cc
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/test/export.cc (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/test/export.cc (revision 3687)
@@ -0,0 +1,63 @@
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/site_set/p_array.hh>
+
+#include <mln/level/sort_psites.hh>
+
+#include <mln/morpho/tree/data.hh>
+#include "../export_leaves.hh"
+
+#include <mln/io/pbm/save.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d<int> I;
+ typedef p_array<point2d> S;
+ typedef morpho::tree::data<I,S> tree_t;
+
+ int vals[] = {3, 3, 4,
+ 3, 5, 4,
+ 4, 4, 4 };
+
+ I ima = make::image2d(vals);
+ S s = level::sort_psites_decreasing(ima);
+ tree_t t(ima, s, c4());
+
+ export_leaves_to_file(t, ima);
+
+ typedef mln_ch_value_(I, bool) B;
+ B b_img = export_leaves_to_img(t, ima);
+
+ io::pbm::save(b_img, "leaves.pbm");
+}
Index: trunk/milena/sandbox/edwin/rush/leaves/test/Makefile
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/test/Makefile (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/test/Makefile (revision 3687)
@@ -0,0 +1,41 @@
+include makefile.rules
+TARGET=export
+#sharp_SRC=sharp.cc
+#sharp_OBJS=${sharp_SRC:.cc=.o}
+
+export_SRC=export.cc
+export_OBJS=${export_SRC:.cc=.o}
+
+OLENADIR=$(MLN_DIR)/..
+MILENADIR=$(MLN_DIR)
+
+CXXFLAGS=-I$(MILENADIR) -I./ -W -Wall
+
+
+CXXFLAGS += $(if $(DEBUG), -g -ggdb, -DNDEBUG\
+ $(if $(RELEASE), -O3, -O1))
+
+CXX=g++
+LD=g++
+LDFLAGS=
+
+all: $(TARGET)
+
+
+$(TARGET): $($(TARGET)_OBJS) $($(TARGET)_SRC)
+ $(LD) $(LDFLAGS) -o $@ $($(TARGET)_OBJS)
+
+%.o: %.cc
+ $(CXX) $(CXXFLAGS) -c $<
+
+%.o: %.hh
+ $(CXX) $(CXXFLAGS) -c $<
+
+depend:
+ makedepend -- $(CXXFLAGS) -- -v $($(TARGET)_SRC)
+
+clean:
+ rm -f *.o $(TARGET)
+ #rm -f *.pbm
+ #find -name "*.pgm" \! -regex ".*/affiche2?.pgm" -delete
+# DO NOT DELETE
\ No newline at end of file
Index: trunk/milena/sandbox/edwin/rush/leaves/configure
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/configure (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/configure (revision 3687)
@@ -0,0 +1,21 @@
+#! /bin/bash
+
+for arg in "$@"; do
+ if [ "$arg" == "--debug" ]; then
+ debug=1;
+ elif [ "$arg" == "--release" ]; then
+ release=1;
+ elif [ "${arg#--mln_dir=}" ]; then
+ MLN_DIR=${arg#--mln_dir=}
+ fi
+done
+
+rm -f makefile.rules
+touch makefile.rules
+if [ "$debug" ]; then
+ echo 'DEBUG = 1' >> makefile.rules
+fi
+if [ "$release" ]; then
+ echo 'RELEASE = 1' >> makefile.rules
+fi
+echo "MLN_DIR = $MLN_DIR" >> makefile.rules
\ No newline at end of file
Property changes on: trunk/milena/sandbox/edwin/rush/leaves/configure
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/leaves/get_leaves.cc
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/get_leaves.cc (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/get_leaves.cc (revision 3687)
@@ -0,0 +1,65 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/site_set/p_array.hh>
+
+#include <mln/level/sort_psites.hh>
+
+#include <mln/morpho/tree/data.hh>
+#include <mln/morpho/tree/compute_attribute_image.hh>
+#include "export_leaves.hh"
+
+#include <mln/morpho/attribute/sharpness.hh>
+
+#include <mln/io/pbm/save.hh>
+#include <mln/io/pgm/load.hh>
+
+#include <mln/value/int_u8.hh>
+
+#include <iostream>
+
+
+
+void usage(char** argv)
+{
+ std::cout << "Retrieve leaves of the component tree using sharpness"
+ << " attribute. It returns a binary image of leaves and creates"
+ << " txt file that contains nodes of the branch that the leaf belongs to."
+ << std::endl;
+ std::cout << "Usage: " << argv[0] << " input.pgm" << std::endl;
+ abort();
+}
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc == 0)
+ usage(argv);
+
+
+ // Load a pgm img (Gray level Or Gradient Image)
+ typedef image2d<int_u8> I;
+ I input;
+ io::pgm::load(input, argv[1]);
+
+ // Tree Creation
+ typedef p_array<point2d> S;
+ typedef morpho::tree::data<I,S> tree_t;
+ S s = level::sort_psites_decreasing(input);
+ tree_t t(input, s, c4());
+
+ // Attribute pruning.
+ typedef morpho::attribute::sharpness<I> sharp_t;
+ typedef mln_ch_value_(I, double) A;
+
+ A a = morpho::tree::compute_attribute_image(sharp_t (), t);
+
+
+ //Export Leaves
+ typedef mln_ch_value_(I, bool) B;
+ B b_img = export_leaves_to_img(t, a);
+ io::pbm::save(b_img, "leaves.pbm");
+ export_leaves_to_file(t, a);
+}
Index: trunk/milena/sandbox/edwin/rush/leaves/splot.sh
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/splot.sh (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/splot.sh (revision 3687)
@@ -0,0 +1,10 @@
+#! /bin/bash
+FILE=gplot.batch
+
+echo "set terminal png" > "$FILE"
+for f in *.txt; do
+ echo 'set output "'$f'.png"' >> "$FILE"
+ echo 'plot "'$f'"' >> "$FILE"
+done;
+
+gnuplot "$FILE"
\ No newline at end of file
Property changes on: trunk/milena/sandbox/edwin/rush/leaves/splot.sh
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/leaves/chain.sh
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/chain.sh (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/chain.sh (revision 3687)
@@ -0,0 +1,34 @@
+#! /bin/bash
+
+function usage()
+{
+echo "./chain.sh input.ppm (--graylevel | --gradient)"
+exit 2
+}
+
+if [ $# -ne 2 ]; then
+ usage
+fi
+
+if [ "$2" = "--gradient" ]; then
+ gradient=1
+elif [ "$2" = "--graylevel" ]; then
+ graylevel=1
+else
+ usage
+fi
+
+make leaves
+if [ "x$gradient" = "x1" ]; then
+ make all
+ name="gradient.pgm"
+ ./gradient "$1" "$name"
+else
+ name="$1"
+ name="${name%.ppm}.pgm"
+ convert +compress -depth 8 -colorspace Gray "$1" "$name"
+fi
+./leaves "$name"
+rm -Rf "$1".dir
+mkdir "$1".dir
+mv *.txt "leaves.pbm" "$name" "$1".dir
\ No newline at end of file
Property changes on: trunk/milena/sandbox/edwin/rush/leaves/chain.sh
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/leaves/Makefile
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/Makefile (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/Makefile (revision 3687)
@@ -0,0 +1,35 @@
+include makefile.rules
+
+
+OLENADIR=$(MLN_DIR)/..
+MILENADIR=$(MLN_DIR)
+
+CXXFLAGS = -I$(MILENADIR) -I./ -W -Wall
+CXXFLAGS += $(if $(DEBUG), -g -ggdb, -DNDEBUG\
+ $(if $(RELEASE), -O3, -O1))
+CXX=g++
+LD=g++
+LDFLAGS=
+SRC=
+
+
+GRADIENT_SRC = $(MLN_DIR)/sandbox/theo/exec/color_internal_gradient.cc
+LEAVES_SRC = get_leaves.cc
+
+
+all: leaves gradient
+
+
+leaves: $(LEAVES_SRC)
+ $(CXX) $(CXXFLAGS) $< -o leaves
+
+gradient: $(GRADIENT_SRC)
+ $(CXX) $(CXXFLAGS) $< -o gradient
+
+
+clean:
+ rm -f leaves gradient
+
+
+%.o: %.cc
+ $(CXX) $(CXXFLAGS) -c $<
\ No newline at end of file
Index: trunk/milena/sandbox/edwin/rush/leaves/export_leaves.hh
===================================================================
--- trunk/milena/sandbox/edwin/rush/leaves/export_leaves.hh (revision 0)
+++ trunk/milena/sandbox/edwin/rush/leaves/export_leaves.hh (revision 3687)
@@ -0,0 +1,115 @@
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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, 51 Franklin Street, Fifth Floor,
+// 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 EXPORT_LEAVES_HH_
+# define EXPORT_LEAVES_HH_
+
+# include <mln/core/concept/image.hh>
+
+# include <mln/morpho/tree/data.hh>
+# include "../../tree/propagate.hh"
+
+
+# include <mln/data/fill.hh>
+
+# include <fstream>
+# include <sstream>
+
+namespace mln {
+
+ template <typename T, typename A>
+ inline
+ void
+ export_leaves_to_file(const T& tree, const Image<A>& attr_image);
+
+ template <typename T, typename A>
+ inline
+ mln_ch_value(A, bool)
+ export_leaves_to_img(const T& tree, const Image<A>& attr_image);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename A>
+ inline
+ void
+ export_leaves_to_file(const T& tree, const Image<A>& attr_image)
+ {
+ mln_precondition(tree.f().domain() == attr_image.domain());
+
+ const A& a = exact(attr_image);
+ mln_leaf_piter(T) leaf(tree);
+
+ for_all(leaf)
+ {
+ std::stringstream fn;
+ for (int i = 0; i < leaf.dim; i++)
+ fn << "[" << leaf[i] << "]";
+ fn << ".txt";
+
+ std::ofstream out(fn.str().c_str());
+ mln_psite(T) n = leaf;
+ int i = 0;
+ while (!tree.is_root(n))
+ {
+ out << i++ << " " << a(n) << std::endl;
+ n = tree.parent(n);
+ }
+ out << i << " " << a(n) << std::endl;
+ }
+ }
+
+ template <typename T, typename A>
+ inline
+ mln_ch_value(A, bool)
+ export_leaves_to_img(const T& tree, const Image<A>& attr_image)
+ {
+ mln_precondition(tree.f().domain() == attr_image.domain());
+
+ typedef mln_ch_value(A, bool) I;
+ const A& a = exact(attr_image);
+
+ I output;
+ initialize(output, a);
+ data::fill(output, false);
+
+ mln_leaf_piter(T) l(tree);
+ for_all(l)
+ output(l) = true;
+
+ morpho::tree::propagate_representant(tree, output);
+ return output;
+ }
+
+
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+} // end of namespace mln
+
+#endif /* !EXPORT_LEAVES_HH_ */
Index: trunk/milena/sandbox/edwin/rush/exo2/configure
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/configure (revision 0)
+++ trunk/milena/sandbox/edwin/rush/exo2/configure (revision 3687)
@@ -0,0 +1,21 @@
+#! /bin/bash
+
+for arg in "$@"; do
+ if [ "$arg" == "--debug" ]; then
+ debug=1;
+ elif [ "$arg" == "--release" ]; then
+ release=1;
+ elif [ "${arg#--mln_dir=}" ]; then
+ MLN_DIR=${arg#--mln_dir=}
+ fi
+done
+
+rm -f makefile.rules
+touch makefile.rules
+if [ "$debug" ]; then
+ echo 'DEBUG = 1' >> makefile.rules
+fi
+if [ "$release" ]; then
+ echo 'RELEASE = 1' >> makefile.rules
+fi
+echo "MLN_DIR = $MLN_DIR" >> makefile.rules
\ No newline at end of file
Property changes on: trunk/milena/sandbox/edwin/rush/exo2/configure
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/exo2/wst_from_closing.cc
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/wst_from_closing.cc (revision 0)
+++ trunk/milena/sandbox/edwin/rush/exo2/wst_from_closing.cc (revision 3687)
@@ -0,0 +1,127 @@
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/value/label_16.hh>
+#include <mln/level/convert.hh>
+
+#include <mln/io/ppm/load.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/io/pgm/save.hh>
+
+#include "color_internal_gradient.hh"
+#include "color_labeling_mean.hh"
+#include <mln/morpho/closing/height.hh>
+#include <mln/morpho/watershed/all.hh>
+#include <mln/morpho/elementary/dilation.hh>
+
+
+#include <iostream>
+#include <string>
+
+
+void usage(char** argv)
+{
+ std::cout << "Usage: " << argv[0] << " input.ppm height [-o1 | -o2 | -o3]"
+ << std::endl
+ << "-o1\tSuperpose WS on input image (out: superpose.ppm)" << std::endl
+ << "-o2\tCount number of basins" << std::endl
+ << "-o3\tReplace basin by its mean color on the input (out: mean.ppm)"
+ << std::endl;
+ abort();
+}
+
+
+
+int main(int argc, char** argv)
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::int_u16;
+ using value::rgb8;
+
+ if (argc < 3)
+ usage(argv);
+
+ int output_ = 0;
+ int lambda_h = std::atoi(argv[2]);
+
+ if (argc == 4)
+ if (std::string(argv[3]) == "-o1")
+ output_ = 1;
+ else if (std::string(argv[3]) == "-o2")
+ output_ = 2;
+ else if (std::string(argv[3]) == "-o3")
+ output_ = 3;
+ else
+ usage(argv);
+
+
+
+ // Load color image.
+ typedef image2d<rgb8> I_;
+ I_ input_;
+ io::ppm::load(input_, argv[1]);
+
+ // Gradient.
+ typedef image2d<int_u8> I;
+ I input = color_internal_gradient(input_);
+
+ // Closing
+ std::cout << lambda_h << std::endl;
+ input = morpho::closing::height(input, c4(), lambda_h);
+
+ // Watershed
+ typedef image2d<int_u16> WST;
+ int_u16 n_basins = 0;
+ WST wst = morpho::watershed::flooding(input, c4(), n_basins);
+
+ if (!output_ || output_ == 1)
+ {
+ I_ out = morpho::watershed::superpose(input_, wst);
+ io::ppm::save(out, "superpose.pgm");
+ }
+
+ if (!output_ || output_ == 2)
+ std::cout << "Number of basins: " << n_basins << std::endl;
+
+ if (!output_ || output_ == 3)
+ {
+ typedef image2d<value::label_16> L;
+ L lab = level::convert(value::label_16(),
+ morpho::elementary::dilation(wst, c8()));
+ I_ out = color_labeling_mean(input_, lab, n_basins);
+ io::ppm::save(out, "mean.pgm");
+ }
+
+}
Index: trunk/milena/sandbox/edwin/rush/exo2/color_internal_gradient.hh
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/color_internal_gradient.hh (revision 0)
+++ trunk/milena/sandbox/edwin/rush/exo2/color_internal_gradient.hh (revision 3687)
@@ -0,0 +1,149 @@
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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, 51 Franklin Street, Fifth Floor,
+// 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 COLOR_INTERNAL_GRADIENT_HH_
+# define COLOR_INTERNAL_GRADIENT_HH_
+
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/morpho/elementary/gradient_internal.hh>
+#include <mln/math/diff_abs.hh>
+
+#include <mln/accu/image/init.hh>
+#include <mln/accu/image/take.hh>
+#include <mln/accu/image/to_result.hh>
+
+#include <mln/accu/max.hh>
+
+namespace mln
+{
+
+ value::int_u8
+ dist(const value::rgb8& c1,
+ const value::rgb8& c2)
+ {
+ unsigned d = 0;
+ d += math::diff_abs(c1.red(), c2.red());
+ d += math::diff_abs(c1.green(), c2.green());
+ d += math::diff_abs(c1.blue(), c2.blue());
+ if (d > 255)
+ d = 255;
+ return d;
+ }
+
+ template <typename N>
+ image2d<value::int_u8>
+ color_gradient(const image2d<value::rgb8>& input,
+ const N& nbh)
+ {
+ using value::int_u8;
+ image2d<int_u8> output(input.domain());
+
+ mln_piter(box2d) p(input.domain());
+ mln_niter(N) n(nbh, p);
+ for_all(p)
+ {
+ int_u8 d = 0u;
+ for_all(n) if (input.domain().has(n))
+ {
+ int_u8 d_ = dist(input(p), input(n));
+ if (d_ > d)
+ d = d_;
+ }
+ output(p) = d;
+ }
+
+ return output;
+ }
+
+
+
+ template <typename I>
+ image2d<value::int_u8>
+ get_red(const I& input)
+ {
+ typedef image2d<value::int_u8> J;
+ J output(input.domain());
+
+ mln_pixter(const I) p_in(input);
+ mln_pixter(J) p_out(output);
+ for_all_2(p_in, p_out)
+ p_out.val() = p_in.val().red();
+ return output;
+ }
+
+ template <typename I>
+ image2d<value::int_u8>
+ get_green(const I& input)
+ {
+ typedef image2d<value::int_u8> J;
+ J output(input.domain());
+
+ mln_pixter(const I) p_in(input);
+ mln_pixter(J) p_out(output);
+ for_all_2(p_in, p_out)
+ p_out.val() = p_in.val().green();
+ return output;
+ }
+
+ template <typename I>
+ image2d<value::int_u8>
+ get_blue(const I& input)
+ {
+ typedef image2d<value::int_u8> J;
+ J output(input.domain());
+
+ mln_pixter(const I) p_in(input);
+ mln_pixter(J) p_out(output);
+ for_all_2(p_in, p_out)
+ p_out.val() = p_in.val().blue();
+ return output;
+ }
+
+ image2d<value::int_u8>
+ color_internal_gradient(const image2d<value::rgb8>& input)
+ {
+ typedef accu::max< value::int_u8 > A;
+ image2d<A> grad(input.domain());
+
+ using morpho::elementary::gradient_internal;
+
+ accu::image::init(grad);
+
+ accu::image::take(grad,
+ gradient_internal(get_red(input), c4()));
+ accu::image::take(grad,
+ gradient_internal(get_green(input), c4()));
+ accu::image::take(grad,
+ gradient_internal(get_blue(input), c4()));
+
+ return accu::image::to_result(grad);
+ }
+
+} // mln
+
+#endif /* !COLOR_INTERNAL_GRADIENT_HH_ */
Index: trunk/milena/sandbox/edwin/rush/exo2/color_labeling_mean.hh
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/color_labeling_mean.hh (revision 0)
+++ trunk/milena/sandbox/edwin/rush/exo2/color_labeling_mean.hh (revision 3687)
@@ -0,0 +1,70 @@
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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, 51 Franklin Street, Fifth Floor,
+// 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 COLOR_LABELING_MEAN_HH_
+# define COLOR_LABELING_MEAN_HH_
+
+# include <mln/core/image/image2d.hh>
+
+# include <mln/labeling/compute.hh>
+# include <mln/accu/mean.hh>
+# include <mln/level/transform.hh>
+
+# include <mln/value/label_8.hh>
+# include <mln/value/int_u16.hh>
+
+namespace mln {
+
+ template <typename L>
+ image2d< value::rgb8 >
+ color_labeling_mean(const image2d< value::rgb8>& input,
+ const Image<L>& label,
+ unsigned nlabels)
+ {
+ using value::rgb8;
+ typedef algebra::vec<3,float> V;
+
+ accu::mean<value::rgb8> m_;
+ util::array<V> m = labeling::compute(m_, input, exact(label), nlabels);
+
+ util::array<rgb8> c(unsigned(nlabels) + 1);
+
+ c[0] = rgb8(0,0,0);
+ for (unsigned l = 1; l <= nlabels; ++l)
+ {
+ c[l].red() = m[l][0];
+ c[l].green() = m[l][1];
+ c[l].blue() = m[l][2];
+ }
+
+ return level::transform(label, c);
+ }
+
+} // mln
+
+#endif /* !COLOR_LABELING_MEAN_HH_ */
Index: trunk/milena/sandbox/edwin/rush/exo2/Makefile
===================================================================
--- trunk/milena/sandbox/edwin/rush/exo2/Makefile (revision 0)
+++ trunk/milena/sandbox/edwin/rush/exo2/Makefile (revision 3687)
@@ -0,0 +1,29 @@
+include makefile.rules
+
+
+OLENADIR=$(MLN_DIR)/..
+MILENADIR=$(MLN_DIR)
+
+CXXFLAGS = -I$(MILENADIR) -I./ -W -Wall
+CXXFLAGS += $(if $(DEBUG), -g -ggdb, -DNDEBUG\
+ $(if $(RELEASE), -O3, -O1))
+CXX=g++
+LD=g++
+LDFLAGS=
+SRC=
+
+OUT_IMG=superpose.pgm mean.pgm gradient.pgm closing.pgm
+
+all: wst_from_closing
+
+%: %.cc
+ $(CXX) $(CXXFLAGS) $< -o $@
+
+
+clean:
+ rm -f $(OUT_IMG)
+ rm -f wst_from_closing
+
+
+%.o: %.cc
+ $(CXX) $(CXXFLAGS) -c $<
\ No newline at end of file
1
0
18 Apr '09
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-04-19 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Routines to export leaves toward several representation.
* edwin/rush/Makefile: New.
* edwin/rush/chain.sh: Script that handles process.
* edwin/rush/configure: New.
* edwin/rush/export_leaves.hh: Leaves exportation methods.
* edwin/rush/get_leaves.cc: Process file that import pgm image,
creates tree, applies an attribute and export the leaves.
* edwin/rush/splot.sh: New file to autogenerate gnuplot graphics.
* edwin/rush/test/Makefile: New.
* edwin/rush/test/configure: New.
* edwin/rush/test/export.cc: Test file for routines.
* edwin/rush/test: New test folder.
* edwin/rush: New.
* edwin/tree/propagate.hh: Add missing include.
---
rush/Makefile | 35 +++++++++++++++
rush/chain.sh | 34 ++++++++++++++
rush/configure | 21 +++++++++
rush/export_leaves.hh | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++
rush/get_leaves.cc | 65 ++++++++++++++++++++++++++++
rush/splot.sh | 10 ++++
rush/test/Makefile | 41 +++++++++++++++++
rush/test/configure | 21 +++++++++
rush/test/export.cc | 63 +++++++++++++++++++++++++++
tree/propagate.hh | 1
10 files changed, 406 insertions(+)
Index: trunk/milena/sandbox/edwin/tree/propagate.hh
===================================================================
--- trunk/milena/sandbox/edwin/tree/propagate.hh (revision 3685)
+++ trunk/milena/sandbox/edwin/tree/propagate.hh (revision 3686)
@@ -33,6 +33,7 @@
/// Functions to propagate a node value in the tree.
#include <mln/morpho/tree/data.hh>
+# include "propagate_node.hh"
namespace mln {
namespace morpho {
Index: trunk/milena/sandbox/edwin/rush/test/configure
===================================================================
--- trunk/milena/sandbox/edwin/rush/test/configure (revision 0)
+++ trunk/milena/sandbox/edwin/rush/test/configure (revision 3686)
@@ -0,0 +1,21 @@
+#! /bin/bash
+
+for arg in "$@"; do
+ if [ "$arg" == "--debug" ]; then
+ debug=1;
+ elif [ "$arg" == "--release" ]; then
+ release=1;
+ elif [ "${arg#--mln_dir=}" ]; then
+ MLN_DIR=${arg#--mln_dir=}
+ fi
+done
+
+rm -f makefile.rules
+touch makefile.rules
+if [ "$debug" ]; then
+ echo 'DEBUG = 1' >> makefile.rules
+fi
+if [ "$release" ]; then
+ echo 'RELEASE = 1' >> makefile.rules
+fi
+echo "MLN_DIR = $MLN_DIR" >> makefile.rules
\ No newline at end of file
Property changes on: trunk/milena/sandbox/edwin/rush/test/configure
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/test/export.cc
===================================================================
--- trunk/milena/sandbox/edwin/rush/test/export.cc (revision 0)
+++ trunk/milena/sandbox/edwin/rush/test/export.cc (revision 3686)
@@ -0,0 +1,63 @@
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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, 51 Franklin Street, Fifth Floor,
+// 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.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/site_set/p_array.hh>
+
+#include <mln/level/sort_psites.hh>
+
+#include <mln/morpho/tree/data.hh>
+#include "../export_leaves.hh"
+
+#include <mln/io/pbm/save.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d<int> I;
+ typedef p_array<point2d> S;
+ typedef morpho::tree::data<I,S> tree_t;
+
+ int vals[] = {3, 3, 4,
+ 3, 5, 4,
+ 4, 4, 4 };
+
+ I ima = make::image2d(vals);
+ S s = level::sort_psites_decreasing(ima);
+ tree_t t(ima, s, c4());
+
+ export_leaves_to_file(t, ima);
+
+ typedef mln_ch_value_(I, bool) B;
+ B b_img = export_leaves_to_img(t, ima);
+
+ io::pbm::save(b_img, "leaves.pbm");
+}
Index: trunk/milena/sandbox/edwin/rush/test/Makefile
===================================================================
--- trunk/milena/sandbox/edwin/rush/test/Makefile (revision 0)
+++ trunk/milena/sandbox/edwin/rush/test/Makefile (revision 3686)
@@ -0,0 +1,41 @@
+include makefile.rules
+TARGET=export
+#sharp_SRC=sharp.cc
+#sharp_OBJS=${sharp_SRC:.cc=.o}
+
+export_SRC=export.cc
+export_OBJS=${export_SRC:.cc=.o}
+
+OLENADIR=$(MLN_DIR)/..
+MILENADIR=$(MLN_DIR)
+
+CXXFLAGS=-I$(MILENADIR) -I./ -W -Wall
+
+
+CXXFLAGS += $(if $(DEBUG), -g -ggdb, -DNDEBUG\
+ $(if $(RELEASE), -O3, -O1))
+
+CXX=g++
+LD=g++
+LDFLAGS=
+
+all: $(TARGET)
+
+
+$(TARGET): $($(TARGET)_OBJS) $($(TARGET)_SRC)
+ $(LD) $(LDFLAGS) -o $@ $($(TARGET)_OBJS)
+
+%.o: %.cc
+ $(CXX) $(CXXFLAGS) -c $<
+
+%.o: %.hh
+ $(CXX) $(CXXFLAGS) -c $<
+
+depend:
+ makedepend -- $(CXXFLAGS) -- -v $($(TARGET)_SRC)
+
+clean:
+ rm -f *.o $(TARGET)
+ #rm -f *.pbm
+ #find -name "*.pgm" \! -regex ".*/affiche2?.pgm" -delete
+# DO NOT DELETE
\ No newline at end of file
Index: trunk/milena/sandbox/edwin/rush/configure
===================================================================
--- trunk/milena/sandbox/edwin/rush/configure (revision 0)
+++ trunk/milena/sandbox/edwin/rush/configure (revision 3686)
@@ -0,0 +1,21 @@
+#! /bin/bash
+
+for arg in "$@"; do
+ if [ "$arg" == "--debug" ]; then
+ debug=1;
+ elif [ "$arg" == "--release" ]; then
+ release=1;
+ elif [ "${arg#--mln_dir=}" ]; then
+ MLN_DIR=${arg#--mln_dir=}
+ fi
+done
+
+rm -f makefile.rules
+touch makefile.rules
+if [ "$debug" ]; then
+ echo 'DEBUG = 1' >> makefile.rules
+fi
+if [ "$release" ]; then
+ echo 'RELEASE = 1' >> makefile.rules
+fi
+echo "MLN_DIR = $MLN_DIR" >> makefile.rules
\ No newline at end of file
Property changes on: trunk/milena/sandbox/edwin/rush/configure
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/get_leaves.cc
===================================================================
--- trunk/milena/sandbox/edwin/rush/get_leaves.cc (revision 0)
+++ trunk/milena/sandbox/edwin/rush/get_leaves.cc (revision 3686)
@@ -0,0 +1,65 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/site_set/p_array.hh>
+
+#include <mln/level/sort_psites.hh>
+
+#include <mln/morpho/tree/data.hh>
+#include <mln/morpho/tree/compute_attribute_image.hh>
+#include "export_leaves.hh"
+
+#include <mln/morpho/attribute/sharpness.hh>
+
+#include <mln/io/pbm/save.hh>
+#include <mln/io/pgm/load.hh>
+
+#include <mln/value/int_u8.hh>
+
+#include <iostream>
+
+
+
+void usage(char** argv)
+{
+ std::cout << "Retrieve leaves of the component tree using sharpness"
+ << " attribute. It returns a binary image of leaves and creates"
+ << " txt file that contains nodes of the branch that the leaf belongs to."
+ << std::endl;
+ std::cout << "Usage: " << argv[0] << " input.pgm" << std::endl;
+ abort();
+}
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc == 0)
+ usage(argv);
+
+
+ // Load a pgm img (Gray level Or Gradient Image)
+ typedef image2d<int_u8> I;
+ I input;
+ io::pgm::load(input, argv[1]);
+
+ // Tree Creation
+ typedef p_array<point2d> S;
+ typedef morpho::tree::data<I,S> tree_t;
+ S s = level::sort_psites_decreasing(input);
+ tree_t t(input, s, c4());
+
+ // Attribute pruning.
+ typedef morpho::attribute::sharpness<I> sharp_t;
+ typedef mln_ch_value_(I, double) A;
+
+ A a = morpho::tree::compute_attribute_image(sharp_t (), t);
+
+
+ //Export Leaves
+ typedef mln_ch_value_(I, bool) B;
+ B b_img = export_leaves_to_img(t, a);
+ io::pbm::save(b_img, "leaves.pbm");
+ export_leaves_to_file(t, a);
+}
Index: trunk/milena/sandbox/edwin/rush/splot.sh
===================================================================
--- trunk/milena/sandbox/edwin/rush/splot.sh (revision 0)
+++ trunk/milena/sandbox/edwin/rush/splot.sh (revision 3686)
@@ -0,0 +1,10 @@
+#! /bin/bash
+FILE=gplot.batch
+
+echo "set terminal png" > "$FILE"
+for f in *.txt; do
+ echo 'set output "'$f'.png"' >> "$FILE"
+ echo 'plot "'$f'"' >> "$FILE"
+done;
+
+gnuplot "$FILE"
\ No newline at end of file
Property changes on: trunk/milena/sandbox/edwin/rush/splot.sh
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/chain.sh
===================================================================
--- trunk/milena/sandbox/edwin/rush/chain.sh (revision 0)
+++ trunk/milena/sandbox/edwin/rush/chain.sh (revision 3686)
@@ -0,0 +1,34 @@
+#! /bin/bash
+
+function usage()
+{
+echo "./chain.sh input.ppm (--graylevel | --gradient)"
+exit 2
+}
+
+if [ $# -ne 2 ]; then
+ usage
+fi
+
+if [ "$2" = "--gradient" ]; then
+ gradient=1
+elif [ "$2" = "--graylevel" ]; then
+ graylevel=1
+else
+ usage
+fi
+
+make leaves
+if [ "x$gradient" = "x1" ]; then
+ make all
+ name="gradient.pgm"
+ ./gradient "$1" "$name"
+else
+ name="$1"
+ name="${name%.ppm}.pgm"
+ convert +compress -depth 8 -colorspace Gray "$1" "$name"
+fi
+./leaves "$name"
+rm -Rf "$1".dir
+mkdir "$1".dir
+mv *.txt "leaves.pbm" "$name" "$1".dir
\ No newline at end of file
Property changes on: trunk/milena/sandbox/edwin/rush/chain.sh
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/edwin/rush/Makefile
===================================================================
--- trunk/milena/sandbox/edwin/rush/Makefile (revision 0)
+++ trunk/milena/sandbox/edwin/rush/Makefile (revision 3686)
@@ -0,0 +1,35 @@
+include makefile.rules
+
+
+OLENADIR=$(MLN_DIR)/..
+MILENADIR=$(MLN_DIR)
+
+CXXFLAGS = -I$(MILENADIR) -I./ -W -Wall
+CXXFLAGS += $(if $(DEBUG), -g -ggdb, -DNDEBUG\
+ $(if $(RELEASE), -O3, -O1))
+CXX=g++
+LD=g++
+LDFLAGS=
+SRC=
+
+
+GRADIENT_SRC = $(MLN_DIR)/sandbox/theo/exec/color_internal_gradient.cc
+LEAVES_SRC = get_leaves.cc
+
+
+all: leaves gradient
+
+
+leaves: $(LEAVES_SRC)
+ $(CXX) $(CXXFLAGS) $< -o leaves
+
+gradient: $(GRADIENT_SRC)
+ $(CXX) $(CXXFLAGS) $< -o gradient
+
+
+clean:
+ rm -f leaves gradient
+
+
+%.o: %.cc
+ $(CXX) $(CXXFLAGS) -c $<
\ No newline at end of file
Index: trunk/milena/sandbox/edwin/rush/export_leaves.hh
===================================================================
--- trunk/milena/sandbox/edwin/rush/export_leaves.hh (revision 0)
+++ trunk/milena/sandbox/edwin/rush/export_leaves.hh (revision 3686)
@@ -0,0 +1,115 @@
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// 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, 51 Franklin Street, Fifth Floor,
+// 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 EXPORT_LEAVES_HH_
+# define EXPORT_LEAVES_HH_
+
+# include <mln/core/concept/image.hh>
+
+# include <mln/morpho/tree/data.hh>
+# include "../tree/propagate.hh"
+
+
+# include <mln/data/fill.hh>
+
+# include <fstream>
+# include <sstream>
+
+namespace mln {
+
+ template <typename T, typename A>
+ inline
+ void
+ export_leaves_to_file(const T& tree, const Image<A>& attr_image);
+
+ template <typename T, typename A>
+ inline
+ mln_ch_value(A, bool)
+ export_leaves_to_img(const T& tree, const Image<A>& attr_image);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename A>
+ inline
+ void
+ export_leaves_to_file(const T& tree, const Image<A>& attr_image)
+ {
+ mln_precondition(tree.f().domain() == attr_image.domain());
+
+ const A& a = exact(attr_image);
+ mln_leaf_piter(T) leaf(tree);
+
+ for_all(leaf)
+ {
+ std::stringstream fn;
+ for (int i = 0; i < leaf.dim; i++)
+ fn << "[" << leaf[i] << "]";
+ fn << ".txt";
+
+ std::ofstream out(fn.str().c_str());
+ mln_psite(T) n = leaf;
+ int i = 0;
+ while (!tree.is_root(n))
+ {
+ out << i++ << " " << a(n) << std::endl;
+ n = tree.parent(n);
+ }
+ out << i << " " << a(n) << std::endl;
+ }
+ }
+
+ template <typename T, typename A>
+ inline
+ mln_ch_value(A, bool)
+ export_leaves_to_img(const T& tree, const Image<A>& attr_image)
+ {
+ mln_precondition(tree.f().domain() == attr_image.domain());
+
+ typedef mln_ch_value(A, bool) I;
+ const A& a = exact(attr_image);
+
+ I output;
+ initialize(output, a);
+ data::fill(output, false);
+
+ mln_leaf_piter(T) l(tree);
+ for_all(l)
+ output(l) = true;
+
+ morpho::tree::propagate_representant(tree, output);
+ return output;
+ }
+
+
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+} // end of namespace mln
+
+#endif /* !EXPORT_LEAVES_HH_ */
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Update src of 'color labeling mean'.
* theo/exec/color_labeling_mean.cc: Update.
color_labeling_mean.cc | 36 +++++++++++++++++++++++++++---------
1 file changed, 27 insertions(+), 9 deletions(-)
Index: theo/exec/color_labeling_mean.cc
--- theo/exec/color_labeling_mean.cc (revision 3684)
+++ theo/exec/color_labeling_mean.cc (working copy)
@@ -6,6 +6,8 @@
#include <mln/level/transform.hh>
#include <mln/value/label_8.hh>
+#include <mln/value/int_u16.hh>
+#include <mln/level/convert.hh>
#include <mln/io/pgm/load.hh>
#include <mln/io/ppm/load.hh>
@@ -13,32 +15,48 @@
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.ppm label.pgm output.pgm" << std::endl
+ << " Replace every label by its mean color value." << std::endl;
+ std::abort();
+}
int main(int argc, char* argv[])
{
using namespace mln;
using value::int_u8;
+ using value::int_u16;
using value::label_8;
using value::rgb8;
+ if (argc != 4)
+ usage(argv);
+
+
+ image2d<rgb8> ima;
+ io::ppm::load(ima, argv[1]);
+
+
image2d<int_u8> lab;
- io::pgm::load(lab, argv[1]);
+ io::pgm::load(lab, argv[2]);
- int_u8 min, nlabels;
- estim::min_max(lab, min, nlabels);
+ image2d<int_u16> lab_ = level::convert(int_u16(), lab);
- std::cout << min << ' ' << nlabels << std::endl;
+ int_u16 min, nlabels;
+ estim::min_max(lab_, min, nlabels);
- image2d<rgb8> ima;
- io::ppm::load(ima, argv[2]);
+ std::cout << "n labels = " << nlabels << std::endl;
accu::mean<rgb8> m_;
typedef algebra::vec<3,float> V;
- util::array<V> m = labeling::compute(m_, ima, lab, nlabels);
+ util::array<V> m = labeling::compute(m_, ima, lab_, nlabels);
+
+ util::array<rgb8> c(unsigned(nlabels) + 1);
- util::array<rgb8> c(nlabels + 1);
- for (unsigned l = 0; l <= nlabels; ++l)
+ c[0] = rgb8(0,0,0);
+ for (unsigned l = 1; l <= nlabels; ++l)
{
c[l].red() = m[l][0];
c[l].green() = m[l][1];
1
0
Re: [Olena-patches] [Olena] #3: Migrate Olena 0.11 (and previous revisions) from PRCS to Git (was: Migrate Olena 0.11 (and previous revisions) from PRCS to Subversion)
by Olena Trac 17 Apr '09
by Olena Trac 17 Apr '09
17 Apr '09
#3: Migrate Olena 0.11 (and previous revisions) from PRCS to Git
--------------------------+-------------------------------------------------
Reporter: levill_r | Owner: levill_r
Type: enhancement | Status: reopened
Priority: blocker | Milestone: Olena 0.11.1
Component: other | Version: 0.11
Resolution: | Keywords: prcs subversion svn git
--------------------------+-------------------------------------------------
Changes (by levill_r):
* keywords: prcs subversion svn => prcs subversion svn git
* status: closed => reopened
* resolution: wontfix =>
Old description:
> '''No further development should be done on the 0.11 branch until this
> task is either fixed or removed.'''
>
> This task is an open discussion. I haven't much tried to convert the
> PRCS Olena repository to a Subversion one, and I think it '''is''' really
> feasible, though not trivial. If you're interested in this migration,
> please ask me (Roland) first before making actual changes to the PRCS or
> the SVN repository.
New description:
Use `prcs2git` (http://takaki-web.media-as.org/my_works/prcs2git) to
convert the old PRCS revisions of Olena to Git.
I (Roland) made an attempt and successfully converted the whole repository
(minus two bogus revisions, namely 10.138 and 10.139) by using it.
However there is room for improvement:
* ignoring revisions is not possible (there should be an option taking an
ignore pattern as argument)
* information about author and committer (name, e-mail, date) is not
propagated;
* log title (short messages) are filled with PRCS metadata (ugly!) ; we
should retrieve the title from somewhere (PRCS, the !ChangeLog(s) or even
the mailing list);
* log messages are meaningless.
Branches, however, have been well translated.
'''Remember that no further development should be done on the 0.11 branch
until this task is either fixed or removed.'''
--
Comment:
s/Subversion/Git/.
--
Ticket URL: <https://trac.lrde.org/olena/ticket/3#comment:8>
Olena <http://olena.lrde.epita.fr>
Olena, a generic and efficient C++ image processing library.
1
0
milena r3684: Remove check save + modification in compute attribute method
by Edwin Carlinet 17 Apr '09
by Edwin Carlinet 17 Apr '09
17 Apr '09
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-04-17 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Remove check save + modification in compute attribute method.
* mln/io/pgm/save.hh: Remove static check unit_8 while saving pgm.
* mln/morpho/tree/compute_attribute_image.hh: Add extra
argument where the accumulator image will be store.
---
io/pgm/save.hh | 3 -
morpho/tree/compute_attribute_image.hh | 57 ++++++++++++++++++++++-----------
2 files changed, 38 insertions(+), 22 deletions(-)
Index: trunk/milena/mln/morpho/tree/compute_attribute_image.hh
===================================================================
--- trunk/milena/mln/morpho/tree/compute_attribute_image.hh (revision 3683)
+++ trunk/milena/mln/morpho/tree/compute_attribute_image.hh (revision 3684)
@@ -35,6 +35,7 @@
///
/// \todo Specialize for low quant (and try fastest).
+# include <mln/core/routine/duplicate.hh>
# include <mln/core/concept/image.hh>
# include <mln/morpho/tree/data.hh>
# include <mln/trait/accumulators.hh>
@@ -42,7 +43,6 @@
# include <mln/data/fill.hh>
-
namespace mln
{
@@ -52,25 +52,38 @@
namespace tree
{
- /// Compute a tree with a parent relationship between sites.
- ///
- /// Warning: \p s translates the ordering related to the
- /// "natural" childhood relationship. The parenthood is thus
- /// inverted w.r.t. to \p s.
- ///
- /// It is very convenient since all processing upon the parent
- /// tree are performed following \p s (in the default "forward"
- /// way).
- ///
- /// FIXME: Put it more clearly...
- ///
- /// The parent result image verifies: \n
- /// - p is root iff parent(p) == p \n
- /// - p is a node iff either p is root or f(parent(p)) != f(p).
-
+ /**
+ ** Compute an attribute image using tree with a parent
+ ** relationship between sites. In the attribute image, the
+ ** resulting value at a node is the 'sum' of its sub-components
+ ** value + the attribute value at this node.
+ **
+ ** Warning: \p s translates the ordering related to the
+ ** "natural" childhood relationship. The parenthood is thus
+ ** inverted w.r.t. to \p s.
+ **
+ ** It is very convenient since all processing upon the parent
+ ** tree are performed following \p s (in the default "forward"
+ ** way).
+ **
+ ** FIXME: Put it more clearly...
+ **
+ ** The parent result image verifies: \n
+ ** - p is root iff parent(p) == p \n
+ ** - p is a node iff either p is root or f(parent(p)) != f(p).
+ **
+ ** @param[in] a Attribute.
+ ** @param[in] t Component tree.
+ ** @param[out] accu_image Optional argument used to store image
+ ** of attribute accumulator.
+ **
+ ** @return The attribute image.
+ */
template <typename A, typename T>
mln_ch_value(typename T::function, mln_result(A))
- compute_attribute_image(const Accumulator<A>& a, const T& t);
+ compute_attribute_image(const Accumulator<A>& a,
+ const T& t,
+ mln_ch_value(typename T::function, A)* accu_image = 0);
@@ -121,7 +134,9 @@
template <typename A, typename T>
inline
mln_ch_value(typename T::function, mln_result(A))
- compute_attribute_image(const Accumulator<A>& a_, const T& t)
+ compute_attribute_image(const Accumulator<A>& a_,
+ const T& t,
+ mln_ch_value(typename T::function, A)* accu_image = 0)
{
trace::entering("morpho::tree::compute_attribute_image");
@@ -161,6 +176,10 @@
}
}
+ // Store accumulator image.
+ if (accu_image)
+ *accu_image = duplicate(acc);
+
typedef typename T::function I;
mln_ch_value(I, mln_result(A)) output;
initialize(output, acc);
Index: trunk/milena/mln/io/pgm/save.hh
===================================================================
--- trunk/milena/mln/io/pgm/save.hh (revision 3683)
+++ trunk/milena/mln/io/pgm/save.hh (revision 3684)
@@ -82,9 +82,6 @@
// FIXME: Is it exhaustive?
mlc_is_not_a(mln_value(I), value::Vectorial)::check();
mlc_converts_to(mln_value(I),unsigned)::check();
- /// Make sure this is a low quantification value type
- /// (mln_card returns 0 if it is not)
- metal::bool_<mln_card(mln_value(I)) != 0>::check();
trace::entering("mln::io::pgm::save");
io::pnm::save(PGM, exact(ima), filename);
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-04-17 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Add labeling output and add doc.
* edwin/tree/components.hh,
* edwin/tree/propagate.hh,
* edwin/tree/propagate_node.hh: Clean and add documentation.
* edwin/tree/sharp.cc: Add labeling and benchmark.
---
components.hh | 43 +++++++++++++++++++++++++++++--
propagate.hh | 25 +++++++++++++++++-
propagate_node.hh | 4 +-
sharp.cc | 74 +++++++++++++++++++++++++++---------------------------
4 files changed, 103 insertions(+), 43 deletions(-)
Index: trunk/milena/sandbox/edwin/tree/propagate.hh
===================================================================
--- trunk/milena/sandbox/edwin/tree/propagate.hh (revision 3682)
+++ trunk/milena/sandbox/edwin/tree/propagate.hh (revision 3683)
@@ -71,7 +71,7 @@
*/
template <typename A, typename T>
inline
- A set_value_to_components(const Image<A>& attr_image,
+ A propagate_components(const Image<A>& attr_image,
const T& tree,
const p_array< mln_psite(A) >& component_list,
const mln_value(A)& null)
@@ -91,6 +91,29 @@
return out;
}
+
+ template <typename T, typename V>
+ inline
+ mln_ch_value(typename T::function, V)
+ set_value_to_components(const T& tree,
+ const p_array< mln_psite(T) >& component_list,
+ const V& value,
+ const V& null)
+ {
+ mln_ch_value(typename T::function, V) out;
+ initialize(out, tree.f());
+ data::fill(out, null);
+
+ mln_piter(p_array< mln_psite(T) >) p(component_list);
+ for_all(p)
+ {
+ out(p) = value;
+ morpho::tree::propagate_node_to_descendants(p, tree, out);
+ }
+ morpho::tree::propagate_representant(tree, out);
+ return out;
+ }
+
} // end of namespace mln::morpho::tree
} // end of namespace mln::morpho
} // end of namespace mln
Index: trunk/milena/sandbox/edwin/tree/sharp.cc
===================================================================
--- trunk/milena/sandbox/edwin/tree/sharp.cc (revision 3682)
+++ trunk/milena/sandbox/edwin/tree/sharp.cc (revision 3683)
@@ -30,10 +30,15 @@
#include <mln/pw/all.hh>
/* level */
-#include <mln/level/stretch.hh>
+//#include <mln/level/stretch.hh>
+
+/* label */
+#include <mln/labeling/blobs.hh>
+#include <mln/value/label_16.hh>
/* trace */
#include <mln/trace/quiet.hh>
+#include <mln/util/timer.hh>
/* std */
#include <string>
@@ -49,12 +54,14 @@
abort();
}
-void dsp(const std::string& str)
+void dsp(const std::string& str, mln::util::timer& timer)
{
+ std::cout << "in " << timer.read() << std::endl;
std::cout << std::endl
<< "*********************" << std::endl
<< "** " << str << std::endl
<< "*********************" << std::endl;
+ timer.restart();
}
namespace mln
@@ -170,6 +177,7 @@
unsigned card = 0;
unsigned height = 0;
double sharpness = 0;
+ util::timer timer;
if (argc < 2)
usage(argv);
@@ -195,9 +203,8 @@
/********************/
/* Load & Pre-treat */
/********************/
-
if (mydebug)
- dsp("Load & Pre-treat");
+ dsp("Load & Pre-treat", timer);
typedef image2d<int_u8> I;
I input;
@@ -208,7 +215,7 @@
/***************************/
if (mydebug)
- dsp("Component tree creation");
+ dsp("Component tree creation", timer);
typedef p_array< mln_site_(I) > S;
typedef morpho::tree::data<I,S> tree_t;
@@ -221,7 +228,7 @@
/* Compute Attribute On Image */
/******************************/
if (mydebug)
- dsp("Image sharp attribute");
+ dsp("Image sharp attribute", timer);
// TODO: l'attribut devrait favoriser les composantes plus larges
// dans son calcul. Ainsi au lieu de faire un sharpness, on aurait
@@ -251,7 +258,7 @@
if (card)
{
if (mydebug)
- dsp("Image card attribute");
+ dsp("Image card attribute", timer);
a = duplicate((fun::p2v::ternary(card_wrapper(pw::value(a_img)) > pw::cst(card),
pw::value(a),
@@ -261,7 +268,7 @@
if (height)
{
if (mydebug)
- dsp("Image height attribute");
+ dsp("Image height attribute", timer);
a = duplicate((fun::p2v::ternary(height_wrapper(pw::value(a_img)) > pw::cst(height),
pw::value(a),
pw::cst(0.0))) | a.domain());
@@ -271,7 +278,6 @@
/* Retrieve Components (Maximising the criteria) */
/************************************************/
- accumulator::arg_max<A> argmax(a);
p_array< mln_psite_(A) > obj_array; // Array of object components.
if (mydebug) {
@@ -283,7 +289,7 @@
s << "components whose treshold > " << sharpness;
else
s << "components util leaves are glutted";
- dsp(s.str());
+ dsp(s.str(), timer);
}
if (nb_components) {
@@ -297,48 +303,42 @@
/* Print them */
- if (mydebug) {
- dsp("Image Filtered Components");
- mln_fwd_piter_(p_array< mln_psite_(I) >) c(obj_array);
- for_all(c)
- std::cout << c;
- }
+// if (mydebug) {
+// mln_fwd_piter_(p_array< mln_psite_(I) >) c(obj_array);
+// for_all(c)
+// std::cout << c;
+// }
/***********************************/
/* Use components in output image */
/***********************************/
if (mydebug) {
- dsp("Create mask and propagate");
+ dsp("Propagate components and stretch", timer);
}
// Note: now we must propagate the representant value to the other components sites.
- A pre_output = morpho::tree::set_value_to_components(a, tree, obj_array, 0);
- I output = level::stretch(int_u8(), pre_output); //adapt to 0-255
- io::pgm::save(output, "components.pgm");
+
+ //a = morpho::tree::propagate_components(a, tree, obj_array, 0);
+ //I output = level::stretch(int_u8(), a); //adapt to 0-255
+ //io::pgm::save(output, "components.pgm");
/* EXTRA */
-// typedef mln_ch_value_(I, bool) M;
-// M mask;
-// initialize(mask, a);
-// data::fill(mask, false);
+ // labeling
+ typedef mln_ch_value_(I, bool) M;
+ typedef mln_ch_value_(I, value::label<16>) L;
+
+ M mask = morpho::tree::set_value_to_components(tree, obj_array, true, false);
+ value::label<16> nlabel;
+ L label = labeling::blobs(mask, c4(), nlabel);
+ io::pgm::save(label, "label.pgm");
-// mln_fwd_piter_(p_array< mln_psite_(I) >) c(obj_array);
-// for_all(c)
-// {
-// mask(c) = true;
-// propagate_node_to_descendants(c, tree, mask);
-// }
+ if (mydebug) {
+ dsp("Finish", timer);
+ }
- // mask now contains all nodes related to objects
-
- // /* Labeling */
-// typedef mln_ch_value_(I, value::label<8>) L;
-// value::label<8> nlabel;
-// L label = labeling::blobs(mask, c4(), nlabel);
-// io::ppm::save(debug::colorize(value::rgb8(), label, nlabel), "label.pgm");
// /* Now store output image */
Index: trunk/milena/sandbox/edwin/tree/components.hh
===================================================================
--- trunk/milena/sandbox/edwin/tree/components.hh (revision 3682)
+++ trunk/milena/sandbox/edwin/tree/components.hh (revision 3683)
@@ -26,8 +26,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef COMPONENTS_HH_
-# define COMPONENTS_HH_
+#ifndef MLN_MORPHO_TREE_COMPONENTS_HH_
+# define MLN_MORPHO_TREE_COMPONENTS_HH_
# include <mln/core/concept/image.hh>
# include <mln/core/concept/function.hh>
@@ -40,19 +40,56 @@
# include <mln/trace/exiting.hh>
+/**
+** \file mln/morpho/tree/components.hh
+**
+** Routines that offers different way of retrieving tree components.
+** Tree components are nodes maximising the attribute.
+*/
+
namespace mln {
namespace morpho {
namespace tree {
+ /**
+ ** Retrieve components from the tree until all leaves belong to
+ ** components.
+ **
+ ** @param tree Component tree.
+ ** @param attr_image Attribute image.
+ **
+ ** @return Array of components.
+ */
template <typename T, typename A>
p_array< mln_psite(A) >
get_components(const T& tree, const Image<A>& attr_image);
+ /**
+ ** Retrieve the \p n most important components from the tree. n
+ ** should be lesser than the maximum number of components. If
+ ** not, the functions stops when there's no more components.
+ **
+ ** @param tree Component tree.
+ ** @param attr_image Attribute image.
+ ** @param n Number of components to get.
+ **
+ ** @return Array of components.
+ */
template <typename T, typename A>
p_array< mln_psite(A) >
get_components(const T& tree, const Image<A>& attr_image, unsigned n);
+ /**
+ ** Retrieve the most important components that check
+ ** predicate \p pred.
+ **
+ ** @param tree Component tree.
+ ** @param attr_image Attribute image.
+ ** @param pred Predicate that components must check.
+ **
+ ** @return Array of components.
+ */
template <typename T, typename A, typename P2B>
p_array< mln_psite(A) >
get_components(const T& tree, const Image<A>& attr_image, const Function_p2b<P2B>& pred);
@@ -275,4 +312,4 @@
# endif /* !MLN_INCLUDE_ONLY */
-#endif /* !COMPONENTS_HH_ */
+#endif /* !MLN_MORPHO_TREE_COMPONENTS_HH_ */
Index: trunk/milena/sandbox/edwin/tree/propagate_node.hh
===================================================================
--- trunk/milena/sandbox/edwin/tree/propagate_node.hh (revision 3682)
+++ trunk/milena/sandbox/edwin/tree/propagate_node.hh (revision 3683)
@@ -29,9 +29,9 @@
#ifndef MLN_MORPHO_TREE_PROPAGATE_NODE_HH_
# define MLN_MORPHO_TREE_PROPAGATE_NODE_HH_
+# include <mln/core/concept/image.hh>
+# include <mln/core/macros.hh>
#include <mln/morpho/tree/data.hh>
-#include <mln/core/site_set/p_array.hh>
-#include <stack>
/// \file mln/morpho/tree/propagate_node.hh
///
1
0