* icdar/2009/hsc/icdar_io.cc: sample / test.
* icdar/2009/hsc/io/icdar/load.hh,
* icdar/2009/hsc/io/icdar/save.hh: I/O routines.
---
milena/sandbox/ChangeLog | 8 ++
milena/sandbox/icdar/2009/hsc/icdar_io.cc | 51 +++++++++++++
milena/sandbox/icdar/2009/hsc/io/icdar/load.hh | 96 ++++++++++++++++++++++++
milena/sandbox/icdar/2009/hsc/io/icdar/save.hh | 88 ++++++++++++++++++++++
4 files changed, 243 insertions(+), 0 deletions(-)
create mode 100644 milena/sandbox/icdar/2009/hsc/icdar_io.cc
create mode 100644 milena/sandbox/icdar/2009/hsc/io/icdar/load.hh
create mode 100644 milena/sandbox/icdar/2009/hsc/io/icdar/save.hh
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index 37485b0..a5875f7 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,5 +1,13 @@
2009-04-07 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add ICDAR I/O routines.
+
+ * icdar/2009/hsc/icdar_io.cc: sample / test.
+ * icdar/2009/hsc/io/icdar/load.hh,
+ * icdar/2009/hsc/io/icdar/save.hh: I/O routines.
+
+2009-04-07 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add new small tools for ICDAR.
* icdar/2009/hsc/input_lines_to_lines.cc: Iterate on lbl.domain().
diff --git a/milena/sandbox/icdar/2009/hsc/icdar_io.cc
b/milena/sandbox/icdar/2009/hsc/icdar_io.cc
new file mode 100644
index 0000000..3b9ca74
--- /dev/null
+++ b/milena/sandbox/icdar/2009/hsc/icdar_io.cc
@@ -0,0 +1,51 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/make/image2d.hh>
+#include <mln/debug/println.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/level/compare.hh>
+
+#include "io/icdar/save.hh"
+#include "io/icdar/load.hh"
+
+int main(int argc, char *argv[])
+{
+ using namespace mln;
+ using namespace mln::value;
+
+ if (argc < 2)
+ {
+ std::cout << "Usage: " << argv[0] << "
<input.pgm>" << std::endl;
+ return 1;
+ }
+
+ image2d<int_u8> input;
+ io::pgm::load(input, argv[1]);
+ io::icdar::save(input, "icdar.raw");
+
+ image2d<int_u8> output;
+ io::icdar::load(output, "icdar.raw", 48, 44);
+
+ mln_assertion(output.domain() == input.domain());
+ mln_assertion(output == input);
+
+ /// Small test.
+// {
+// int_u8 val[4][5] = { { 2, 3, 6, 7, 8 },
+// { 1, 2, 3, 4, 5 },
+// { 1, 2, 3, 4, 5 },
+// { 1, 2, 3, 4, 5 } };
+//
+// image2d<int_u8> ima = make::image(val);
+//
+// debug::println(ima);
+//
+// io::icdar::save(ima, "icdar.raw");
+//
+// image2d<int_u8> ima_l;
+//
+// io::icdar::load(ima_l, "icdar.raw", 4, 5);
+//
+// debug::println(ima_l);
+// }
+}
diff --git a/milena/sandbox/icdar/2009/hsc/io/icdar/load.hh
b/milena/sandbox/icdar/2009/hsc/io/icdar/load.hh
new file mode 100644
index 0000000..35f59f6
--- /dev/null
+++ b/milena/sandbox/icdar/2009/hsc/io/icdar/load.hh
@@ -0,0 +1,96 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_IO_ICDAR_LOAD_HH
+# define MLN_IO_ICDAR_LOAD_HH
+
+/// \file mln/io/icdar/load.hh
+///
+/// Load an image saved as a raw buffer of integers.
+/// Output file format for ICDAR 2009 contest.
+///
+/// Reference:
http://www.iit.demokritos.gr/~bgat/HandSegmCont2009/Protocol.html
+
+#include <cstdio>
+#include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace io
+ {
+
+ namespace icdar
+ {
+
+ template <typename I>
+ void load(Image<I>& ima_, const std::string& filename,
+ int nrows, int ncols);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ void load(Image<I>& ima_, const std::string& filename,
+ int nrows, int ncols)
+ {
+ trace::entering("io::icdar::load");
+
+ I& ima = exact(ima_);
+ ima = I(nrows, ncols, 0); // Make sure there is no border.
+
+ int size = nrows * ncols;
+ unsigned int *buffer; //Pointer to store raw data
+ FILE *f;
+
+ buffer = (unsigned int *) calloc (size, sizeof (int));
+ f = fopen(filename.c_str(), "rb");
+ fread(buffer, size, sizeof (int),f);
+
+ for (int i = 0; i < size; ++i)
+ {
+ mln_value(I) v;// = buffer[i];
+ convert::from_to(buffer[i], v);
+ ima(ima.point_at_index(i)) = v;
+ }
+
+ fclose(f);
+
+ trace::exiting("io::icdar::load");
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::io::icdar
+
+ } // end of namespace mln::io
+
+} // end of namespace mln
+
+#endif // ! MLN_IO_ICDAR_LOAD_HH
diff --git a/milena/sandbox/icdar/2009/hsc/io/icdar/save.hh
b/milena/sandbox/icdar/2009/hsc/io/icdar/save.hh
new file mode 100644
index 0000000..7a9ad5f
--- /dev/null
+++ b/milena/sandbox/icdar/2009/hsc/io/icdar/save.hh
@@ -0,0 +1,88 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_IO_ICDAR_SAVE_HH
+# define MLN_IO_ICDAR_SAVE_HH
+
+/// \file mln/io/icdar/save.hh
+///
+/// Save an image as a raw buffer of integers.
+/// Output file format for ICDAR 2009 contest.
+///
+/// Reference:
http://www.iit.demokritos.gr/~bgat/HandSegmCont2009/Protocol.html
+
+#include <cstdio>
+#include <mln/core/concept/image.hh>
+
+namespace mln
+{
+
+ namespace io
+ {
+
+ namespace icdar
+ {
+
+ template <typename I>
+ void save(const Image<I>& ima_, const std::string& filename);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ void save(const Image<I>& ima_, const std::string& filename)
+ {
+ trace::entering("io::icdar::save");
+
+ const I& ima = exact(ima_);
+ mln_precondition(ima.is_valid());
+
+ FILE *f = fopen(filename.c_str(), "wb");
+
+ mln_piter(I) p(ima.domain());
+ for_all(p)
+ {
+ /// Probably too violent...
+ unsigned int value = static_cast<unsigned int>(ima(p));
+ fwrite(&value, sizeof (int), 1, f);
+ }
+
+ fclose(f);
+
+ trace::exiting("io::icdar::save");
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::io::icdar
+
+ } // end of namespace mln::io
+
+} // end of namespace mln
+
+#endif // ! MLN_IO_ICDAR_SAVE_HH
--
1.5.6.5