* mln/io/pbm/load.hh,
* mln/io/pgm/load.hh,
* mln/io/ppm/load.hh: load a list of 2D image files and build a 3D
image from that.
* tests/io/pbm/pbm.cc,
* tests/io/pgm/pgm.cc,
* tests/io/ppm/ppm.cc: update tests.
---
milena/ChangeLog | 13 +++++++
milena/mln/io/pbm/load.hh | 38 ++++++++++++++++++++-
milena/mln/io/pgm/load.hh | 67 +++++++++++++++++++++++++++++---------
milena/mln/io/ppm/load.hh | 77 ++++++++++++++++++++++++++++++-------------
milena/tests/io/pbm/pbm.cc | 30 +++++++++++++----
milena/tests/io/pgm/pgm.cc | 35 +++++++++++++++++---
milena/tests/io/ppm/ppm.cc | 33 ++++++++++++++++---
7 files changed, 235 insertions(+), 58 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 4868689..556e3ec 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,18 @@
2009-02-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add new routines to make a 3D image from a list of files.
+
+ * mln/io/pbm/load.hh,
+ * mln/io/pgm/load.hh,
+ * mln/io/ppm/load.hh: load a list of 2D image files and build a 3D
+ image from that.
+
+ * tests/io/pbm/pbm.cc,
+ * tests/io/pgm/pgm.cc,
+ * tests/io/ppm/ppm.cc: update tests.
+
+2009-02-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add more trace::warning in labeling canvas.
* mln/canvas/labeling.hh: add new trace::warnings.
diff --git a/milena/mln/io/pbm/load.hh b/milena/mln/io/pbm/load.hh
index ea9e78c..81ad23d 100644
--- a/milena/mln/io/pbm/load.hh
+++ b/milena/mln/io/pbm/load.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 EPITA
-// Research and Development Laboratory (LRDE)
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -40,8 +40,11 @@
# include <string>
# include <mln/core/image/image2d.hh>
+# include <mln/core/image/image3d.hh>
# include <mln/io/pnm/load_header.hh>
+# include <mln/make/image3d.hh>
+
namespace mln
{
@@ -69,6 +72,14 @@ namespace mln
///
image2d<bool> load(const std::string& filename);
+ /// Load ppm images as slices of a 3D Milena image.
+ ///
+ /// \param[out] ima A reference to the 3D image which will receive
+ /// data.
+ /// \param[in] filenames The list of 2D images to load..
+ void load(image3d<bool>& ima,
+ const util::array<std::string>& filenames);
+
# ifndef MLN_INCLUDE_ONLY
namespace internal
@@ -160,6 +171,29 @@ namespace mln
ima = load(filename);
}
+
+ inline
+ void load(image3d<bool>& ima,
+ const util::array<std::string>& filenames)
+ {
+ trace::entering("mln::io::pbm::load");
+ mln_precondition(!filenames.is_empty());
+
+ util::array<image2d<bool> > slices;
+
+ for (unsigned i = 0; i < filenames.nelements(); ++i)
+ {
+ image2d<bool> tmp;
+ io::pbm::load(tmp, filenames[i]);
+ slices.append(tmp);
+ }
+
+ ima = make::image3d(slices);
+
+ trace::exiting("mln::io::pbm::load");
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::io::pbm
diff --git a/milena/mln/io/pgm/load.hh b/milena/mln/io/pgm/load.hh
index a82f5b5..c69349c 100644
--- a/milena/mln/io/pgm/load.hh
+++ b/milena/mln/io/pgm/load.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 EPITA
-// Research and Development Laboratory
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -42,11 +42,13 @@
# include <string>
# include <mln/core/image/image2d.hh>
+# include <mln/core/image/image3d.hh>
# include <mln/value/int_u8.hh>
# include <mln/io/pnm/load.hh>
+# include <mln/make/image3d.hh>
namespace mln
{
@@ -57,28 +59,38 @@ namespace mln
namespace pgm
{
- /*! Load a pgm image in a Milena image.
- *
- * \param[out] ima A reference to the image which will receive
- * data.
- * \param[in] filename The source.
- */
+ /// Load a pgm image in a Milena image.
+ ///
+ /// \param[out] ima A reference to the image which will receive
+ /// data.
+ /// \param[in] filename The source.
template <typename I>
void load(Image<I>& ima,
const std::string& filename);
- /*! Load a pgm image in a Milena image. To use this routine, you
- * should specialize the template whith the value type of the
- * image loaded. (ex : load<value::int_u8>("...") )
- *
- * \param[in] filename The image source.
- *
- * \return An image2d which contains loaded data.
- */
+ /// Load a pgm image in a Milena image. To use this routine, you
+ /// should specialize the template whith the value type of the
+ /// image loaded. (ex : load<value::int_u8>("...") )
+ ///
+ /// \param[in] filename The image source.
+ ///
+ /// \return An image2d which contains loaded data.
template <typename V>
image2d<V> load(const std::string& filename);
+
+ /// Load ppm images as slices of a 3D Milena image.
+ ///
+ /// \param[out] ima A reference to the 3D image which will receive
+ /// data.
+ /// \param[in] filenames The list of 2D images to load..
+ ///
+ template <typename V>
+ void load(image3d<V>& ima,
+ const util::array<std::string>& filenames);
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename V>
@@ -101,6 +113,29 @@ namespace mln
trace::exiting("mln::io::pgm::load");
}
+
+ template <typename V>
+ inline
+ void load(image3d<V>& ima,
+ const util::array<std::string>& filenames)
+ {
+ trace::entering("mln::io::pgm::load");
+ mln_precondition(!filenames.is_empty());
+
+ util::array<image2d<V> > slices;
+
+ for (unsigned i = 0; i < filenames.nelements(); ++i)
+ {
+ image2d<V> tmp;
+ io::pnm::load<image2d<V> >(PGM, tmp, filenames[i]);
+ slices.append(tmp);
+ }
+
+ ima = make::image3d(slices);
+
+ trace::exiting("mln::io::pgm::load");
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::io::pgm
diff --git a/milena/mln/io/ppm/load.hh b/milena/mln/io/ppm/load.hh
index bf9d27b..291eaf8 100644
--- a/milena/mln/io/ppm/load.hh
+++ b/milena/mln/io/ppm/load.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 EPITA
-// Research and Development Laboratory
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -29,23 +29,23 @@
#ifndef MLN_IO_PPM_LOAD_HH
# define MLN_IO_PPM_LOAD_HH
-/*!
- * \file mln/io/ppm/load.hh
- *
- * \brief Define a function which loads an image of kind ppm with
- * given path.
- *
- */
+/// \file mln/io/ppm/load.hh
+///
+/// Define a function which loads an image of kind ppm with
+/// given path.
# include <iostream>
# include <fstream>
# include <string>
# include <mln/core/image/image2d.hh>
+# include <mln/core/image/image3d.hh>
# include <mln/value/rgb8.hh>
# include <mln/io/pnm/load.hh>
+# include <mln/make/image3d.hh>
+
namespace mln
{
@@ -55,27 +55,36 @@ namespace mln
namespace ppm
{
- /*! Load a ppm image in a Milena image.
- *
- * \param[out] ima A reference to the image which will receive
- * data.
- * \param[in] filename The source.
- */
+ /// Load a ppm image in a Milena image.
+ ///
+ /// \param[out] ima A reference to the image which will receive
+ /// data.
+ /// \param[in] filename The source.
template <typename I>
void load(Image<I>& ima,
const std::string& filename);
- /*! Load a ppm image in a Milena image. To use this routine, you
- * should specialize the template whith the value type of the
- * image loaded. (ex : load<value::int_u8>("...") )
- *
- * \param[in] filename The image source.
- *
- * \return An image2d which contains loaded data.
- */
+ /// Load a ppm image in a Milena image. To use this routine, you
+ /// should specialize the template whith the value type of the
+ /// image loaded. (ex : load<value::int_u8>("..."))
+ ///
+ /// \param[in] filename The image source.
+ ///
+ /// \return An image2d which contains loaded data.
+ ///
template <typename V>
image2d<V> load(const std::string& filename);
+
+ /// Load ppm images as slices of a 3D Milena image.
+ ///
+ /// \param[out] ima A reference to the 3D image which will receive
+ /// data.
+ /// \param[in] filenames The list of 2D images to load..
+ template <typename V>
+ void load(image3d<V>& ima,
+ const util::array<std::string>& filenames);
+
# ifndef MLN_INCLUDE_ONLY
template <typename V>
@@ -98,6 +107,28 @@ namespace mln
trace::exiting("mln::io::ppm::load");
}
+ template <typename V>
+ inline
+ void load(image3d<V>& ima,
+ const util::array<std::string>& filenames)
+ {
+ trace::entering("mln::io::ppm::load");
+ mln_precondition(!filenames.is_empty());
+
+ util::array<image2d<V> > slices;
+
+ for (unsigned i = 0; i < filenames.nelements(); ++i)
+ {
+ image2d<V> tmp;
+ io::pnm::load<image2d<V> >(PPM, tmp, filenames[i]);
+ slices.append(tmp);
+ }
+
+ ima = make::image3d(slices);
+
+ trace::exiting("mln::io::ppm::load");
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::io::ppm
diff --git a/milena/tests/io/pbm/pbm.cc b/milena/tests/io/pbm/pbm.cc
index fc02dda..e54d820 100644
--- a/milena/tests/io/pbm/pbm.cc
+++ b/milena/tests/io/pbm/pbm.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,10 +26,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/io/pbm/pbm.cc
- *
- * \brief Test on mln::io::pbm::.
- */
+/// \file tests/io/pbm/pbm.cc
+///
+/// Test on mln::io::pbm::.
#include <mln/core/image/image2d.hh>
#include <mln/io/pbm/load.hh>
@@ -44,10 +44,26 @@ int main()
using namespace mln;
image2d<bool> pic = io::pbm::load(MLN_IMG_DIR "/picasso.pbm");
- io::pbm::save(pic, "pic.pbm");
- image2d<bool> pic2 = io::pbm::load("pic.pbm");
+ io::pbm::save(pic, "out.pbm");
+ image2d<bool> pic2 = io::pbm::load("out.pbm");
mln_assertion(pic == pic2);
+
+
+ pic2(point2d(0,0)) = true;
+ io::pbm::save(pic2, "out.pbm");
+
+ util::array<std::string> files(2);
+ files[0] = MLN_IMG_DIR "/picasso.pbm";
+ files[1] = "out.pbm";
+
+ image3d<bool> ima3d;
+ io::pbm::load(ima3d, files);
+
+ mln_assertion(ima3d.nslices() == 2);
+ mln_assertion(slice(ima3d, 0) == pic);
+ mln_assertion(slice(ima3d, 1) == pic2);
+
}
diff --git a/milena/tests/io/pgm/pgm.cc b/milena/tests/io/pgm/pgm.cc
index 6a6da68..fd22c42 100644
--- a/milena/tests/io/pgm/pgm.cc
+++ b/milena/tests/io/pgm/pgm.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,13 +26,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/io/pgm/pgm.cc
- *
- * \brief Test on mln::io::pgm::load and mln::io::pgm::save.
- */
+/// \file tests/io/pgm/pgm.cc
+///
+/// Test on mln::io::pgm::load and mln::io::pgm::save.
+
#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/routine/duplicate.hh>
#include <mln/value/int_u8.hh>
@@ -40,6 +43,8 @@
#include <mln/level/compare.hh>
+#include <mln/literal/colors.hh>
+
#include "tests/data.hh"
@@ -65,4 +70,24 @@ int main()
io::pgm::load(lena2, "out.pgm");
mln_assertion(lena2 == lena);
}
+
+ {
+ image2d<int_u8> lena = io::pgm::load<int_u8>(MLN_IMG_DIR "/lena.pgm");
+
+ image2d<int_u8> lena2 = duplicate(lena);
+ lena2(point2d(0,0)) = 200;
+
+ io::pgm::save(lena2, "out.pgm");
+
+ util::array<std::string> files(2);
+ files[0] = MLN_IMG_DIR "/lena.pgm";
+ files[1] = "out.pgm";
+
+ image3d<int_u8> ima3d;
+ io::pgm::load(ima3d, files);
+
+ mln_assertion(ima3d.nslices() == 2);
+ mln_assertion(slice(ima3d, 0) == lena);
+ mln_assertion(slice(ima3d, 1) == lena2);
+ }
}
diff --git a/milena/tests/io/ppm/ppm.cc b/milena/tests/io/ppm/ppm.cc
index 7dca079..ecc80b4 100644
--- a/milena/tests/io/ppm/ppm.cc
+++ b/milena/tests/io/ppm/ppm.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,12 +26,13 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/io/ppm/ppm.cc
- *
- * \brief Test on mln::io::ppm::load and mln::io::ppm::save.
- */
+/// \file tests/io/ppm/ppm.cc
+///
+/// Test on mln::io::ppm::load and mln::io::ppm::save.
+
#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
#include <mln/value/rgb8.hh>
#include <mln/io/ppm/load.hh>
@@ -38,6 +40,10 @@
#include <mln/level/compare.hh>
+#include <mln/util/array.hh>
+
+#include <mln/literal/colors.hh>
+
#include "tests/data.hh"
@@ -52,4 +58,21 @@ int main()
image2d<rgb8> lena2;
io::ppm::load(lena2, "out.ppm");
mln_assertion(lena2 == lena);
+
+
+
+ lena2(point2d(0,0)) = literal::green;
+ io::ppm::save(lena2, "out.ppm");
+
+ util::array<std::string> files(2);
+ files[0] = MLN_IMG_DIR "/lena.ppm";
+ files[1] = "out.ppm";
+
+ image3d<rgb8> ima3d;
+ io::ppm::load(ima3d, files);
+
+ mln_assertion(ima3d.nslices() == 2);
+ mln_assertion(slice(ima3d, 0) == lena);
+ mln_assertion(slice(ima3d, 1) == lena2);
}
+
--
1.5.6.5