https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Ugo Jardonnet <jardonnet(a)lrde.epita.fr>
Sandox: ICP: Make it save images of every step of the registration.
* jardonnet/test/icp_ref.cc,
* jardonnet/test/icp.cc: Cleanup output image.
* jardonnet/test/Makefile: Remove gprof option.
* jardonnet/registration/save.hh: Add proper saving.
* jardonnet/registration/icp_ref.hh: Add step loggin.
Add images for test and slides.
* jardonnet/test/img/x10.pbm,
* jardonnet/test/img/x11.pbm,
* jardonnet/test/img/c10.pbm,
* jardonnet/test/img/c11.pbm: New test images.
registration/icp_ref.hh | 15 ++++++++---
registration/save.hh | 65
++++++++++++++++++++++++++++++++++++++----------
registration/tools.hh | 8 +++++
test/Makefile | 2 -
test/icp.cc | 10 ++++---
test/icp_ref.cc | 7 ++---
6 files changed, 82 insertions(+), 25 deletions(-)
Index: jardonnet/test/icp_ref.cc
--- jardonnet/test/icp_ref.cc (revision 2013)
+++ jardonnet/test/icp_ref.cc (working copy)
@@ -82,17 +82,18 @@
qk.apply_on(c, c, c.npoints());
image2d<value::rgb8> output(convert::to_box2d(working_box), 1);
+ level::fill(output, literal::white);
//to 2d : projection (FIXME:if 3d)
- for (size_t i = 0; i < c.npoints(); i++)
+ for (unsigned i = 0; i < c.npoints(); i++)
{
point2d p(c[i][0], c[i][1]);
if (output.has(p))
- output(p) = literal::white;
+ output(p) = literal::black;
}
//ref image
- for (size_t i = 0; i < x.npoints(); i++)
+ for (unsigned i = 0; i < x.npoints(); i++)
{
point2d px(x[i][0], x[i][1]);
if (output.has(px))
Index: jardonnet/test/icp.cc
--- jardonnet/test/icp.cc (revision 2013)
+++ jardonnet/test/icp.cc (working copy)
@@ -63,10 +63,6 @@
qk.apply_on(c, c, c.npoints());
- //init output image
- image2d<value::rgb8> output(convert::to_box2d(working_box), 0);
- level::fill(output, literal::white);
-
float stddev, mean;
registration::mean_stddev(c, map, mean, stddev);
@@ -84,6 +80,12 @@
quat7<3> fqk = registration::final_qk(c, map, 2*stddev);
fqk.apply_on(c, c, c.npoints());
+
+ //init output image
+ image2d<value::rgb8> output(convert::to_box2d(working_box), 0);
+ level::fill(output, literal::white);
+
+
//print x
for (size_t i = 0; i < x.npoints(); i++)
{
Index: jardonnet/test/img/x10.pbm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: jardonnet/test/img/x10.pbm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: jardonnet/test/img/x11.pbm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: jardonnet/test/img/x11.pbm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: jardonnet/test/img/c10.pbm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: jardonnet/test/img/c10.pbm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: jardonnet/test/img/c11.pbm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: jardonnet/test/img/c11.pbm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: jardonnet/test/Makefile
--- jardonnet/test/Makefile (revision 2013)
+++ jardonnet/test/Makefile (working copy)
@@ -23,7 +23,7 @@
g++ icp_ref.cc -I../../.. -g -o 'icp_refD'
icp_ref: icp_ref.cc ../registration/icp_ref.hh +depend
- g++ icp_ref.cc -I../../.. -pg -O3 -DNDEBUG -o 'icp_ref'
+ g++ icp_ref.cc -I../../.. -O3 -DNDEBUG -o 'icp_ref'
icp.o:
g++ -c icp.cc -I../../.. -O3 -DNDEBUG
Index: jardonnet/registration/save.hh
--- jardonnet/registration/save.hh (revision 2013)
+++ jardonnet/registration/save.hh (working copy)
@@ -1,37 +1,76 @@
#ifndef MLN_REGISTRATION_SAVE_HH
# define MLN_REGISTRATION_SAVE_HH
+# include <mln/convert/to_image.hh>
+# include <mln/io/ppm/save.hh>
+# include <mln/io/pbm/save.hh>
#include <string>
+# include "quat7.hh"
+# include "tools.hh"
+
namespace mln
{
+ namespace io
+ {
+ namespace pbm
+ {
+ template <typename P>
+ void save(const p_array<P>& a, const std::string& filename)
+ {
+ mln_precondition(P::dim == 2);
+
+ image2d out = convert::to_image(a);
+ save(out, filename);
+ }
+ }
+ }
+
+
namespace registration
{
template <typename P>
- void save_(const p_array<P>& Ck, int l)
+ void save_(const quat7<3>& qk,
+ const p_array<P>& c,
+ const p_array<P>& x,
+ int every)
{
static int id = 0;
+ static int i = 0;
+
+ if (++i % every != 0)
+ return;
- using namespace std;
+ //build ck: apply transform
+ p_array<P> ck(c);
+ qk.apply_on(c, ck, c.npoints());
- //FIXME: Should use Ck box but Ck.bbox() is not correct for c_length
- image2d<bool> img(box2d(500,800), 0);
- for (size_t i = 0; i < l; i++)
+ const box_<P> working_box = enlarge(bigger(ck.bbox(),x.bbox()),100);
+ image2d<value::rgb8> out(convert::to_box2d(working_box), 1);
+ level::fill(out, literal::white);
+
+ //x in green
+ for (unsigned i = 0; i < ck.npoints(); i++)
{
- point2d p = convert::to_point2d(Ck[i]);
- if (img.has(p))
- img(p) = true;
+ point2d p(ck[i][0], ck[i][1]);
+ if (out.has(p))
+ out(p) = literal::green;
}
- //FIXME: Good but put point after c_length
- //image2d<bool> img = convert::to_image2d(Ck);
+ //x in black
+ for (unsigned i = 0; i < x.npoints(); i++)
+ {
+ point2d p(x[i][0], x[i][1]);
+ if (out.has(p))
+ out(p) = literal::black;
+ }
+ //save
std::stringstream oss;
- oss << "i_" << id++ << ".pbm";
- io::pbm::save(img, oss.str());
-
+ oss << "step_" << id++ << ".ppm";
+ io::ppm::save(out, oss.str());
}
}
Index: jardonnet/registration/tools.hh
--- jardonnet/registration/tools.hh (revision 2013)
+++ jardonnet/registration/tools.hh (working copy)
@@ -12,6 +12,14 @@
namespace mln
{
+ namespace registration
+ {
+
+
+
+ }
+
+
template <typename P>
void shuffle(p_array<P>& a)
{
Index: jardonnet/registration/icp_ref.hh
--- jardonnet/registration/icp_ref.hh (revision 2013)
+++ jardonnet/registration/icp_ref.hh (working copy)
@@ -57,9 +57,13 @@
# include "save.hh"
+
+
namespace mln
{
+
+
namespace registration
{
@@ -89,6 +93,7 @@
const M& map,
quat7<P::dim>& qk,
const size_t c_length,
+ const p_array<P>& X,
const float epsilon = 1e-3)
{
trace::entering("registration::impl::icp_");
@@ -131,7 +136,9 @@
e_k = rms(C, map, c_length, buf_qk[1], buf_qk[1]);
#ifndef NDEBUG
- //plot file
+ //save file
+ save_(qk,C,X,5);
+ //print info
std::cout << k << '\t' << (e_k >= d_k ? '
' : '-') << '\t'
<< e_k << '\t' << d_k << '\t'
<< ((qk - buf_qk[1]).sqr_norm() / qk.sqr_norm())
<< '\t'
<< std::endl;
@@ -139,8 +146,8 @@
pts += c_length;
#endif
k++;
- } while (e_k >= d_k && d_k_1 - d_k > epsilon);
- // FIXME : test (e_k >= d_k) seems to be a bad idea.
+ } while (d_k_1 - d_k > epsilon);
+ // FIXME : test (e_k >= d_k) but seems to be a bad idea.
trace::exiting("registration::impl::icp_");
}
@@ -188,7 +195,7 @@
size_t l = cloud.npoints() / std::pow(q, e);
l = (l<1) ? 1 : l;
- impl::icp_(cloud, map, qk, l, 1e-3);
+ impl::icp_(cloud, map, qk, l, x, 1e-3);
#ifndef NDEBUG
{