https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Sandbox: ICP: 'lazy'_map.
* sandbox/jardonnet/test/icp.cc: Update.
* sandbox/jardonnet/test/reduce.cc: New: image scaling.
* sandbox/jardonnet/test/01.pbm,
* sandbox/jardonnet/test/02.pbm: New: test images.
* sandbox/jardonnet/registration/icp.hh: Use type lazy_map instead of std::pair, in order
to use sp�cific constructors.
* sandbox/jardonnet/registration/projection.hh: update.
* sandbox/jardonnet/registration/tools.hh: Add tools for boxes (to include in Milena?).
registration/icp.hh | 25 +++++++++--------
registration/projection.hh | 27 ++++--------------
registration/tools.hh | 66 +++++++++++++++++++++++++++++++++++++++++++++
test/reduce.cc | 26 +++++++++++++++++
4 files changed, 113 insertions(+), 31 deletions(-)
Index: sandbox/jardonnet/test/icp.cc
Index: sandbox/jardonnet/test/reduce.cc
--- sandbox/jardonnet/test/reduce.cc (revision 0)
+++ sandbox/jardonnet/test/reduce.cc (revision 0)
@@ -0,0 +1,26 @@
+#include <mln/core/image2d.hh>
+
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pbm/save.hh>
+
+#include <mln/subsampling/subsampling.hh>
+
+
+int main(int argc, char*argv[])
+{
+ if (argc != 3)
+ {
+ std::cout << "usage : " << argv[0] << " in.pbm
out.pbm" << std::endl;
+ }
+
+ using namespace mln;
+
+ image2d<bool> img;
+
+ io::pbm::load(img, argv[1]);
+
+ image2d<bool> output = subsampling::subsampling(img, make::dpoint2d(2,2), argc);
+
+ io::pbm::save(output, argv[2]);
+}
+
Index: sandbox/jardonnet/test/01.pbm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: sandbox/jardonnet/test/01.pbm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: sandbox/jardonnet/test/02.pbm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: sandbox/jardonnet/test/02.pbm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: sandbox/jardonnet/registration/icp.hh
--- sandbox/jardonnet/registration/icp.hh (revision 1815)
+++ sandbox/jardonnet/registration/icp.hh (working copy)
@@ -66,24 +66,24 @@
namespace impl
{
- template <typename P, typename T1, typename T2>
+ template <typename P, typename T>
inline
p_array<P>
icp_(p_array<P>& C,
const p_array<P>& X,
- std::pair<T1,T2>&)
+ lazy_map<T>& map)
{
trace::entering("registration::impl::icp_");
unsigned int k;
quat7<P::dim> old_qk, qk;
float err;
- float err_bis;
+ //float err_bis;
p_array<P> Ck(C), Xk(C); //FIXME: Xk copy C
algebra::vec<P::dim,float> mu_C = center(C), mu_Xk;
- const float epsilon = 1e-2;
+ const float epsilon = 1;//1e-3;
//// step 1
k = 0;
@@ -91,7 +91,7 @@
//// step 2
//err_bis = projection::fill_Xk(Ck, map, Xk);
//projection::de_base(Ck, X, Xk, err_bis);
- projection::memo(Ck, X, Xk, err_bis);
+ projection::memo(Ck, X, Xk, map);
mu_Xk = center(Xk);
@@ -104,12 +104,11 @@
//// err = d(Ck+1,Xk)
err = rms(Ck, Xk);
- std::cout << "error :" << err << std::endl;
+ std::cout << k << ' ' << err << std::endl;
//plot file
++k;
} while (k < 3 || (qk - old_qk).sqr_norm() > epsilon);
- std::cout << "nb of iterations : " << k <<
std::endl;
trace::exiting("registration::impl::icp_");
return Ck;
}
@@ -120,8 +119,8 @@
//Only for 2d and 3d image
template <typename I, typename J>
inline
- mln_concrete(I)
- icp(Image<I>& cloud_,
+ mln_concrete(I) //FIXME: should return something else ? qk ?
+ icp(const Image<I>& cloud_,
const Image<J>& surface_)
{
trace::entering("registration::icp");
@@ -142,7 +141,7 @@
fun::cham<point3d> fun;
w_window<mln_dpoint(I3d), float> chamfer = make::w_window(win3d, fun);
*/
- std::pair<mln_ch_value(I3d,float), mln_ch_value(I3d,mln_point(I3d)) > maps;//
=
+ //std::pair<mln_ch_value(I3d,float), mln_ch_value(I3d,mln_point(I3d)) >
maps;// =
//dt::chamfer(surface, chamfer);
@@ -150,7 +149,11 @@
p_array<mln_point(I3d)> c = convert::to_p_array(cloud);
p_array<mln_point(I3d)> x = convert::to_p_array(surface);
- p_array<mln_point(I3d)> res = impl::icp_(c, x, maps);
+ //build closest point map
+ //lazy_map<I3d> map(enlarge(bigger(c.bbox(),x.bbox()),50));
+ lazy_map<I3d> map(1000,1000,50);
+
+ p_array<mln_point(I3d)> res = impl::icp_(c, x, map);
//to 2d : projection (FIXME:if 3d)
//mln_concrete(I) output = convert::to_image2d(res)?
Index: sandbox/jardonnet/registration/projection.hh
--- sandbox/jardonnet/registration/projection.hh (revision 1815)
+++ sandbox/jardonnet/registration/projection.hh (working copy)
@@ -67,27 +67,18 @@
}
- template <typename P>
- void memo(// input
- const p_array<P>& Ck,
+ template <typename P, typename T>
+ void memo(const p_array<P>& Ck,
const p_array<P>& X,
- // inout
p_array<P>& Xk,
- float& err)
+ lazy_map<T>& map) // first: closest points, second: is_computed
{
- //FIXME: remove static
- //FIXME: domain generated by X and C's domain?
- static image3d<point3d> map(1000,1000,10);
- static image3d<bool> mapset(1000,1000,10);
-
assert(Ck.npoints() == Xk.npoints());
- err = 0.f;
-
for (size_t i = 0; i < Ck.npoints(); ++i)
{
float best_d;
- if (mapset(Ck[i]) == false)
+ if (map.known(Ck[i]) == false)
{
algebra::vec<P::dim,float> Cki = Ck[i];
algebra::vec<P::dim,float> best_x = X[0];
@@ -103,16 +94,12 @@
}
}
Xk.hook_()[i] = algebra::to_point<P>(best_x);
- map(Ck[i]) = Xk[i];
- mapset(Ck[i]) = true;
+ map.map(Ck[i]) = Xk[i];
+ map.known(Ck[i]) = true;
}
else
- {
- Xk.hook_()[i] = map(Ck[i]);
- }
- err += best_d;
+ Xk.hook_()[i] = map.map(Ck[i]);
}
- err /= Ck.npoints();
}
} // end of namespace projection
Index: sandbox/jardonnet/registration/tools.hh
--- sandbox/jardonnet/registration/tools.hh (revision 1815)
+++ sandbox/jardonnet/registration/tools.hh (working copy)
@@ -6,9 +6,75 @@
# include <mln/algebra/mat.hh>
# include <mln/core/p_array.hh>
+
namespace mln
{
+
+ //FIXME: Shall we use something *really* lazy
+ template <typename I>
+ struct lazy_map
+ {
+ template <typename P>
+ lazy_map(const box_<P>& domain)
+ : map(domain), known(domain)
+ { }
+
+ lazy_map(int nrows, int ncols, int bdr = 3)
+ : map(nrows, ncols, bdr), known(nrows,ncols,bdr)
+ { }
+
+ mln_ch_value(I, mln_point(I)) map;
+ mln_ch_value(I, bool) known;
+ };
+
+
+ // Point
+
+ template <typename P>
+ P min(const P& a, const P& b)
+ {
+ if (a > b)
+ return b;
+ return a;
+ }
+
+ template <typename P>
+ P max(const P& a, const P& b)
+ {
+ if (a < b)
+ return b;
+ return a;
+ }
+
+
+ // Box
+
+ template <typename P>
+ inline
+ const box_<P>& //dif
+ enlarge(const box_<P>& box, unsigned b)
+ {
+ for (unsigned i = 0; i < P::dim; ++i)
+ {
+ box.pmin()[i] -= b;
+ box.pmax()[i] += b;
+ }
+ return box;
+ }
+
+ template <typename P>
+ box_<P> bigger(box_<P> a, box_<P> b)
+ {
+ P pmin,pmax;
+
+ pmin = min(a.pmin(), b.pmin());
+ pmax = max(a.pmax(), b.pmax());
+
+ return box_<P>(pmin, pmax);
+ }
+
+
//FIXME: move?
namespace convert
{