Olena-patches
Threads by month
- ----- 2025 -----
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
August 2012
- 2 participants
- 138 discussions

olena-2.0-120-g83730f3 mln/fun/x2x/rotation.hh: Remove alpha and axis attributes.
by Guillaume Lazzara 23 Aug '12
by Guillaume Lazzara 23 Aug '12
23 Aug '12
---
milena/ChangeLog | 4 +++
milena/mln/fun/x2x/rotation.hh | 55 +++++++--------------------------------
2 files changed, 14 insertions(+), 45 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index bd1f03f..4fe25e6 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2012-05-28 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * mln/fun/x2x/rotation.hh: Remove alpha and axis attributes.
+
+2012-05-28 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* mln/registration/icp.hh: Cleanup some debug.
2012-05-28 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/milena/mln/fun/x2x/rotation.hh b/milena/mln/fun/x2x/rotation.hh
index da0e1fc..8e106f7 100644
--- a/milena/mln/fun/x2x/rotation.hh
+++ b/milena/mln/fun/x2x/rotation.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009, 2010, 2011 EPITA Research and
+// Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 EPITA Research and
// Development Laboratory (LRDE)
//
// This file is part of Olena.
@@ -163,7 +163,7 @@ namespace mln
rotation();
/// Constructor with radian alpha and a facultative direction
/// (rotation axis).
- rotation(C alpha, const algebra::vec<n,C>& axis);
+ rotation(const C& alpha, const algebra::vec<n,C>& axis);
/// Constructor with quaternion
rotation(const algebra::quat& q);
/// Constructor with h_mat.
@@ -172,24 +172,16 @@ namespace mln
/// Perform the rotation of the given vector.
algebra::vec<n,C> operator()(const algebra::vec<n,C>& v) const;
- /// Set a new grade alpha.
- void set_alpha(C alpha);
- /// Set a new rotation axis.
- void set_axis(const algebra::vec<n,C>& axis);
-
protected:
- void update();
+ void update(const C& alpha, const algebra::vec<n,C>& axis);
bool check_rotation(const algebra::quat& q);
- /* FIXME: Is it useful to keep these values, since they are
- primarily used to build the matrix `m_'? */
- C alpha_;
- algebra::vec<n,C> axis_;
};
# ifndef MLN_INCLUDE_ONLY
+
template <unsigned n, typename C>
inline
rotation<n,C>::rotation()
@@ -198,12 +190,10 @@ namespace mln
template <unsigned n, typename C>
inline
- rotation<n,C>::rotation(C alpha, const algebra::vec<n,C>& axis)
- : alpha_(alpha),
- axis_(axis)
+ rotation<n,C>::rotation(const C& alpha, const algebra::vec<n,C>& axis)
{
this->m_ = algebra::h_mat<n,C>::Id;
- update();
+ update(alpha, axis);
}
template <unsigned n, typename C>
@@ -214,15 +204,8 @@ namespace mln
mlc_bool(n == 3)::check();
mln_precondition(q.is_unit());
- this->m_ = mln::make::h_mat(q);
+ this->m_ = mln::make::h_mat(C(), q);
mln_assertion(check_rotation(q));
-
- /// Update attributes.
- alpha_ = acos(w) * 2;
- axis_[0] = x;
- axis_[1] = y;
- axis_[2] = z;
- axis_.normalize();
}
@@ -257,36 +240,18 @@ namespace mln
rotation<n,C>
rotation<n,C>::inv() const
{
- typename rotation::invert res(-alpha_, axis_);
+ typename rotation::invert res(this->m_._1());
return res;
}
- template <unsigned n, typename C>
- inline
- void
- rotation<n,C>::set_alpha(C alpha)
- {
- alpha_ = alpha;
- update();
- }
-
- template <unsigned n, typename C>
- inline
- void
- rotation<n,C>::set_axis(const algebra::vec<n,C>& axis)
- {
- axis_ = axis;
- update();
- }
-
// Homogenous matrix for a rotation of a point (x,y,z)
// about the vector (u,v,w) by the angle alpha.
template <unsigned n, typename C>
inline
void
- rotation<n,C>::update()
+ rotation<n,C>::update(const C& alpha, const algebra::vec<n,C>& axis)
{
- this->m_ = internal::get_rot_h_mat(alpha_, axis_);
+ this->m_ = internal::get_rot_h_mat(alpha, axis);
}
template <unsigned n, typename C>
--
1.7.2.5
1
0

23 Aug '12
---
milena/ChangeLog | 4 ++++
milena/mln/registration/icp.hh | 19 +++++++++++--------
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index a707cc8..bd1f03f 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2012-05-28 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * mln/registration/icp.hh: Cleanup some debug.
+
+2012-05-28 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* mln/geom/rotate.hh: Add support for n-D images.
2012-05-28 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/milena/mln/registration/icp.hh b/milena/mln/registration/icp.hh
index aa263f7..c6d03db 100644
--- a/milena/mln/registration/icp.hh
+++ b/milena/mln/registration/icp.hh
@@ -159,7 +159,9 @@ namespace mln
mln_postcondition(box.is_valid());
+#ifndef NDEBUG
std::cout << "Map image defined on " << box << std::endl;
+#endif // NDEBUG
X_ = X;
init(X, box);
@@ -190,10 +192,11 @@ namespace mln
mln_postcondition(cp_ima_.is_valid());
mln_postcondition(cp_ima_.domain().is_valid());
+
+#ifndef NDEBUG
std::cout << "pmin = " << cp_ima_.domain().pmin() << std::endl;;
std::cout << "pmax = " << cp_ima_.domain().pmax() << std::endl;;
-#ifndef NDEBUG
mln_ch_value(I, bool) debug2(box);
data::fill(debug2, false);
mln_ch_value(I, value::rgb8) debug(box);
@@ -361,8 +364,9 @@ namespace mln
std::ostringstream ss2;
ss2 << "out_" << prefix << r << ".ppm";
io::ppm::save(mln::slice(out,0), ss2.str());
-#endif
+
std::cout << "Points removed with the whole set and current d_min/d_max: " << removed << std::endl;
+#endif
}
@@ -394,11 +398,11 @@ namespace mln
d_max = int(mean + sd);
}
+#ifndef NDEBUG
std::cout << "Standard deviation = " << sd << std::endl;
- std::ostringstream ss1;
- ss1 << "histo_" << r << ".dat";
std::cout << h << std::endl;
std::cout << "d thresholds = " << d_min << ' ' << d_max << std::endl;
+#endif // ! NDEBUG
}
template <typename P, typename F>
@@ -422,7 +426,7 @@ namespace mln
for_all(p)
{
vec3d_f Pk_i = pair.first.rotate(p.to_vec()) + pair.second;
- vec3d_f Yk_i = closest_point(Pk_i);
+ //vec3d_f Yk_i = closest_point(Pk_i);
int d_i = closest_point.dmap_X_(Pk_i);
if (d_i >= d_min && d_i <= d_max)
@@ -438,6 +442,7 @@ namespace mln
}
}
+# ifndef NDEBUG
{
std::ostringstream ss2;
ss2 << method << "_" << r << "_removed_sites" << ".cloud";
@@ -449,7 +454,6 @@ namespace mln
io::cloud::save(tmp, ss2.str());
}
-# ifndef NDEBUG
std::ostringstream ss2;
ss2 << method << "_" << r << "_removed_sites" << ".ppm";
io::ppm::save(mln::slice(out,0), ss2.str());
@@ -656,7 +660,6 @@ namespace mln
// quaternion qR - rotation
qR = get_rot(P_, mu_P, mu_Yk, closest_point, qR_old, qT_old);
- vec3d_f tmp = qR.v();
// vector qT - translation
qT = mu_Yk - qR.rotate(mu_P);
@@ -678,10 +681,10 @@ namespace mln
ss << "0";
ss << k << ".ppm";
io::ppm::save(mln::slice(tmp_,0), ss.str());
-#endif
std::cout << "e_" << k << "=" << e_k << std::endl;
std::cout << "d_" << k << "=" << d_k << std::endl;
+#endif // ! NDEBUG
// Check distance and error according to the related paper.
// Disabled because of the following 'if'
--
1.7.2.5
1
0

olena-2.0-118-ge3a68da mln/geom/rotate.hh: Add support for n-D images.
by Guillaume Lazzara 23 Aug '12
by Guillaume Lazzara 23 Aug '12
23 Aug '12
---
milena/ChangeLog | 4 ++++
milena/mln/geom/rotate.hh | 22 ++++++++++------------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 8ac0430..a707cc8 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2012-05-28 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * mln/geom/rotate.hh: Add support for n-D images.
+
+2012-05-28 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* mln/algebra/mat.hh: Add implementations for 4x4 matrices.
2012-05-25 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/milena/mln/geom/rotate.hh b/milena/mln/geom/rotate.hh
index 1ba8cb1..218aeeb 100644
--- a/milena/mln/geom/rotate.hh
+++ b/milena/mln/geom/rotate.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2012 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -44,6 +44,8 @@
# include <mln/data/paste.hh>
# include <mln/geom/bbox.hh>
+# include <mln/geom/top_right.hh>
+# include <mln/geom/bottom_left.hh>
# include <mln/extension/duplicate.hh>
@@ -132,7 +134,6 @@ namespace mln
// Do not check that output_domain_ is valid. If it is not,
// further in this routine, we define a default domain.
typedef mln_site(I) P;
- mln_precondition(P::dim == 2);
mln_precondition(input.is_valid());
mln_precondition(angle >= -360.0f && angle <= 360.0f);
// mlc_converts_to(mln_exact(Ext), mln_value(I))::check();
@@ -142,12 +143,12 @@ namespace mln
extension::duplicate(input);
mln_site(I) c = geom::bbox(input).pcenter();
- typedef fun::x2x::translation<2,double> trans_t;
+ typedef fun::x2x::translation<P::dim,double> trans_t;
trans_t
t(-1 * c.to_vec()),
t_1(c.to_vec());
- typedef fun::x2x::rotation<2,double> rot_t;
+ typedef fun::x2x::rotation<P::dim,double> rot_t;
rot_t rot(math::pi * angle / 180.f, literal::origin);
typedef
@@ -209,16 +210,15 @@ namespace mln
const B& box = exact(box_);
typedef mln_site(B) P;
- mln_precondition(P::dim == 2);
mln_precondition(box.is_valid());
mln_precondition(angle >= -360.0f && angle <= 360.0f);
- typedef fun::x2x::translation<2,double> trans_t;
+ typedef fun::x2x::translation<P::dim,double> trans_t;
trans_t
t(-1 * ref.to_vec()),
t_1(ref.to_vec());
- typedef fun::x2x::rotation<2,double> rot_t;
+ typedef fun::x2x::rotation<P::dim,double> rot_t;
rot_t rot(math::pi * angle / 180.f, literal::origin);
typedef
@@ -230,10 +230,8 @@ namespace mln
accu::shape::bbox<P> accu;
P
- top_right(box.pmin().row(),
- box.pmax().col()),
- bot_left(box.pmax().row(),
- box.pmin().col());
+ top_right = geom::top_right(box),
+ bot_left = geom::bottom_left(box);
accu.take(P(comp_transf(box.pmin().to_vec())));
accu.take(P(comp_transf(top_right.to_vec())));
--
1.7.2.5
1
0

olena-2.0-117-g3e10eb3 mln/algebra/mat.hh: Add implementations for 4x4 matrices.
by Guillaume Lazzara 23 Aug '12
by Guillaume Lazzara 23 Aug '12
23 Aug '12
---
milena/ChangeLog | 4 +
milena/mln/algebra/mat.hh | 265 ++++++++++++++++++++++++++++++++-------------
2 files changed, 195 insertions(+), 74 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 0be75ec..8ac0430 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,7 @@
+2012-05-28 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ * mln/algebra/mat.hh: Add implementations for 4x4 matrices.
+
2012-05-25 Guillaume Lazzara <z(a)lrde.epita.fr>
New routines to get bottom left and top right sites.
diff --git a/milena/mln/algebra/mat.hh b/milena/mln/algebra/mat.hh
index 0fc08b4..e51f6e1 100644
--- a/milena/mln/algebra/mat.hh
+++ b/milena/mln/algebra/mat.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2006, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2006, 2008, 2009, 2012 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -123,7 +124,7 @@ namespace mln
mat<m,n,T> t() const;
/// Return the inverse of the matrix.
- /// Only compile on square matrix.
+ /// Only compile on square matrix.
mat<n,m,T> _1() const;
private:
@@ -134,18 +135,6 @@ namespace mln
};
- template <typename T>
- mat<2,2,T>
- make(const T& t00, const T& t01,
- const T& t10, const T& t11);
-
- template <typename T>
- mat<3,3,T>
- make(const T& t00, const T& t01, const T& t02,
- const T& t10, const T& t11, const T& t12,
- const T& t20, const T& t21, const T& t22);
-
-
} // end of namespace algebra
@@ -225,7 +214,7 @@ namespace mln
{
typedef algebra::mat<m, m, mln_trait_op_times(T, U)> ret;
};
-
+
// mat * s
template < unsigned n, unsigned m, typename T,
@@ -245,7 +234,7 @@ namespace mln
// {
// typedef algebra::mat<n, m, mln_trait_binary(Name, T, S)> ret;
// };
-
+
// mat / s
template < unsigned n, unsigned m, typename T,
@@ -340,6 +329,7 @@ namespace mln
// Trace.
+ /// Compute the trace of a matrix \p m
template<unsigned n, typename T>
mln_sum(T)
tr(const mat<n,n,T>& m);
@@ -347,13 +337,10 @@ namespace mln
// Determinant.
- template<typename T>
- mln_sum_product(T,T)
- det(const mat<2,2,T>& m);
-
- template<typename T>
+ /// Compute the determinant of a matrix \p m
+ template<unsigned n, typename T>
mln_sum_product(T,T)
- det(const mat<3,3,T>& m);
+ det(const mat<n,n,T>& m);
@@ -548,6 +535,37 @@ namespace mln
namespace internal
{
+ // "Make" routines.
+
+ template <typename T>
+ inline
+ mat<2,2,T>
+ make(const T& t00, const T& t01,
+ const T& t10, const T& t11)
+ {
+ mat<2,2,T> tmp;
+ tmp(0, 0) = t00; tmp(0, 1) = t01;
+ tmp(1, 0) = t10; tmp(1, 1) = t11;
+ return tmp;
+ }
+
+ template <typename T>
+ inline
+ mat<3,3,T>
+ make(const T& t00, const T& t01, const T& t02,
+ const T& t10, const T& t11, const T& t12,
+ const T& t20, const T& t21, const T& t22)
+ {
+ mat<3,3,T> tmp;
+ tmp(0, 0) = t00; tmp(0, 1) = t01; tmp(0, 2) = t02;
+ tmp(1, 0) = t10; tmp(1, 1) = t11; tmp(1, 2) = t12;
+ tmp(2, 0) = t20; tmp(2, 1) = t21; tmp(2, 2) = t22;
+ return tmp;
+ }
+
+
+ // Inverse routines.
+
template <typename T>
inline
mat<2,2,float>
@@ -568,35 +586,119 @@ namespace mln
mln_precondition(d != 0);
return make<float>( det(make(m(1,1), m(1,2),
m(2,1), m(2,2))),
-
+
det(make(m(0,2), m(0,1),
m(2,2), m(2,1))),
-
+
det(make(m(0,1), m(0,2),
m(1,1), m(1,2))),
-
+
det(make(m(1,2), m(1,0),
m(2,2), m(2,0))),
-
+
det(make(m(0,0), m(0,2),
m(2,0), m(2,2))),
-
+
det(make(m(0,2), m(0,0),
m(1,2), m(1,0))),
det(make(m(1,0), m(1,1),
m(2,0), m(2,1))),
-
+
det(make(m(0,1), m(0,0),
m(2,1), m(2,0))),
-
+
det(make(m(0,0), m(0,1),
m(1,0), m(1,1)))
) / d;
}
- } // end of namespace algebra::inverse
+ template <typename T>
+ inline
+ mat<4,4,float>
+ inverse(const mat<4,4,T>& m)
+ {
+ mat<4,4,T> mo;
+
+ // Based on MESA implementation of the GLU library.
+ mo(0,0) = m(1,1) * m(2,2) * m(3,3) - m(1,1) * m(2,3) * m(3,2) -
+ m(2,1) * m(1,2) * m(3,3) + m(2,1) * m(1,3) * m(3,2) +
+ m(3,1) * m(1,2) * m(2,3) - m(3,1) * m(1,3) * m(2,2);
+
+ mo(1,0) = -m(1,0) * m(2,2) * m(3,3) + m(1,0) * m(2,3) * m(3,2) +
+ m(2,0) * m(1,2) * m(3,3) - m(2,0) * m(1,3) * m(3,2) -
+ m(3,0) * m(1,2) * m(2,3) + m(3,0) * m(1,3) * m(2,2);
+
+ mo(2,0) = m(1,0) * m(2,1) * m(3,3) - m(1,0) * m(2,3) * m(3,1) -
+ m(2,0) * m(1,1) * m(3,3) + m(2,0) * m(1,3) * m(3,1) +
+ m(3,0) * m(1,1) * m(2,3) - m(3,0) * m(1,3) * m(2,1);
+
+ mo(3,0) = -m(1,0) * m(2,1) * m(3,2) + m(1,0) * m(2,2) * m(3,1) +
+ m(2,0) * m(1,1) * m(3,2) - m(2,0) * m(1,2) * m(3,1) -
+ m(3,0) * m(1,1) * m(2,2) + m(3,0) * m(1,2) * m(2,1);
+
+ mo(0,1) = -m(0,1) * m(2,2) * m(3,3) + m(0,1) * m(2,3) * m(3,2) +
+ m(2,1) * m(0,2) * m(3,3) - m(2,1) * m(0,3) * m(3,2) -
+ m(3,1) * m(0,2) * m(2,3) + m(3,1) * m(0,3) * m(2,2);
+
+ mo(1,1) = m(0,0) * m(2,2) * m(3,3) - m(0,0) * m(2,3) * m(3,2) -
+ m(2,0) * m(0,2) * m(3,3) + m(2,0) * m(0,3) * m(3,2) +
+ m(3,0) * m(0,2) * m(2,3) - m(3,0) * m(0,3) * m(2,2);
+
+ mo(2,1) = -m(0,0) * m(2,1) * m(3,3) + m(0,0) * m(2,3) * m(3,1) +
+ m(2,0) * m(0,1) * m(3,3) - m(2,0) * m(0,3) * m(3,1) -
+ m(3,0) * m(0,1) * m(2,3) + m(3,0) * m(0,3) * m(2,1);
+
+ mo(3,1) = m(0,0) * m(2,1) * m(3,2) - m(0,0) * m(2,2) * m(3,1) -
+ m(2,0) * m(0,1) * m(3,2) + m(2,0) * m(0,2) * m(3,1) +
+ m(3,0) * m(0,1) * m(2,2) - m(3,0) * m(0,2) * m(2,1);
+
+ mo(0,2) = m(0,1) * m(1,2) * m(3,3) - m(0,1) * m(1,3) * m(3,2) -
+ m(1,1) * m(0,2) * m(3,3) + m(1,1) * m(0,3) * m(3,2) +
+ m(3,1) * m(0,2) * m(1,3) - m(3,1) * m(0,3) * m(1,2);
+
+ mo(1,2) = -m(0,0) * m(1,2) * m(3,3) + m(0,0) * m(1,3) * m(3,2) +
+ m(1,0) * m(0,2) * m(3,3) - m(1,0) * m(0,3) * m(3,2) -
+ m(3,0) * m(0,2) * m(1,3) + m(3,0) * m(0,3) * m(1,2);
+
+ mo(2,2) = m(0,0) * m(1,1) * m(3,3) - m(0,0) * m(1,3) * m(3,1) -
+ m(1,0) * m(0,1) * m(3,3) + m(1,0) * m(0,3) * m(3,1) +
+ m(3,0) * m(0,1) * m(1,3) - m(3,0) * m(0,3) * m(1,1);
+
+ mo(3,2) = -m(0,0) * m(1,1) * m(3,2) + m(0,0) * m(1,2) * m(3,1) +
+ m(1,0) * m(0,1) * m(3,2) - m(1,0) * m(0,2) * m(3,1) -
+ m(3,0) * m(0,1) * m(1,2) + m(3,0) * m(0,2) * m(1,1);
+
+ mo(0,3) = -m(0,1) * m(1,2) * m(2,3) + m(0,1) * m(1,3) * m(2,2) +
+ m(1,1) * m(0,2) * m(2,3) - m(1,1) * m(0,3) * m(2,2) -
+ m(2,1) * m(0,2) * m(1,3) + m(2,1) * m(0,3) * m(1,2);
+
+ mo(1,3) = m(0,0) * m(1,2) * m(2,3) - m(0,0) * m(1,3) * m(2,2) -
+ m(1,0) * m(0,2) * m(2,3) + m(1,0) * m(0,3) * m(2,2) +
+ m(2,0) * m(0,2) * m(1,3) - m(2,0) * m(0,3) * m(1,2);
+
+ mo(2,3) = -m(0,0) * m(1,1) * m(2,3) + m(0,0) * m(1,3) * m(2,1) +
+ m(1,0) * m(0,1) * m(2,3) - m(1,0) * m(0,3) * m(2,1) -
+ m(2,0) * m(0,1) * m(1,3) + m(2,0) * m(0,3) * m(1,1);
+
+ mo(3,3) = m(0,0) * m(1,1) * m(2,2) - m(0,0) * m(1,2) * m(2,1) -
+ m(1,0) * m(0,1) * m(2,2) + m(1,0) * m(0,2) * m(2,1) +
+ m(2,0) * m(0,1) * m(1,2) - m(2,0) * m(0,2) * m(1,1);
+
+ double det = m(0,0) * mo(0,0) + m(0,1) * mo(1,0) + m(0,2) * mo(2,0) + m(0,3) * mo(0,3);
+ mln_precondition(det != 0);
+
+ det = 1.0 / det;
+
+ for (int i = 0; i < 4; i++)
+ for (int j = 0; j < 4; j++)
+ mo(i,j) *= det;
+
+ return mo;
+ }
+
+ } // end of namespace algebra::internal
template <unsigned n, unsigned m, typename T>
inline
@@ -608,35 +710,6 @@ namespace mln
}
- // "Make" routines.
-
- template <typename T>
- inline
- mat<2,2,T>
- make(const T& t00, const T& t01,
- const T& t10, const T& t11)
- {
- mat<2,2,T> tmp;
- tmp(0, 0) = t00; tmp(0, 1) = t01;
- tmp(1, 0) = t10; tmp(1, 1) = t11;
- return tmp;
- }
-
- template <typename T>
- inline
- mat<3,3,T>
- make(const T& t00, const T& t01, const T& t02,
- const T& t10, const T& t11, const T& t12,
- const T& t20, const T& t21, const T& t22)
- {
- mat<3,3,T> tmp;
- tmp(0, 0) = t00; tmp(0, 1) = t01; tmp(0, 2) = t02;
- tmp(1, 0) = t10; tmp(1, 1) = t11; tmp(1, 2) = t12;
- tmp(2, 0) = t20; tmp(2, 1) = t21; tmp(2, 2) = t22;
- return tmp;
- }
-
-
// Operators.
@@ -827,29 +900,72 @@ namespace mln
// Determinant.
- template<typename T>
- inline
- mln_sum_product(T,T)
- det(const mat<2,2,T>& m)
+ namespace impl
{
- return m(0,0) * m(1,1) - m(0,1) * m(1,0);
- }
- template<typename T>
+ template<unsigned n, typename T>
+ mln_sum_product(T,T)
+ det(const mat<n,n,T>& m)
+ {
+ // Not implemented.
+ mlc_abort(T)::check();
+ }
+
+ template<typename T>
+ inline
+ mln_sum_product(T,T)
+ det(const mat<2,2,T>& m)
+ {
+ return m(0,0) * m(1,1) - m(0,1) * m(1,0);
+ }
+
+ template<typename T>
+ inline
+ mln_sum_product(T,T)
+ det(const mat<3,3,T>& m)
+ {
+ return
+ + m(0,0) * m(1,1) * m(2,2)
+ - m(0,0) * m(1,2) * m(2,1)
+ - m(0,1) * m(1,0) * m(2,2)
+ + m(0,1) * m(1,2) * m(2,0)
+ + m(0,2) * m(1,0) * m(2,1)
+ - m(0,2) * m(1,1) * m(2,0);
+ }
+
+ template<typename T>
+ inline
+ mln_sum_product(T,T)
+ det(const mat<4,4,T>& m)
+ {
+ return m(0,3) * m(1,2) * m(2,1) * m(3,0) - m(0,2) * m(1,3) * m(2,1) * m(3,0) -
+ m(0,3) * m(1,1) * m(2,2) * m(3,0) + m(0,1) * m(1,3) * m(2,2) * m(3,0) +
+ m(0,2) * m(1,1) * m(2,3) * m(3,0) - m(0,1) * m(1,2) * m(2,3) * m(3,0) -
+ m(0,3) * m(1,2) * m(2,0) * m(3,1) + m(0,2) * m(1,3) * m(2,0) * m(3,1) +
+ m(0,3) * m(1,0) * m(2,2) * m(3,1) - m(0,0) * m(1,3) * m(2,2) * m(3,1) -
+ m(0,2) * m(1,0) * m(2,3) * m(3,1) + m(0,0) * m(1,2) * m(2,3) * m(3,1) +
+ m(0,3) * m(1,1) * m(2,0) * m(3,2) - m(0,1) * m(1,3) * m(2,0) * m(3,2) -
+ m(0,3) * m(1,0) * m(2,1) * m(3,2) + m(0,0) * m(1,3) * m(2,1) * m(3,2) +
+ m(0,1) * m(1,0) * m(2,3) * m(3,2) - m(0,0) * m(1,1) * m(2,3) * m(3,2) -
+ m(0,2) * m(1,1) * m(2,0) * m(3,3) + m(0,1) * m(1,2) * m(2,0) * m(3,3) +
+ m(0,2) * m(1,0) * m(2,1) * m(3,3) - m(0,0) * m(1,2) * m(2,1) * m(3,3) -
+ m(0,1) * m(1,0) * m(2,2) * m(3,3) + m(0,0) * m(1,1) * m(2,2) * m(3,3);
+ }
+
+ } // end of namespace mln::algebra::impl
+
+
+ template<unsigned n, typename T>
inline
mln_sum_product(T,T)
- det(const mat<3,3,T>& m)
+ det(const mat<n,n,T>& m)
{
- return
- + m(0,0) * m(1,1) * m(2,2)
- - m(0,0) * m(1,2) * m(2,1)
- - m(0,1) * m(1,0) * m(2,2)
- + m(0,1) * m(1,2) * m(2,0)
- + m(0,2) * m(1,0) * m(2,1)
- - m(0,2) * m(1,1) * m(2,0);
+ return mln::algebra::impl::det(m);
}
+
+
// vec methods.
template <unsigned n, typename T>
@@ -863,6 +979,7 @@ namespace mln
return tmp;
}
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::algebra
--
1.7.2.5
1
0

olena-2.0-116-gd9daf6a New routines to get bottom left and top right sites.
by Guillaume Lazzara 23 Aug '12
by Guillaume Lazzara 23 Aug '12
23 Aug '12
* mln/geom/bottom_left.hh,
* mln/geom/top_right.hh: New.
* mln/geom/all.hh: Add includes.
---
milena/ChangeLog | 9 ++
milena/mln/geom/all.hh | 4 +-
milena/mln/geom/bottom_left.hh | 160 ++++++++++++++++++++++++++++++++++++++++
milena/mln/geom/top_right.hh | 160 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 332 insertions(+), 1 deletions(-)
create mode 100644 milena/mln/geom/bottom_left.hh
create mode 100644 milena/mln/geom/top_right.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index d8d0804..0be75ec 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,14 @@
2012-05-25 Guillaume Lazzara <z(a)lrde.epita.fr>
+ New routines to get bottom left and top right sites.
+
+ * mln/geom/bottom_left.hh,
+ * mln/geom/top_right.hh: New.
+
+ * mln/geom/all.hh: Add includes.
+
+2012-05-25 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Improve conversion between algebra::h_mat and algebra::quat.
* mln/algebra/h_mat.hh,
diff --git a/milena/mln/geom/all.hh b/milena/mln/geom/all.hh
index 70a719f..fb258f0 100644
--- a/milena/mln/geom/all.hh
+++ b/milena/mln/geom/all.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009, 2010, 2011 EPITA Research and
+// Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 EPITA Research and
// Development Laboratory (LRDE)
//
// This file is part of Olena.
@@ -68,6 +68,8 @@ namespace mln
# include <mln/geom/size1d.hh>
# include <mln/geom/size2d.hh>
# include <mln/geom/size3d.hh>
+# include <mln/geom/top_right.hh>
+# include <mln/geom/bottom_left.hh>
# include <mln/geom/translate.hh>
diff --git a/milena/mln/geom/bottom_left.hh b/milena/mln/geom/bottom_left.hh
new file mode 100644
index 0000000..a7ee930
--- /dev/null
+++ b/milena/mln/geom/bottom_left.hh
@@ -0,0 +1,160 @@
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef MLN_GEOM_BOTTOM_LEFT_HH
+# define MLN_GEOM_BOTTOM_LEFT_HH
+
+/// \file
+///
+/// Give the bottom left point of an image.
+
+# include <mln/core/concept/image.hh>
+# include <mln/geom/bbox.hh>
+
+
+namespace mln
+{
+
+ namespace geom
+ {
+
+ /*! \brief Give the bottom left point of a 2d or 3d image.
+
+ In 3d, the top-right point corresponds to the bottom left corner
+ of the front face.
+ */
+ template <typename I>
+ mln_site(I) bottom_left(const Image<I>& ima);
+
+
+ /*! \brief Give the bottom left point of a box 2d or 3d.
+ \overload
+ */
+ template <typename B>
+ mln_site(B) bottom_left(const Box<B>& b);
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace impl
+ {
+
+ template <typename B>
+ inline
+ mln_site(B) bottom_left_2d(const Box<B>& b_)
+ {
+ const B& b = exact(b_);
+ mln_site(B) bottom_left(b.pmax().row(),
+ b.pmin().col());
+ return bottom_left;
+ }
+
+ template <typename B>
+ inline
+ mln_site(B) bottom_left_3d(const Box<B>& b_)
+ {
+ const B& b = exact(b_);
+ mln_site(B) bottom_left(b.pmax().sli(),
+ b.pmax().row(),
+ b.pmin().col());
+ return bottom_left;
+ }
+
+ } // end of namespace mln::geom::impl
+
+
+ namespace internal
+ {
+
+ // Not implemented.
+ template <unsigned n>
+ struct bottom_left_dispatch_impl;
+
+ // 2d
+ template <>
+ struct bottom_left_dispatch_impl<2>
+ {
+ template <typename B>
+ inline
+ mln_site(B) run(const Box<B>& box) const
+ {
+ return impl::bottom_left_2d(box);
+ }
+ };
+
+ // 3d
+ template <>
+ struct bottom_left_dispatch_impl<3>
+ {
+ template <typename B>
+ inline
+ mln_site(B) run(const Box<B>& box) const
+ {
+ return impl::bottom_left_3d(box);
+ }
+ };
+
+
+ template <typename B>
+ inline
+ mln_site(B) bottom_left_dispatch(const Box<B>& box)
+ {
+ typedef mln_site(B) P;
+ return bottom_left_dispatch_impl<P::dim>().run(box);
+ }
+
+ } // end of namespace mln::geom::internal
+
+
+ // Facades
+
+ template <typename I>
+ inline
+ mln_site(I) bottom_left(const Image<I>& ima)
+ {
+ mln_precondition(exact(ima).is_valid());
+ mln_site(I) output = internal::bottom_left_dispatch(exact(ima).domain());
+
+ return output;
+ }
+
+ template <typename B>
+ inline
+ mln_site(B) bottom_left(const Box<B>& b)
+ {
+ mln_precondition(exact(b).is_valid());
+ mln_site(B) output = internal::bottom_left_dispatch(b);
+
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+
+#endif // ! MLN_GEOM_BOTTOM_LEFT_HH
diff --git a/milena/mln/geom/top_right.hh b/milena/mln/geom/top_right.hh
new file mode 100644
index 0000000..655eef0
--- /dev/null
+++ b/milena/mln/geom/top_right.hh
@@ -0,0 +1,160 @@
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef MLN_GEOM_TOP_RIGHT_HH
+# define MLN_GEOM_TOP_RIGHT_HH
+
+/// \file
+///
+/// Give the top right point of an image.
+
+# include <mln/core/concept/image.hh>
+# include <mln/geom/bbox.hh>
+
+
+namespace mln
+{
+
+ namespace geom
+ {
+
+ /*! \brief Give the top right point of a 2d or 3d image.
+
+ In 3d, the top-right point corresponds to the top right corner
+ of the back face.
+ */
+ template <typename I>
+ mln_site(I) top_right(const Image<I>& ima);
+
+
+ /*! \brief Give the top right point of a box 2d or 3d.
+ \overload
+ */
+ template <typename B>
+ mln_site(B) top_right(const Box<B>& b);
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace impl
+ {
+
+ template <typename B>
+ inline
+ mln_site(B) top_right_2d(const Box<B>& b_)
+ {
+ const B& b = exact(b_);
+ mln_site(B) top_right(b.pmin().row(),
+ b.pmax().col());
+ return top_right;
+ }
+
+ template <typename B>
+ inline
+ mln_site(B) top_right_3d(const Box<B>& b_)
+ {
+ const B& b = exact(b_);
+ mln_site(B) top_right(b.pmin().sli(),
+ b.pmin().row(),
+ b.pmax().col());
+ return top_right;
+ }
+
+ } // end of namespace mln::geom::impl
+
+
+ namespace internal
+ {
+
+ // Not implemented.
+ template <unsigned n>
+ struct top_right_dispatch_impl;
+
+ // 2d
+ template <>
+ struct top_right_dispatch_impl<2>
+ {
+ template <typename B>
+ inline
+ mln_site(B) run(const Box<B>& box) const
+ {
+ return impl::top_right_2d(box);
+ }
+ };
+
+ // 3d
+ template <>
+ struct top_right_dispatch_impl<3>
+ {
+ template <typename B>
+ inline
+ mln_site(B) run(const Box<B>& box) const
+ {
+ return impl::top_right_3d(box);
+ }
+ };
+
+
+ template <typename B>
+ inline
+ mln_site(B) top_right_dispatch(const Box<B>& box)
+ {
+ typedef mln_site(B) P;
+ return top_right_dispatch_impl<P::dim>().run(box);
+ }
+
+ } // end of namespace mln::geom::internal
+
+
+ // Facades
+
+ template <typename I>
+ inline
+ mln_site(I) top_right(const Image<I>& ima)
+ {
+ mln_precondition(exact(ima).is_valid());
+ mln_site(I) output = internal::top_right_dispatch(exact(ima).domain());
+
+ return output;
+ }
+
+ template <typename B>
+ inline
+ mln_site(B) top_right(const Box<B>& b)
+ {
+ mln_precondition(exact(b).is_valid());
+ mln_site(B) output = internal::top_right_dispatch(b);
+
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+
+#endif // ! MLN_GEOM_TOP_RIGHT_HH
--
1.7.2.5
1
0

olena-2.0-115-gd9deb1a Improve conversion between algebra::h_mat and algebra::quat.
by Guillaume Lazzara 23 Aug '12
by Guillaume Lazzara 23 Aug '12
23 Aug '12
* mln/algebra/h_mat.hh,
* mln/algebra/quat.hh: New from_to_ overloads.
* mln/fun/x2x/rotation.hh: Make use of new make::h_mat overload.
* mln/make/h_mat.hh: New overload using quaternion as argument.
* mln/value/builtin/integers.hh: Add epsilon.
* tests/algebra/h_mat.cc,
* tests/make/h_mat.cc: Improve tests.
---
milena/ChangeLog | 16 ++++++
milena/mln/algebra/h_mat.hh | 94 +++++++++++++++++++++++++++++++++-
milena/mln/algebra/quat.hh | 71 +++++++++++++++++++++++++-
milena/mln/fun/x2x/rotation.hh | 12 +----
milena/mln/make/h_mat.hh | 38 +++++++++++++-
milena/mln/value/builtin/integers.hh | 4 +-
milena/tests/algebra/h_mat.cc | 52 +++++++++++++-----
milena/tests/make/h_mat.cc | 38 +++++++++++++-
8 files changed, 291 insertions(+), 34 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index de897eb..d8d0804 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,19 @@
+2012-05-25 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Improve conversion between algebra::h_mat and algebra::quat.
+
+ * mln/algebra/h_mat.hh,
+ * mln/algebra/quat.hh: New from_to_ overloads.
+
+ * mln/fun/x2x/rotation.hh: Make use of new make::h_mat overload.
+
+ * mln/make/h_mat.hh: New overload using quaternion as argument.
+
+ * mln/value/builtin/integers.hh: Add epsilon.
+
+ * tests/algebra/h_mat.cc,
+ * tests/make/h_mat.cc: Improve tests.
+
2012-05-10 Guillaume Lazzara <z(a)lrde.epita.fr>
Rely on Argument-Dependent Lookup (ADL) in from_to_ overloads.
diff --git a/milena/mln/algebra/h_mat.hh b/milena/mln/algebra/h_mat.hh
index 3d75a66..e2ee67f 100644
--- a/milena/mln/algebra/h_mat.hh
+++ b/milena/mln/algebra/h_mat.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009, 2012 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -31,10 +32,21 @@
* \brief Definition of a matrix with homogeneous coordinates.
*
* \todo Add traits.
+ *
+ * FIXME: there is a big issue with this class. exact() does not
+ * return the correct type since the exact type is NOT correctly
+ * propagated to Object. mat and h_mat should inherit from a base
+ * class and the operator traits should be updated so that
+ * interoperability between mat and h_mat is preserved which is not
+ * obvious.
+ *
*/
# include <mln/algebra/mat.hh>
+# include <mln/algebra/quat.hh>
+# include <mln/math/pi.hh>
+# include <mln/util/couple.hh>
namespace mln
{
@@ -57,9 +69,15 @@ namespace mln
h_mat();
/// Constructor with the underlying matrix.
h_mat(const mat<d+1, d+1, T>& x);
+
};
+ /// \internal Conversion: h_mat -> quat
+ template <typename C>
+ void from_to_(const algebra::h_mat<3,C>& from, algebra::quat& to);
+
+
# ifndef MLN_INCLUDE_ONLY
template <unsigned d, typename T>
@@ -76,6 +94,80 @@ namespace mln
{
}
+
+ // Conversions
+
+ template <typename C>
+ void from_to_(const algebra::h_mat<3,C>& from, algebra::quat& to)
+ {
+ C tr = from(0, 0) + from(1, 1) + from(2, 2) + 1;
+
+ if (tr > 0.005f) // Actually, greater than 0
+ {
+ C s = 0.5 / sqrt(tr),
+ w = 0.25 / s,
+ x = (from(2, 1) - from(1, 2)) * s,
+ y = (from(0, 2) - from(2, 0)) * s,
+ z = (from(1, 0) - from(0, 1)) * s;
+
+ to = algebra::quat(w, x, y, z);
+ return;
+ }
+
+ // If the trace of the matrix is less than or equal to zero
+ // then identify which major diagonal element has the greatest
+ // value.
+
+ C max = 0;
+ unsigned c = 0;
+ for (unsigned d = 0; d <= 3; ++d)
+ if (from(d, d) > max)
+ {
+ max = from(d, d);
+ c = d;
+ }
+
+ // Depending on this value, calculate the following:
+ C s, w, x, y, z;
+ switch(c)
+ {
+ case 0:
+ s = sqrt(1.0 + from(0, 0) - from(1, 1) - from(2, 2)) * 2;
+ x = 0.5 / s;
+ y = (from(0, 1) + from(1, 0)) / s;
+ z = (from(0, 2) + from(2, 0)) / s;
+ w = (from(1, 2) + from(2, 1)) / s;
+ break;
+
+ case 1:
+ s = sqrt(1.0 + from(1, 1) - from(0, 0) - from(2, 2)) * 2;
+ x = (from(0, 1) + from(1, 0)) / s;
+ y = 0.5 / s;
+ z = (from(1, 2) + from(2, 1)) / s;
+ w = (from(0, 2) + from(2, 0)) / s;
+ break;
+
+ case 2:
+ s = sqrt(1.0 + from(2, 2) - from(0, 0) - from(1, 1)) * 2;
+ x = (from(0, 2) + from(2, 0)) / s;
+ y = (from(1, 2) + from(2, 1)) / s;
+ z = 0.5 / s;
+ w = (from(0, 1) + from(1, 0) ) / s;
+ break;
+
+ // Error case
+ default:
+ x = 0;
+ y = 0;
+ z = 0;
+ w = 0;
+ }
+
+ to = algebra::quat(w, x, y, z);
+ return;
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::algebra
diff --git a/milena/mln/algebra/quat.hh b/milena/mln/algebra/quat.hh
index 9ec725d..20dc9db 100644
--- a/milena/mln/algebra/quat.hh
+++ b/milena/mln/algebra/quat.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009, 2012 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -44,6 +45,8 @@
# include <mln/math/abs.hh>
# include <mln/norm/l2.hh>
+# include <mln/util/couple.hh>
+# include <mln/math/pi.hh>
// FIXME: pow, exp etc... are def here and in value::...
@@ -260,8 +263,28 @@ namespace mln
quat slerp_5(const quat& p, const quat& q, float h);
+ /// \internal Conversion: quaternion -> (angle_degrees, axis).
+ template <typename C>
+ void from_to_(const quat& from, mln::util::couple<C, algebra::vec<3,C> >& to);
+
+ } // end of namespace mln::algebra
+
+
+ namespace make
+ {
+
+ template <typename C>
+ mln::algebra::quat
+ quat(double angle, const mln::algebra::vec<3,C>& axis);
+
+ }
+
# ifndef MLN_INCLUDE_ONLY
+
+ namespace algebra
+ {
+
// Constructors.
inline
@@ -673,10 +696,54 @@ namespace mln
return tmp;
}
-# endif // ! MLN_INCLUDE_ONLY
+
+ // Conversions.
+
+ template <typename C>
+ void from_to_(const quat& from, mln::util::couple<C, algebra::vec<3,C> >& to)
+ {
+ quat tmp = from;
+ tmp.set_unit();
+
+ C w = tmp.to_vec()[0],
+ angle = std::acos(w) * 2 * 180/math::pi;
+
+ C sa = std::sin(std::acos(w));
+ if (std::fabs( sa ) < 0.0005 )
+ sa = 1;
+
+ to.first() = angle;
+ to.second()[0] = tmp.to_vec()[1] / sa;
+ to.second()[1] = tmp.to_vec()[2] / sa;
+ to.second()[2] = tmp.to_vec()[3] / sa;
+ }
} // end of namespace mln::algebra
+
+ namespace make
+ {
+
+ template <typename C>
+ mln::algebra::quat
+ quat(double angle, const mln::algebra::vec<3,C>& axis)
+ {
+ angle *= mln::math::pi/180;
+ C s = std::sin(angle / 2);
+
+ C x = axis[0] * s,
+ y = axis[1] * s,
+ z = axis[2] * s,
+ w = std::cos(angle / 2);
+
+ return mln::algebra::quat(w, x, y, z);
+ }
+
+ } // end of namespace mln::make
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln
#endif // ! MLN_ALGEBRA_QUAT_HH
diff --git a/milena/mln/fun/x2x/rotation.hh b/milena/mln/fun/x2x/rotation.hh
index ed48ebf..da0e1fc 100644
--- a/milena/mln/fun/x2x/rotation.hh
+++ b/milena/mln/fun/x2x/rotation.hh
@@ -214,17 +214,7 @@ namespace mln
mlc_bool(n == 3)::check();
mln_precondition(q.is_unit());
- C
- w = q.to_vec()[0],
- x = q.to_vec()[1], x2 = 2*x*x, xw = 2*x*w,
- y = q.to_vec()[2], y2 = 2*y*y, xy = 2*x*y, yw = 2*y*w,
- z = q.to_vec()[3], z2 = 2*z*z, xz = 2*x*z, yz = 2*y*z, zw = 2*z*w;
-
- C t[9] = {1.f - y2 - z2, xy - zw, xz + yw,
- xy + zw, 1.f - x2 - z2, yz - xw,
- xz - yw, yz + xw, 1.f - x2 - y2};
-
- this->m_ = mln::make::h_mat(t);
+ this->m_ = mln::make::h_mat(q);
mln_assertion(check_rotation(q));
/// Update attributes.
diff --git a/milena/mln/make/h_mat.hh b/milena/mln/make/h_mat.hh
index d124ccf..1ab2dc0 100644
--- a/milena/mln/make/h_mat.hh
+++ b/milena/mln/make/h_mat.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2012 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -41,7 +42,7 @@ namespace mln
{
- /// Create an mln::algebra::mat<n,n,T>.
+ /// Create an mln::algebra::h_mat<n,T>.
/*
* \param[in] tab C-array of values.
*
@@ -51,6 +52,14 @@ namespace mln
algebra::h_mat<mlc_sqrt_int(N), T> h_mat(const T (&tab)[N]);
+ /*! \brief Create a rotation matrix as mln::algebra::h_mat<n,T>.
+
+ \param[in] q A quaternion.
+
+ \return A rotation matrix based on \p q.
+ */
+ template <typename C>
+ algebra::h_mat<3, C> h_mat(const C& v, const algebra::quat& q);
# ifndef MLN_INCLUDE_ONLY
@@ -67,6 +76,31 @@ namespace mln
return tmp;
}
+
+ template <typename C>
+ inline
+ algebra::h_mat<3, C>
+ h_mat(const C& v, const algebra::quat& q)
+ {
+ mln_precondition(q.is_unit());
+ (void) v;
+
+ algebra::h_mat<3, C> m;
+ C
+ w = q.to_vec()[0],
+ x = q.to_vec()[1], x2 = 2*x*x, xw = 2*x*w,
+ y = q.to_vec()[2], y2 = 2*y*y, xy = 2*x*y, yw = 2*y*w,
+ z = q.to_vec()[3], z2 = 2*z*z, xz = 2*x*z, yz = 2*y*z, zw = 2*z*w;
+
+ C t[9] = {1.f - y2 - z2, xy - zw, xz + yw,
+ xy + zw, 1.f - x2 - z2, yz - xw,
+ xz - yw, yz + xw, 1.f - x2 - y2};
+
+ m = mln::make::h_mat(t);
+ return m;
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::make
diff --git a/milena/mln/value/builtin/integers.hh b/milena/mln/value/builtin/integers.hh
index 05cbede..8cc173c 100644
--- a/milena/mln/value/builtin/integers.hh
+++ b/milena/mln/value/builtin/integers.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009, 2012 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -81,6 +82,7 @@ namespace mln
static const E min() { return mln::value::internal::limits<E>::min(); }
static const E max() { return mln::value::internal::limits<E>::max(); }
+ static const E epsilon() { return mln::value::internal::limits<E>::epsilon(); }
typedef float sum;
};
diff --git a/milena/tests/algebra/h_mat.cc b/milena/tests/algebra/h_mat.cc
index a5bb31c..7a30f6b 100644
--- a/milena/tests/algebra/h_mat.cc
+++ b/milena/tests/algebra/h_mat.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2009, 2012 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -26,34 +27,55 @@
#include <mln/fun/i2v/all_to.hh>
#include <mln/algebra/mat.hh>
#include <mln/algebra/h_mat.hh>
+#include <mln/make/h_mat.hh>
+template <typename T>
+bool about_equal(const T& f, const T& q)
+{
+ return mln::math::abs(q - f) <= 0.000001;
+}
+
int main()
{
using namespace mln;
- algebra::mat<1,3,float> m1;
- m1.set_all(4);
- algebra::mat<2,2,float> m2 = literal::identity;
+ // Reading in h_mat.
+ algebra::h_mat<3,float> hm2(all_to(2.5));
+ for (int i = 0; i < 4; ++i)
+ for (int j = 0; j < 4; ++j)
+ mln_assertion(hm2(i, j) == 2.5f);
+ // Conversion from mat to h_mat
+ algebra::mat<2,2,float> m2 = literal::identity;
algebra::h_mat<1,float> hm1(m2);
- algebra::h_mat<2,float> hm2;
- algebra::h_mat<3,float> hm3(all_to(1.5));
+ mln_assertion(m2.size() == hm1.size());
+ for (int i = 0; i < 2; ++i)
+ for (int j = 0; j < 2; ++j)
+ mln_assertion(m2(i, j) == hm1(i, j));
+ // Conversion from h_mat to mat.
+ algebra::h_mat<3,float> hm3(all_to(1.5));
algebra::mat<4,4,float> m4 = hm3;
+ mln_assertion(m4.size() == hm3.size());
+ for (int i = 0; i < 4; ++i)
+ for (int j = 0; j < 4; ++j)
+ mln_assertion(m4(i, j) == hm3(i, j));
- std::cout << "m1 = " << m1 << ";" << std::endl;
- std::cout << "m2 = " << m2 << ";" << std::endl;
- std::cout << "m4 = " << m4 << ";" << std::endl;
- std::cout << "hm1 = " << hm1 << ";" << std::endl;
- std::cout << "hm2 = " << hm2 << ";" << std::endl;
- std::cout << "hm3 = " << hm3 << ";" << std::endl;
+ // Check from_to_ overloads.
{
- algebra::h_mat<2,float> m, m2;
- m = m2;
- // FIXME: Test *many* => runs ok...
+ algebra::quat q_ref(0.92388, 0.186238, 0.310397, 0.124159);
+ double vals[9] = { 0.776477, -0.113801, 0.619785,
+ 0.345031, 0.8998, -0.267046,
+ -0.527293, 0.4212, 0.737938 };
+ algebra::h_mat<3,double> m = make::h_mat(vals);
+ algebra::quat q2;
+ algebra::from_to_(m, q2);
+
+ for (int i = 0; i < 4; ++i)
+ mln_assertion(about_equal(q_ref.to_vec()[i], q2.to_vec()[i]));
}
}
diff --git a/milena/tests/make/h_mat.cc b/milena/tests/make/h_mat.cc
index a737252..eaf232e 100644
--- a/milena/tests/make/h_mat.cc
+++ b/milena/tests/make/h_mat.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2012 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -24,6 +25,7 @@
// executable file might be covered by the GNU General Public License.
#include <mln/make/h_mat.hh>
+#include <mln/math/abs.hh>
static const int result[4][4] = { { 2, 3, 4, 0 },
@@ -31,6 +33,19 @@ static const int result[4][4] = { { 2, 3, 4, 0 },
{ 8, 9, 10, 0 },
{ 0, 0, 0, 1 } };
+static const double result_q[4][4] = { { 0.776477, -0.113801, 0.619785, 0 },
+ { 0.345031, 0.8998, -0.267046, 0 },
+ { -0.527293, 0.4212, 0.737938, 0 },
+ { 0, 0, 0, 1 } };
+
+
+template <typename T>
+bool about_equal(const T& f, const T& q)
+{
+ return mln::math::abs(q - f) <= 0.000001;
+}
+
+
int main()
{
using namespace mln;
@@ -39,8 +54,27 @@ int main()
5, 6, 7,
8, 9, 10 };
algebra::h_mat<3,int> m = make::h_mat(vals);
-
+
for (unsigned i = 0; i < 4; ++i)
for (unsigned j = 0; j < 4; ++j)
mln_assertion(m(i,j) == result[i][j]);
+
+
+ // Checking creation from quaternions.
+ {
+ algebra::vec<3,double> v;
+ v[0] = 1;
+ v[1] = 2;
+ v[2] = 3;
+ v.normalize();
+
+ algebra::quat q(0.92388, 0.186238, 0.310397, 0.124159);
+ q.set_unit();
+
+ algebra::h_mat<3,double> mat = make::h_mat(double(), q);
+
+ for (unsigned i = 0; i < 4; ++i)
+ for (unsigned j = 0; j < 4; ++j)
+ mln_assertion(about_equal(mat(i,j), result_q[i][j]));
+ }
}
--
1.7.2.5
1
0

olena-2.0-114-g2622f3b Rely on Argument-Dependent Lookup (ADL) in from_to_ overloads.
by Guillaume Lazzara 23 Aug '12
by Guillaume Lazzara 23 Aug '12
23 Aug '12
* mln/accu/count_labels.hh,
* mln/convert/from_to.hxx,
* mln/convert/to.hh,
* mln/core/alias/point1d.hh,
* mln/core/alias/point2d.hh,
* mln/core/alias/point3d.hh,
* mln/core/dpoint.hh,
* mln/core/internal/neighborhood_base.hh,
* mln/core/point.hh,
* mln/core/site_set/p_centered.hh,
* mln/core/site_set/p_vaccess.hh,
* mln/fun/v2v/hsl_to_rgb.hh,
* mln/fun/v2v/rgb_to_hsl.hh,
* mln/io/magick/save.hh,
* mln/io/plot/save.hh,
* mln/labeling/blobs_and_compute.hh,
* mln/labeling/value_and_compute.hh,
* mln/make/w_window2d.hh,
* mln/win/multiple.hh,
* mln/win/multiple_size.hh,
* tests/accu/site_set/rectangularity.cc,
* tests/core/other/graph_elt_neighborhood.cc,
* tests/core/other/graph_elt_window.cc,
* tests/core/other/point_set_compatibility.cc,
* tests/draw/graph.cc: Update forward declarations and includes.
* mln/algebra/vec.hh,
* mln/convert/from_to.hh,
* mln/convert/impl/from_double_to_value.hh,
* mln/convert/impl/from_float_to_value.hh,
* mln/convert/impl/from_image_to_site_set.hh,
* mln/convert/impl/from_int_to_value.hh,
* mln/convert/impl/from_unsigned_to_value.hh,
* mln/convert/impl/from_value_to_value.hh,
* mln/core/alias/neighb2d.hh,
* mln/core/alias/neighb3d.hh,
* mln/core/alias/window1d.hh,
* mln/core/alias/window2d.hh,
* mln/core/alias/window3d.hh,
* mln/core/concept/accumulator.hh,
* mln/core/concept/gdpoint.hh,
* mln/core/concept/gpoint.hh,
* mln/core/concept/image.hh,
* mln/core/concept/proxy.hh,
* mln/core/concept/site_set.hh,
* mln/core/concept/window.hh,
* mln/core/image/graph_window_if_piter.hh,
* mln/core/image/image1d.hh,
* mln/core/mixed_neighb.hh,
* mln/core/neighb.hh,
* mln/core/site_set/operators.hh,
* mln/core/w_window.hh,
* mln/fun/i2v/array.hh,
* mln/util/object_id.hh,
* mln/value/hsl.hh,
* mln/value/int_u.hh,
* mln/value/label.hh,
* mln/value/qt/rgb32.hh,
* mln/value/rgb.hh,
* mln/histo/array.hh,
* mln/util/array.hh: Move from_to_ overloads in the same namespace
as their first argument.
Conflicts:
milena/mln/convert/from_to.hh
---
milena/ChangeLog | 67 ++++++++++++++++++++++++++++++++++++++
milena/mln/convert/from_to.hh | 25 +++++++++-----
milena/mln/core/concept/proxy.hh | 6 ++--
3 files changed, 86 insertions(+), 12 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 21114eb..de897eb 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,70 @@
+2012-05-10 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Rely on Argument-Dependent Lookup (ADL) in from_to_ overloads.
+
+ * mln/accu/count_labels.hh,
+ * mln/convert/from_to.hxx,
+ * mln/convert/to.hh,
+ * mln/core/alias/point1d.hh,
+ * mln/core/alias/point2d.hh,
+ * mln/core/alias/point3d.hh,
+ * mln/core/dpoint.hh,
+ * mln/core/internal/neighborhood_base.hh,
+ * mln/core/point.hh,
+ * mln/core/site_set/p_centered.hh,
+ * mln/core/site_set/p_vaccess.hh,
+ * mln/fun/v2v/hsl_to_rgb.hh,
+ * mln/fun/v2v/rgb_to_hsl.hh,
+ * mln/io/magick/save.hh,
+ * mln/io/plot/save.hh,
+ * mln/labeling/blobs_and_compute.hh,
+ * mln/labeling/value_and_compute.hh,
+ * mln/make/w_window2d.hh,
+ * mln/win/multiple.hh,
+ * mln/win/multiple_size.hh,
+ * tests/accu/site_set/rectangularity.cc,
+ * tests/core/other/graph_elt_neighborhood.cc,
+ * tests/core/other/graph_elt_window.cc,
+ * tests/core/other/point_set_compatibility.cc,
+ * tests/draw/graph.cc: Update forward declarations and includes.
+
+ * mln/algebra/vec.hh,
+ * mln/convert/from_to.hh,
+ * mln/convert/impl/from_double_to_value.hh,
+ * mln/convert/impl/from_float_to_value.hh,
+ * mln/convert/impl/from_image_to_site_set.hh,
+ * mln/convert/impl/from_int_to_value.hh,
+ * mln/convert/impl/from_unsigned_to_value.hh,
+ * mln/convert/impl/from_value_to_value.hh,
+ * mln/core/alias/neighb2d.hh,
+ * mln/core/alias/neighb3d.hh,
+ * mln/core/alias/window1d.hh,
+ * mln/core/alias/window2d.hh,
+ * mln/core/alias/window3d.hh,
+ * mln/core/concept/accumulator.hh,
+ * mln/core/concept/gdpoint.hh,
+ * mln/core/concept/gpoint.hh,
+ * mln/core/concept/image.hh,
+ * mln/core/concept/proxy.hh,
+ * mln/core/concept/site_set.hh,
+ * mln/core/concept/window.hh,
+ * mln/core/image/graph_window_if_piter.hh,
+ * mln/core/image/image1d.hh,
+ * mln/core/mixed_neighb.hh,
+ * mln/core/neighb.hh,
+ * mln/core/site_set/operators.hh,
+ * mln/core/w_window.hh,
+ * mln/fun/i2v/array.hh,
+ * mln/util/object_id.hh,
+ * mln/value/hsl.hh,
+ * mln/value/int_u.hh,
+ * mln/value/label.hh,
+ * mln/value/qt/rgb32.hh,
+ * mln/value/rgb.hh,
+ * mln/histo/array.hh,
+ * mln/util/array.hh: Move from_to_ overloads in the same namespace
+ as their first argument.
+
2012-05-22 Guillaume Lazzara <z(a)lrde.epita.fr>
* demos/graph/region_adjacency_graph.cc: Add program arguments.
diff --git a/milena/mln/convert/from_to.hh b/milena/mln/convert/from_to.hh
index 272a47d..a3ec6d4 100644
--- a/milena/mln/convert/from_to.hh
+++ b/milena/mln/convert/from_to.hh
@@ -102,6 +102,7 @@ namespace mln
to = from;
}
+
// Object -> Object (F not convertible towards T)
// No conversion exists!
template <typename F, typename T>
@@ -116,15 +117,6 @@ namespace mln
}
- // Object -> Object
- template <typename T>
- inline
- void
- from_to_(const Object<T>& from, Object<T>& to)
- {
- exact(to) = exact(from);
- }
-
namespace convert
{
@@ -208,6 +200,21 @@ namespace mln
exact(from), exact(to));
}
+ // Object -> Object
+ template <typename T>
+ inline
+ void
+ from_to_dispatch(const Object<T>& from, Object<T>& to)
+ {
+ // // Here we would like to call from_to_ overloads in order
+ // to let the user specify its own conversion
+ // function. However, doing so may lead to ambiguous
+ // prototypes between from_to_(Object<>, Object<>) and
+ // from_to_(T, T).
+ // from_to_(exact(from), exact(to));
+ exact(to) = exact(from);
+ }
+
// Dispatch entry points.
diff --git a/milena/mln/core/concept/proxy.hh b/milena/mln/core/concept/proxy.hh
index 8c4d2e9..43aed15 100644
--- a/milena/mln/core/concept/proxy.hh
+++ b/milena/mln/core/concept/proxy.hh
@@ -186,7 +186,7 @@ namespace mln
// Disambiguate between (Proxy Op Object) and (Object Op Literal).
-
+
template < template <class, class> class Op,
typename P, typename L >
struct set_binary_< Op, mln::Proxy, P, mln::Literal, L >
@@ -229,7 +229,7 @@ namespace mln
typedef q_subject;
q_subject subj_();
*/
-
+
protected:
Proxy();
};
@@ -261,7 +261,7 @@ namespace mln
template <typename T>
typename mln::internal::unproxy_rec_<const T>::ret
unproxy_rec(const T& t);
-
+
// operator <<
--
1.7.2.5
1
0

olena-2.0-113-gfa8caca demos/graph/region_adjacency_graph.cc: Add program arguments.
by Guillaume Lazzara 23 Aug '12
by Guillaume Lazzara 23 Aug '12
23 Aug '12
---
milena/ChangeLog | 4 ++
milena/demos/graph/region_adjacency_graph.cc | 41 +++++++++++++++++++-------
2 files changed, 34 insertions(+), 11 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 67cf83a..21114eb 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,7 @@
+2012-05-22 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ * demos/graph/region_adjacency_graph.cc: Add program arguments.
+
2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr>
* mln/core/internal/image_base.hh: Improve documentation.
diff --git a/milena/demos/graph/region_adjacency_graph.cc b/milena/demos/graph/region_adjacency_graph.cc
index 44a2f17..32d05b0 100644
--- a/milena/demos/graph/region_adjacency_graph.cc
+++ b/milena/demos/graph/region_adjacency_graph.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2012 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -67,6 +68,9 @@
#include <mln/math/diff_abs.hh>
#include <mln/debug/draw_graph.hh>
+#include <mln/debug/filename.hh>
+#include <mln/data/transform.hh>
+#include <mln/fun/v2v/rgb_to_int_u.hh>
namespace mln
{
@@ -149,27 +153,42 @@ namespace mln
}
-int main()
+int main(int argc, char *argv[])
{
using namespace mln;
using value::int_u8;
using value::rgb8;
using value::label_16;
- image2d<int_u8> input_pgm;
- io::pgm::load(input_pgm, "house.pgm");
+ if (argc != 3 && argc != 4)
+ {
+ std::cout << "Usage: " << argv[0] << " <input.*> <output_prefix>"
+ << " [closing_area_value (default:25)]" << std::endl;
+ return 1;
+ }
+ /// Load input image.
image2d<rgb8> input_ppm;
- io::ppm::load(input_ppm, "house.ppm");
+ io::ppm::load(input_ppm, argv[1]);
+
+ /// Convert input image to graylevel image.
+ image2d<value::int_u8>
+ input_pgm = data::transform(input_ppm, fun::v2v::rgb_to_int_u<8>());
+
+ /// Set output filename prefix.
+ debug::internal::filename_prefix = argv[2];
+ unsigned area_value = 25;
+ if (argc == 4)
+ area_value = atoi(argv[3]);
/// Gradient of the gray level image.
image2d<int_u8> grad = morpho::gradient(input_pgm, win_c4p());
- io::pgm::save(grad, "tmp_grad_c4p.pgm");
+ io::pgm::save(grad, debug::filename("grad_c4p.pgm"));
/// Closing of the gradient.
- image2d<int_u8> clo = morpho::closing::area(grad, c4(), 25);
- io::pgm::save(clo, "tmp_clo_a100.pgm");
+ image2d<int_u8> clo = morpho::closing::area(grad, c4(), area_value);
+ io::pgm::save(clo, debug::filename("clo_a100.pgm"));
/// Watershed on the closing image.
label_16 nbasins;
@@ -178,12 +197,12 @@ int main()
/// Output: A watershed image where each basin value is set to the basin
/// mean value in the original ppm image.
io::ppm::save(labeling::mean_values(input_ppm, wshed, nbasins),
- "tmp_wshed_mean_colors.ppm");
+ debug::filename("wshed_mean_colors.ppm"));
/// Set watershed line value to yellow.
data::fill((input_ppm | (pw::value(wshed) == 0u)).rw(), literal::yellow);
- io::ppm::save(input_ppm, "tmp_wshed_color.ppm");
+ io::ppm::save(input_ppm, debug::filename("wshed_color.ppm"));
/// Build region adjacency graph.
@@ -210,5 +229,5 @@ int main()
mln_VAR(ima_e, make::edge_image(ima_v, dist()));
io::ppm::save(make_debug_graph_image(input_ppm, ima_v, ima_e, literal::white),
- "tmp_wst_rag_graph_image_white.ppm");
+ debug::filename("wst_rag_graph_image_white.ppm"));
}
--
1.7.2.5
1
0
* scribo/binarization/internal/local_threshold_core.hh: Add a
missing include.
* scribo/debug/logger.hh: Fix attributes initialization order.
* scribo/text/paragraphs_closing.hh: Fix a warning related to an
unused-variable.
---
scribo/ChangeLog | 12 ++++++++++++
.../binarization/internal/local_threshold_core.hh | 1 +
scribo/scribo/debug/logger.hh | 4 ++--
scribo/scribo/text/paragraphs_closing.hh | 4 ++--
4 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 6982e6b..e0f9201 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,17 @@
2012-05-22 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Small fixes in Scribo.
+
+ * scribo/binarization/internal/local_threshold_core.hh: Add a
+ missing include.
+
+ * scribo/debug/logger.hh: Fix attributes initialization order.
+
+ * scribo/text/paragraphs_closing.hh: Fix a warning related to an
+ unused-variable.
+
+2012-05-22 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add a better support for different k values in Sauvola Multiscale.
* scribo/scribo/binarization/internal/sauvola_ms_functor.hh,
diff --git a/scribo/scribo/binarization/internal/local_threshold_core.hh b/scribo/scribo/binarization/internal/local_threshold_core.hh
index 7589499..1ab7385 100644
--- a/scribo/scribo/binarization/internal/local_threshold_core.hh
+++ b/scribo/scribo/binarization/internal/local_threshold_core.hh
@@ -44,6 +44,7 @@
# include <scribo/util/integral_sum_sum2_functor.hh>
# include <scribo/util/compute_sub_domains.hh>
+# include <scribo/debug/logger.hh>
# ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
# include <scribo/binarization/internal/local_threshold_debug.hh>
# include <mln/io/pgm/save.hh>
diff --git a/scribo/scribo/debug/logger.hh b/scribo/scribo/debug/logger.hh
index cac2770..95bfeb3 100644
--- a/scribo/scribo/debug/logger.hh
+++ b/scribo/scribo/debug/logger.hh
@@ -243,8 +243,8 @@ namespace scribo
: level_(None),
verbose_mode_(Mute),
default_verbose_mode_(Low),
- stream_(std::cerr),
- verbose_prefix_("LOG: ")
+ verbose_prefix_("LOG: "),
+ stream_(std::cerr)
{
// Magick::InitializeMagick(0);
}
diff --git a/scribo/scribo/text/paragraphs_closing.hh b/scribo/scribo/text/paragraphs_closing.hh
index 476c14e..9dd28d2 100644
--- a/scribo/scribo/text/paragraphs_closing.hh
+++ b/scribo/scribo/text/paragraphs_closing.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Copyright (C) 2009, 2010, 2011, 2012 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of Olena.
@@ -207,7 +207,7 @@ namespace scribo
const paragraph_info<L>& current_par = parset(p);
const mln::util::array<line_id_t>& line_ids = current_par.line_ids();
- line_id_t last_id = line_ids[0];
+ //line_id_t last_id = line_ids[0];
for_all_elements(i, line_ids)
{
const line_id_t& line_id = line_ids(i);
--
1.7.2.5
1
0

olena-2.0-111-gdb78cd2 Add a better support for different k values in Sauvola Multiscale.
by Guillaume Lazzara 23 Aug '12
by Guillaume Lazzara 23 Aug '12
23 Aug '12
* scribo/scribo/binarization/internal/sauvola_ms_functor.hh,
* scribo/scribo/binarization/sauvola_ms.hh,
* scribo/scribo/binarization/sauvola_ms_split.hh,
* scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh,
* scribo/scribo/toolchain/text_in_doc_preprocess.hh: Make use of
k2, k3 and k4 variables.
* scribo/src/binarization/sauvola_ms.cc,
* scribo/src/binarization/sauvola_ms_debug.cc,
* scribo/src/binarization/sauvola_ms_fg.cc,
* scribo/src/binarization/sauvola_ms_split.cc: Fix program
arguments.
---
scribo/ChangeLog | 17 +++++++
.../binarization/internal/sauvola_ms_functor.hh | 16 ++++---
scribo/scribo/binarization/sauvola_ms.hh | 48 ++++++++++---------
scribo/scribo/binarization/sauvola_ms_split.hh | 41 ++++++++++++-----
.../internal/text_in_doc_preprocess_functor.hh | 28 +++++++++---
scribo/scribo/toolchain/text_in_doc_preprocess.hh | 46 +++++++++++++++----
scribo/src/binarization/sauvola_ms.cc | 2 +-
scribo/src/binarization/sauvola_ms_debug.cc | 27 ++++++++---
scribo/src/binarization/sauvola_ms_fg.cc | 31 +++++++++++--
scribo/src/binarization/sauvola_ms_split.cc | 29 +++++++++---
10 files changed, 207 insertions(+), 78 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 61e6c7e..6982e6b 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,20 @@
+2012-05-22 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Add a better support for different k values in Sauvola Multiscale.
+
+ * scribo/scribo/binarization/internal/sauvola_ms_functor.hh,
+ * scribo/scribo/binarization/sauvola_ms.hh,
+ * scribo/scribo/binarization/sauvola_ms_split.hh,
+ * scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh,
+ * scribo/scribo/toolchain/text_in_doc_preprocess.hh: Make use of
+ k2, k3 and k4 variables.
+
+ * scribo/src/binarization/sauvola_ms.cc,
+ * scribo/src/binarization/sauvola_ms_debug.cc,
+ * scribo/src/binarization/sauvola_ms_fg.cc,
+ * scribo/src/binarization/sauvola_ms_split.cc: Fix program
+ arguments.
+
2012-05-11 Guillaume Lazzara <z(a)lrde.epita.fr>
Add a default verbose mode in debug::logger.
diff --git a/scribo/scribo/binarization/internal/sauvola_ms_functor.hh b/scribo/scribo/binarization/internal/sauvola_ms_functor.hh
index 3411d1b..020caa9 100644
--- a/scribo/scribo/binarization/internal/sauvola_ms_functor.hh
+++ b/scribo/scribo/binarization/internal/sauvola_ms_functor.hh
@@ -54,9 +54,9 @@ namespace scribo
namespace internal
{
- double k2;
- double k3;
- double k4;
+ double k2 = SCRIBO_DEFAULT_SAUVOLA_K;
+ double k3 = SCRIBO_DEFAULT_SAUVOLA_K;
+ double k4 = SCRIBO_DEFAULT_SAUVOLA_K;
using namespace mln;
@@ -91,7 +91,9 @@ namespace scribo
sauvola_formula formula_;
- sauvola_ms_functor(const I& input, double K, double R, const image2d<value::int_u8>&e_2, unsigned i, unsigned q);
+ sauvola_ms_functor(const I& input, double R,
+ const image2d<value::int_u8>&e_2,
+ unsigned i, unsigned q);
void exec(double mean, double stddev);
void end_of_row(int row);
@@ -113,13 +115,15 @@ namespace scribo
template <typename I>
- sauvola_ms_functor<I>::sauvola_ms_functor(const I& input, double K, double R, const image2d<value::int_u8>&e_2, unsigned i, unsigned q)
+ sauvola_ms_functor<I>::sauvola_ms_functor(const I& input,
+ double R,
+ const image2d<value::int_u8>&e_2,
+ unsigned i, unsigned q)
: input(input),
e_2(e_2),
i(i),
q(q),
pxl(input),
- //K_(K),
R_(R),
i_(i)
{
diff --git a/scribo/scribo/binarization/sauvola_ms.hh b/scribo/scribo/binarization/sauvola_ms.hh
index b1e8144..1f120cc 100644
--- a/scribo/scribo/binarization/sauvola_ms.hh
+++ b/scribo/scribo/binarization/sauvola_ms.hh
@@ -69,6 +69,7 @@
# include <scribo/util/integral_sub_sum_sum2_functor.hh>
# include <scribo/util/compute_sub_domains.hh>
+# include <scribo/debug/logger.hh>
# ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
# include <scribo/binarization/internal/local_threshold_debug.hh>
# include <mln/io/pgm/save.hh>
@@ -96,10 +97,10 @@ namespace scribo
\param[in] w_1 The window size used to compute stats.
\param[in] s The scale factor used for the first subscaling.
\param[in] lambda_min_1 Size of the objects kept at scale 1.
- \param[in] K Sauvola's formulae parameter.
\param[out] integral_sum_sum_2 Integral image of sum and squared
sum.
+ Sauvola's formula parameter K is set to 0.34.
\p w_1 and \p lambda_min_1 are expressed according to the image
at scale 0, i.e. the original size.
@@ -108,22 +109,24 @@ namespace scribo
template <typename I>
mln_ch_value(I,bool)
sauvola_ms(const Image<I>& input_1_, unsigned w_1,
- unsigned s, double K,
+ unsigned s,
image2d<mln::util::couple<double,double> >& integral_sum_sum_2);
/// \overload
/// The integral image is not returned.
+ /// K is set to 0.34.
//
template <typename I>
mln_ch_value(I,bool)
- sauvola_ms(const Image<I>& input_1_, unsigned w_1, unsigned s, double K);
+ sauvola_ms(const Image<I>& input_1_, unsigned w_1, unsigned s);
/// \overload
- /// K is set to 0.34.
+ /// Allow to specify a different k parameter for each scale.
//
template <typename I>
mln_ch_value(I,bool)
- sauvola_ms(const Image<I>& input_1, unsigned w_1, unsigned s);
+ sauvola_ms(const Image<I>& input_1, unsigned w_1, unsigned s,
+ double k2, double k3, double k4);
@@ -154,8 +157,7 @@ namespace scribo
unsigned lambda_min, unsigned lambda_max,
unsigned s,
unsigned q, unsigned i, unsigned w,
- const image2d<mln::util::couple<double,double> >& integral_sum_sum_2,
- double K)
+ const image2d<mln::util::couple<double,double> >& integral_sum_sum_2)
{
typedef image2d<int_u8> I;
typedef point2d P;
@@ -170,7 +172,7 @@ namespace scribo
// 1st pass
scribo::binarization::internal::sauvola_ms_functor< image2d<int_u8> >
- f(sub, K, SCRIBO_DEFAULT_SAUVOLA_R, e_2, i, q);
+ f(sub, SCRIBO_DEFAULT_SAUVOLA_R, e_2, i, q);
scribo::canvas::integral_browsing(integral_sum_sum_2,
ratio,
w_local_w, w_local_h,
@@ -783,7 +785,7 @@ namespace scribo
template <typename I>
mln_ch_value(I,bool)
sauvola_ms(const Image<I>& input_1_, unsigned w_1,
- unsigned s, double K,
+ unsigned s,
image2d<mln::util::couple<double,double> >& integral_sum_sum_2)
{
trace::entering("scribo::binarization::sauvola_ms");
@@ -912,8 +914,7 @@ namespace scribo
mln_max(unsigned),
s,
q, i, w_work,
- integral_sum_sum_2,
- K);
+ integral_sum_sum_2);
}
// Other scales -> maximum and minimum component size.
@@ -929,8 +930,7 @@ namespace scribo
// (8096 / 36) * coeff,
s,
q, i, w_work,
- integral_sum_sum_2,
- K);
+ integral_sum_sum_2);
}
}
@@ -943,8 +943,7 @@ namespace scribo
win_w[2] * 3 * coeff,
// (810 / 9) * coeff,
s, 1, 2, w_work,
- integral_sum_sum_2,
- K);
+ integral_sum_sum_2);
}
scribo::debug::logger().stop_local_time_logging("3. Multi-scale processing -");
@@ -1008,8 +1007,7 @@ namespace scribo
template <typename I>
mln_ch_value(I,bool)
- sauvola_ms(const Image<I>& input_1_, unsigned w_1,
- unsigned s, double K,
+ sauvola_ms(const Image<I>& input_1_, unsigned w_1, unsigned s,
image2d<mln::util::couple<double,double> >& integral_sum_sum_2)
{
trace::entering("scribo::binarization::sauvola_ms");
@@ -1020,7 +1018,7 @@ namespace scribo
mlc_is_not(mln_value(I), bool)::check();
mln_ch_value(I,bool)
- output = impl::generic::sauvola_ms(exact(input_1_), w_1, s, K,
+ output = impl::generic::sauvola_ms(exact(input_1_), w_1, s,
integral_sum_sum_2);
trace::exiting("scribo::binarization::sauvola_ms");
@@ -1029,8 +1027,7 @@ namespace scribo
template <typename I>
mln_ch_value(I,bool)
- sauvola_ms(const Image<I>& input_1_, unsigned w_1,
- unsigned s, double K)
+ sauvola_ms(const Image<I>& input_1_, unsigned w_1, unsigned s)
{
trace::entering("scribo::binarization::sauvola_ms");
@@ -1043,7 +1040,7 @@ namespace scribo
integral_t integral_sum_sum_2;
mln_ch_value(I,bool)
- output = sauvola_ms(input_1_, w_1, s, K, integral_sum_sum_2);
+ output = sauvola_ms(input_1_, w_1, s, integral_sum_sum_2);
trace::exiting("scribo::binarization::sauvola_ms");
return output;
@@ -1052,9 +1049,14 @@ namespace scribo
template <typename I>
mln_ch_value(I,bool)
- sauvola_ms(const Image<I>& input_1, unsigned w_1, unsigned s)
+ sauvola_ms(const Image<I>& input_1, unsigned w_1, unsigned s,
+ double k2, double k3, double k4)
{
- return sauvola_ms(input_1, w_1, s, SCRIBO_DEFAULT_SAUVOLA_K);
+ binarization::internal::k2 = k2;
+ binarization::internal::k3 = k3;
+ binarization::internal::k4 = k4;
+
+ return sauvola_ms(input_1, w_1, s);
}
diff --git a/scribo/scribo/binarization/sauvola_ms_split.hh b/scribo/scribo/binarization/sauvola_ms_split.hh
index ff16a4e..cf74dd1 100644
--- a/scribo/scribo/binarization/sauvola_ms_split.hh
+++ b/scribo/scribo/binarization/sauvola_ms_split.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2010, 2011, 2012 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -59,7 +59,9 @@ namespace scribo
\param[in] min_ntrue A site is set to 'True' in the output if it
is set to 'True' at least \p min_ntrue
components. Possible values: 1, 2, 3.
- \param[in] K Sauvola's formula parameter.
+ \param[in] k2 Sauvola's formula parameter.
+ \param[in] k3 Sauvola's formula parameter.
+ \param[in] k4 Sauvola's formula parameter.
\p w_1 is expressed according to the image at scale 0, i.e. the
original size.
@@ -69,12 +71,19 @@ namespace scribo
template <typename I>
mln_ch_value(I, bool)
sauvola_ms_split(const Image<I>& input_1_, unsigned w_1,
- unsigned s, unsigned min_ntrue,
- double K);
+ unsigned s, unsigned min_ntrue, double k2,
+ double k3, double k4);
+
+ /// \overload
+ /// k2, k3 and k4 are set to \p K.
+ template <typename I>
+ mln_ch_value(I, bool)
+ sauvola_ms_split(const Image<I>& input_1_, unsigned w_1,
+ unsigned s, unsigned min_ntrue, double K);
/// \overload
- /// K is set to 0.34.
+ /// k2, k3 and k4 are set to 0.34.
template <typename I>
mln_ch_value(I, bool)
sauvola_ms_split(const Image<I>& input_1_, unsigned w_1,
@@ -88,8 +97,8 @@ namespace scribo
template <typename I>
mln_ch_value(I, bool)
sauvola_ms_split(const Image<I>& input_1_, unsigned w_1,
- unsigned s, unsigned min_ntrue,
- double K)
+ unsigned s, unsigned min_ntrue, double k2,
+ double k3, double k4)
{
trace::entering("scribo::binarization::sauvola_ms_split");
@@ -107,9 +116,9 @@ namespace scribo
bin_t r_b, g_b, b_b;
- r_b = sauvola_ms(r_i, w_1, s, K);
- g_b = sauvola_ms(g_i, w_1, s, K);
- b_b = sauvola_ms(b_i, w_1, s, K);
+ r_b = sauvola_ms(r_i, w_1, s);
+ g_b = sauvola_ms(g_i, w_1, s);
+ b_b = sauvola_ms(b_i, w_1, s);
border::resize(r_b, input_1.border());
border::resize(g_b, input_1.border());
@@ -151,6 +160,16 @@ namespace scribo
template <typename I>
mln_ch_value(I, bool)
sauvola_ms_split(const Image<I>& input_1, unsigned w_1,
+ unsigned s, unsigned min_ntrue, double K)
+ {
+ return sauvola_ms_split(input_1, w_1, s, min_ntrue,
+ K, K, K);
+ }
+
+
+ template <typename I>
+ mln_ch_value(I, bool)
+ sauvola_ms_split(const Image<I>& input_1, unsigned w_1,
unsigned s, unsigned min_ntrue)
{
return sauvola_ms_split(input_1, w_1, s, min_ntrue,
diff --git a/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh b/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh
index d58b4b2..aea02d8 100644
--- a/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh
+++ b/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2010, 2011, 2012 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -86,10 +86,17 @@ namespace scribo
Few parameters can be set for algorithms:
- - Sauvola:
+ - Sauvola Multi-scale:
* sauvola_win, the window size used in Sauvola based
algorithms (default 101).
- * sauvola_K, a user parameter for Sauvola's threshold formula
+ * sauvola_K2, a user parameter for Sauvola's threshold formula
+ at scale 2.
+ (default 0.34).
+ * sauvola_K3, a user parameter for Sauvola's threshold formula
+ at scale 3.
+ (default 0.34).
+ * sauvola_K4, a user parameter for Sauvola's threshold formula
+ at scale 4.
(default 0.34).
- Extract background/foreground
@@ -126,7 +133,9 @@ namespace scribo
Binarization_Algo binarization_algo;
unsigned sauvola_win;
- double sauvola_K;
+ double sauvola_k2;
+ double sauvola_k3;
+ double sauvola_k4;
unsigned lambda;
// Results
@@ -162,7 +171,9 @@ namespace scribo
enable_denoising(false),
binarization_algo(SauvolaMs),
sauvola_win(101),
- sauvola_K(0.34),
+ sauvola_k2(0.34),
+ sauvola_k3(0.34),
+ sauvola_k4(0.34),
lambda(0)
{
}
@@ -252,7 +263,10 @@ namespace scribo
{
on_new_progress_label("Binarization (Sauvola Multi-scale)");
output = scribo::binarization::sauvola_ms(intensity_ima,
- sauvola_win, 3, sauvola_K);
+ sauvola_win, 3,
+ sauvola_k2,
+ sauvola_k3,
+ sauvola_k4);
}
else // binarization_algo == Convert
{
diff --git a/scribo/scribo/toolchain/text_in_doc_preprocess.hh b/scribo/scribo/toolchain/text_in_doc_preprocess.hh
index efa03dd..eb49bde 100644
--- a/scribo/scribo/toolchain/text_in_doc_preprocess.hh
+++ b/scribo/scribo/toolchain/text_in_doc_preprocess.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2010, 2011, 2012 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -55,7 +55,8 @@ namespace scribo
\param[in] input An image.
\param[in] enable_fg_bg Enable/Disable background removal.
- \param[in] K Binarization threshold parameter. (Default 0.34)
+ \param[in] K Binarization threshold parameter. Use the same
+ value for all scales. (Default 0.34)
If \p enable_fg_bg is set to 'True' then a background removal is
performed. Its parameter lambda is automatically set according
@@ -93,10 +94,14 @@ namespace scribo
bool verbose = false);
/*! \brief Preprocess a document before looking for its content.
+ This methods relies on a multi-scale implementation of Sauvola's
+ binarization.
\param[in] input An image.
\param[in] lambda Parameter to the background removal.
- \param[in] K Binarization threshold parameter. (Default 0.34)
+ \param[in] k2 Binarization threshold parameter for scale 2. (Default 0.34)
+ \param[in] k3 Binarization threshold parameter for scale 3. (Default 0.34)
+ \param[in] k4 Binarization threshold parameter for scale 4. (Default 0.34)
\param[in,out] fg The foreground layer of \p input.
If lambda is set to '0' no background removal is
@@ -107,8 +112,16 @@ namespace scribo
template <typename I>
mln_ch_value(I,bool)
text_in_doc_preprocess(const Image<I>& input, unsigned lambda,
- double K, bool enable_fg_bg, Image<I>& fg,
- bool enable_deskew, bool verbose = false);
+ double k2, double k3, double k4, bool enable_fg_bg,
+ Image<I>& fg, bool enable_deskew,
+ bool verbose = false);
+
+ /// \overload
+ template <typename I>
+ mln_ch_value(I,bool)
+ text_in_doc_preprocess(const Image<I>& input_, unsigned lambda,
+ bool enable_fg_bg, Image<I>& fg,
+ bool enable_deskew, bool verbose);
# ifndef MLN_INCLUDE_ONLY
@@ -137,7 +150,7 @@ namespace scribo
mln_concrete(I) tmp_fg;
mln_ch_value(I,bool)
- output = text_in_doc_preprocess(input, lambda, K,
+ output = text_in_doc_preprocess(input, lambda, K, K, K,
enable_fg_bg, tmp_fg, enable_deskew, verbose);
return output;
@@ -156,8 +169,8 @@ namespace scribo
template <typename I>
mln_ch_value(I,bool)
text_in_doc_preprocess(const Image<I>& input_, unsigned lambda,
- double K, bool enable_fg_bg, Image<I>& fg,
- bool enable_deskew, bool verbose)
+ double k2, double k3, double k4, bool enable_fg_bg,
+ Image<I>& fg, bool enable_deskew, bool verbose)
{
trace::entering("scribo::toolchain::text_in_doc_preprocess");
@@ -167,7 +180,9 @@ namespace scribo
internal::text_in_doc_preprocess_functor<I> f;
// Setup functor.
- f.sauvola_K = K;
+ f.sauvola_k2 = k2;
+ f.sauvola_k3 = k3;
+ f.sauvola_k4 = k4;
f.enable_fg_extraction = enable_fg_bg;
f.lambda = lambda;
f.enable_deskew = enable_deskew;
@@ -182,6 +197,17 @@ namespace scribo
}
+ template <typename I>
+ mln_ch_value(I,bool)
+ text_in_doc_preprocess(const Image<I>& input, unsigned lambda,
+ bool enable_fg_bg, Image<I>& fg,
+ bool enable_deskew, bool verbose)
+ {
+ text_in_doc_preprocess(input, lambda, SCRIBO_DEFAULT_SAUVOLA_K,
+ SCRIBO_DEFAULT_SAUVOLA_K, SCRIBO_DEFAULT_SAUVOLA_K,
+ enable_fg_bg, fg, enable_deskew, verbose);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/src/binarization/sauvola_ms.cc b/scribo/src/binarization/sauvola_ms.cc
index 685337c..fc6a5a9 100644
--- a/scribo/src/binarization/sauvola_ms.cc
+++ b/scribo/src/binarization/sauvola_ms.cc
@@ -143,7 +143,7 @@ int main(int argc, char *argv[])
// Binarize
image2d<bool>
- output = scribo::binarization::sauvola_ms(input_1_gl, w_1, s, k);
+ output = scribo::binarization::sauvola_ms(input_1_gl, w_1, s);
scribo::debug::logger().stop_local_time_logging("Binarized in");
diff --git a/scribo/src/binarization/sauvola_ms_debug.cc b/scribo/src/binarization/sauvola_ms_debug.cc
index 251f0e8..d4dcc14 100644
--- a/scribo/src/binarization/sauvola_ms_debug.cc
+++ b/scribo/src/binarization/sauvola_ms_debug.cc
@@ -64,7 +64,7 @@ static const scribo::debug::opt_data opt_desc[] =
// name, description, arguments, check args function, number of args, default arg
{ "debug-prefix", "Enable debug image outputs. Prefix image name with that "
"given prefix.", "<prefix>", 0, 1, 0 },
- { "k", "Sauvola's formulae parameter", "<value>", 0, 1, "0.34" },
+ { "all-k", "Sauvola's formulae parameter", "<value>", 0, 1, "0.34" },
{ "k2", "Sauvola's formulae parameter", "<value>", 0, 1, "0.20" },
{ "k3", "Sauvola's formulae parameter", "<value>", 0, 1, "0.30" },
@@ -136,14 +136,27 @@ int main(int argc, char *argv[])
unsigned w_1 = atoi(options.opt_value("win-size").c_str());
// First subsampling scale.
unsigned s = atoi(options.opt_value("s").c_str());
- double k = atof(options.opt_value("k").c_str());
- binarization::internal::k2 = atof(options.opt_value("k2").c_str());
- binarization::internal::k3 = atof(options.opt_value("k3").c_str());
- binarization::internal::k4 = atof(options.opt_value("k4").c_str());
+
+ // Setting k parameter.
+ double k = atof(options.opt_value("all-k").c_str());
+ binarization::internal::k2 = k;
+ binarization::internal::k3 = k;
+ binarization::internal::k4 = k;
+
+ // Override k parameter for specific scales.
+ if (options.is_set("k2"))
+ binarization::internal::k2 = atof(options.opt_value("k2").c_str());
+ if (options.is_set("k3"))
+ binarization::internal::k3 = atof(options.opt_value("k3").c_str());
+ if (options.is_set("k4"))
+ binarization::internal::k4 = atof(options.opt_value("k4").c_str());
scribo::debug::logger() << "Using w_1=" << w_1 << " - s=" << s
- << " - k=" << k << std::endl;
+ << " - k2=" << binarization::internal::k2
+ << " - k3=" << binarization::internal::k3
+ << " - k4=" << binarization::internal::k4
+ << std::endl;
scribo::binarization::internal::scale_image_output = "scale_image.pgm";
scribo::binarization::internal::threshold_image_output = "threshold_image.pbm";
@@ -165,7 +178,7 @@ int main(int argc, char *argv[])
// Binarize.
image2d<bool>
- output = scribo::binarization::sauvola_ms(input_1_gl, w_1, s, k);
+ output = scribo::binarization::sauvola_ms(input_1_gl, w_1, s);
scribo::debug::logger().stop_local_time_logging("Binarized in");
diff --git a/scribo/src/binarization/sauvola_ms_fg.cc b/scribo/src/binarization/sauvola_ms_fg.cc
index 98206a8..9f47b7d 100644
--- a/scribo/src/binarization/sauvola_ms_fg.cc
+++ b/scribo/src/binarization/sauvola_ms_fg.cc
@@ -60,7 +60,12 @@ static const scribo::debug::opt_data opt_desc[] =
// name, description, arguments, check args function, number of args, default arg
{ "debug-prefix", "Enable debug image outputs. Prefix image name with that "
"given prefix.", "<prefix>", 0, 1, 0 },
- { "k", "Sauvola's formulae parameter", "<value>", 0, 1, "0.34" },
+ { "all-k", "Sauvola's formulae parameter", "<value>", 0, 1, "0.34" },
+
+ { "k2", "Sauvola's formulae parameter", "<value>", 0, 1, "0.20" },
+ { "k3", "Sauvola's formulae parameter", "<value>", 0, 1, "0.30" },
+ { "k4", "Sauvola's formulae parameter", "<value>", 0, 1, "0.50" },
+
{ "lambda", "Set the maximum area of the background objects. It is only "
"useful if fg-extraction is enabled.", "<size>", 0, 1, "1024" },
{ "s", "First subsampling ratio. Possible values: 2 or 3.", "ratio",
@@ -100,10 +105,26 @@ int main(int argc, char *argv[])
// First subsampling scale.
unsigned s = atoi(options.opt_value("s").c_str());
- double k = atof(options.opt_value("k").c_str());
- scribo::debug::logger() << "Using w_1=" << w_1 << " - s=" << s << " - k="
- << k << " - lambda=" << lambda << std::endl;
+ // Setting k parameter.
+ double k = atof(options.opt_value("all-k").c_str());
+ binarization::internal::k2 = k;
+ binarization::internal::k3 = k;
+ binarization::internal::k4 = k;
+
+ // Override k parameter for specific scales.
+ if (options.is_set("k2"))
+ binarization::internal::k2 = atof(options.opt_value("k2").c_str());
+ if (options.is_set("k3"))
+ binarization::internal::k3 = atof(options.opt_value("k3").c_str());
+ if (options.is_set("k4"))
+ binarization::internal::k4 = atof(options.opt_value("k4").c_str());
+
+ scribo::debug::logger() << "Using w_1=" << w_1 << " - s=" << s
+ << " - k2=" << binarization::internal::k2
+ << " - k3=" << binarization::internal::k3
+ << " - k4=" << binarization::internal::k4
+ << std::endl;
Magick::InitializeMagick(0);
@@ -121,7 +142,7 @@ int main(int argc, char *argv[])
// Binarize
image2d<bool>
- output = scribo::binarization::sauvola_ms(fg_gl, w_1, s, k);
+ output = scribo::binarization::sauvola_ms(fg_gl, w_1, s);
io::pbm::save(output, options.arg("output.pbm"));
}
diff --git a/scribo/src/binarization/sauvola_ms_split.cc b/scribo/src/binarization/sauvola_ms_split.cc
index f1cc490..21915e9 100644
--- a/scribo/src/binarization/sauvola_ms_split.cc
+++ b/scribo/src/binarization/sauvola_ms_split.cc
@@ -55,7 +55,7 @@ static const scribo::debug::opt_data opt_desc[] =
// name, description, arguments, check args function, number of args, default arg
{ "debug-prefix", "Enable debug image outputs. Prefix image name with that "
"given prefix.", "<prefix>", 0, 1, 0 },
- { "k", "Sauvola's formulae parameter. Set it globally for all scales.",
+ { "all-k", "Sauvola's formulae parameter. Set it globally for all scales.",
"<value>", 0, 1, "0.34" },
{ "k2", "Sauvola's formulae parameter", "<value>", 0, 1, "0.20" },
@@ -98,15 +98,28 @@ int main(int argc, char *argv[])
// First subsampling scale.
unsigned s = atoi(options.opt_value("s").c_str());
- double k = atof(options.opt_value("k").c_str());
unsigned min_ntrue = atoi(options.opt_value("min-ntrue").c_str());
- binarization::internal::k2 = atof(options.opt_value("k2").c_str());
- binarization::internal::k3 = atof(options.opt_value("k3").c_str());
- binarization::internal::k4 = atof(options.opt_value("k4").c_str());
- scribo::debug::logger() << "Using w_1=" << w_1 << " - s=" << s << " - k="
- << k << " - min_ntrue=" << min_ntrue << std::endl;
+ // Setting k parameter.
+ double k = atof(options.opt_value("all-k").c_str());
+ binarization::internal::k2 = k;
+ binarization::internal::k3 = k;
+ binarization::internal::k4 = k;
+
+ // Override k parameter for specific scales.
+ if (options.is_set("k2"))
+ binarization::internal::k2 = atof(options.opt_value("k2").c_str());
+ if (options.is_set("k3"))
+ binarization::internal::k3 = atof(options.opt_value("k3").c_str());
+ if (options.is_set("k4"))
+ binarization::internal::k4 = atof(options.opt_value("k4").c_str());
+
+ scribo::debug::logger() << "Using w_1=" << w_1 << " - s=" << s
+ << " - k2=" << binarization::internal::k2
+ << " - k3=" << binarization::internal::k3
+ << " - k4=" << binarization::internal::k4
+ << std::endl;
Magick::InitializeMagick(0);
@@ -114,7 +127,7 @@ int main(int argc, char *argv[])
io::magick::load(input_1, options.arg("input.*"));
image2d<bool>
- output = scribo::binarization::sauvola_ms_split(input_1, w_1, s, min_ntrue, k);
+ output = scribo::binarization::sauvola_ms_split(input_1, w_1, s, min_ntrue);
io::pbm::save(output, options.arg("output.pbm"));
}
--
1.7.2.5
1
0