URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-09-24 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Add benchmark for disk-mapped image and work for color types.
* fabien/igr/color/find_color.cc: Find green color in an image.
* fabien/mln/core/image/disk_ima.hh: Implement disk-mapped image.
* fabien/mln/io/pnm/load_disk_ima.hh: Implement loading of disk-
mapped image from a PNM file.
* fabien/tests/core/image/bench.sh: New script for benchmarking
disk-mapped image and tiled image.
* fabien/mln/test/conversion.hh: Implement test for evaluation of
type conversion.
* fabien/tests/test/conversion.cc: Test evalution of type conversion.
---
igr/color/find_color.cc | 34 ++++++++---
mln/core/image/disk_ima.hh | 1
mln/io/pnm/load_disk_ima.hh | 88 ++++++++++++++++++++++++++++
mln/test/conversion.hh | 136 ++++++++++++++++++++++++++++++++++++++++++++
tests/core/image/bench.sh | 12 +++
tests/test/conversion.cc | 33 ++++++++++
6 files changed, 297 insertions(+), 7 deletions(-)
Index: trunk/milena/sandbox/fabien/igr/color/find_color.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/color/find_color.cc (revision 4544)
+++ trunk/milena/sandbox/fabien/igr/color/find_color.cc (revision 4545)
@@ -1,18 +1,23 @@
#include <mln/core/image/image2d.hh>
+#include <mln/io/pgm/all.hh>
#include <mln/io/ppm/all.hh>
#include <mln/value/rgb8.hh>
#include <mln/value/hsl.hh>
+#include <mln/value/int_u8.hh>
#include <mln/convert/from_to.hh>
#include <mln/data/convert.hh>
+#include <mln/math/diff_abs.hh>
using namespace mln;
using value::rgb8;
using value::hsl_;
+using value::int_u8;
+inline
bool
is_green(hsl_<float, float, float> value)
{
@@ -24,6 +29,24 @@
return false;
}
+inline
+int_u8
+how_green(hsl_<float, float, float> value)
+{
+ float proba = 0.0;
+
+ if (value.hue() > 60 && value.hue() < 180)
+ {
+ proba += 1.f - ((math::diff_abs(120.f, value.hue()) / 100.0) / 0.6);
+ proba *= value.sat();
+ proba *= 1.f - (math::diff_abs(0.5f, value.lum()));
+ }
+
+ if (proba > 1.f)
+ proba = 1.f;
+ return (int_u8) (proba * 255);
+}
+
int main(int argc, char* argv[])
{
if (argc != 3)
@@ -34,21 +57,18 @@
image2d<rgb8> input;
io::ppm::load(input, argv[1]);
+ image2d<int_u8> output;
+ initialize(output, input);
typedef image2d<hsl_<float, float, float> > H;
H ima_hsl = data::convert(hsl_<float, float, float>(), input);
mln_piter_(H) p(ima_hsl.domain());
for_all(p)
{
- if (!is_green(ima_hsl(p)))
- {
- ima_hsl(p).sat() = 0.3;
- ima_hsl(p).lum() = 0.3;
- }
+ output(p) = how_green(ima_hsl(p));
}
- image2d<rgb8> output = data::convert(rgb8(), ima_hsl);
- io::ppm::save(output, argv[2]);
+ io::pgm::save(output, argv[2]);
return 0;
}
Index: trunk/milena/sandbox/fabien/tests/test/conversion.cc
===================================================================
--- trunk/milena/sandbox/fabien/tests/test/conversion.cc (revision 0)
+++ trunk/milena/sandbox/fabien/tests/test/conversion.cc (revision 4545)
@@ -0,0 +1,33 @@
+#include <mln/core/image/image2d.hh>
+
+#include <mln/io/pgm/all.hh>
+#include <mln/io/ppm/all.hh>
+
+#include <mln/value/rgb8.hh>
+#include <mln/value/hsl.hh>
+
+#include <mln/test/conversion.hh>
+
+using namespace mln;
+using value::rgb8;
+using value::hsl_;
+using value::int_u8;
+
+
+int main(int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ std::cout << "Usage: " << argv[0] << " input"
<< std::endl;
+ return 1;
+ }
+
+ image2d<rgb8> input;
+ io::ppm::load(input, argv[1]);
+
+ float delta = test::conversion(input, hsl_<float, float, float>());
+
+ std::cout << "delta conversion = " << delta << std::endl;
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/tests/core/image/bench.sh
===================================================================
--- trunk/milena/sandbox/fabien/tests/core/image/bench.sh (revision 0)
+++ trunk/milena/sandbox/fabien/tests/core/image/bench.sh (revision 4545)
@@ -0,0 +1,12 @@
+#! /bin/sh
+
+make disk_ima
+make tiled2d
+
+echo "---"
+echo "Disk Image Performance"
+time ./disk_ima $1
+
+echo "---"
+echo "Tiled Image Performance"
+time ./tiled2d $1
Property changes on: trunk/milena/sandbox/fabien/tests/core/image/bench.sh
___________________________________________________________________
Added: svn:executable
+ *
Index: trunk/milena/sandbox/fabien/mln/test/conversion.hh
===================================================================
--- trunk/milena/sandbox/fabien/mln/test/conversion.hh (revision 0)
+++ trunk/milena/sandbox/fabien/mln/test/conversion.hh (revision 4545)
@@ -0,0 +1,136 @@
+// Copyright (C) 2009 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_TEST_CONVERSION_HH
+# define MLN_TEST_CONVERSION_HH
+
+/// \file
+///
+/// Test a conversion on the pixel values of an image.
+
+# include <mln/core/concept/image.hh>
+# include <mln/data/convert.hh>
+# include <mln/math/diff_abs.hh>
+# include <mln/value/rgb8.hh>
+
+
+namespace mln
+{
+
+ namespace test
+ {
+
+ /// Test if all pixel values of \p ima can correctly convert into
+ /// the type of \p value and then reconvert into their original
+ /// type.
+ ///
+ /// \param[in] ima The image.
+ /// \param[in] value A value of the conversion type.
+ //
+ template <typename I, typename V>
+ float conversion(const Image<I>& ima, const V& value);
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // Implementations.
+
+ namespace impl
+ {
+
+ template <typename V>
+ inline
+ float color_distance(const V& color1, const V& color2)
+ {
+ return -1.0; // FIXME
+ }
+
+ template <>
+ inline
+ float color_distance<value::rgb8>(const value::rgb8& color1, const
value::rgb8& color2)
+ {
+ float dist = 0.0;
+
+ dist += math::diff_abs(color1.red(), color2.red());
+ dist += math::diff_abs(color1.green(), color2.green());
+ dist += math::diff_abs(color1.blue(), color2.blue());
+
+ dist /= 3 * 255;
+
+ return dist;
+ }
+
+ /// \return The percentage of points which value is not preserved.
+ /// The return value is normalized ([0..1]).
+ template <typename I, typename V>
+ inline
+ float conversion_(const I& ima, const V& value)
+ {
+ float delta = 0;
+
+ typedef mln_ch_value(I, V) J;
+ J converted = data::convert(value, ima);
+ I output = data::convert(mln_value(I)(), converted);
+
+ mln_piter(I) p(ima.domain());
+ for_all(p)
+ {
+ delta += color_distance(ima(p), output(p));
+ //if (ima(p) != output(p))
+ // delta += 1.0;
+ }
+
+ delta /= ima.nelements();
+ return delta;
+ }
+
+ } // end of namespace mln::test::impl
+
+
+
+ // Facades.
+
+
+ template <typename I, typename V>
+ inline
+ float conversion(const Image<I>& ima, const V& value)
+ {
+ trace::entering("test::conversion");
+
+ float res = impl::conversion_(exact(ima), value);
+
+ trace::exiting("test::conversion");
+ return res;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::test
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TEST_CONVERSION_HH
Index: trunk/milena/sandbox/fabien/mln/io/pnm/load_disk_ima.hh
===================================================================
--- trunk/milena/sandbox/fabien/mln/io/pnm/load_disk_ima.hh (revision 0)
+++ trunk/milena/sandbox/fabien/mln/io/pnm/load_disk_ima.hh (revision 4545)
@@ -0,0 +1,88 @@
+// Copyright (C) 2009 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_IO_PNM_LOAD_DISK_IMA_HH
+# define MLN_IO_PNM_LOAD_DISK_IMA_HH
+
+/// \file
+///
+/// Define a function which loads an image of kind PNM 8/16bits with
+/// given path.
+
+# include <iostream>
+# include <fstream>
+# include <string>
+
+# include <mln/io/pnm/load_header.hh>
+# include <mln/io/pnm/max_component.hh>
+# include <mln/io/pnm/macros.hh>
+
+# include <mln/metal/is_a.hh>
+
+namespace mln
+{
+
+ namespace io
+ {
+
+ namespace pnm
+ {
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // Warning if we try to load uncontiguous 2D PNM file into a disk
+ // image, this is not currently supported.
+ template <typename V>
+ inline
+ void load_raw_2d_uncontiguous(std::ifstream& file, disk_ima<V>& ima)
+ {
+ (void) file;
+ (void) ima;
+ std::cout << "You can't load an uncontiguous 2D PNM file into ";
+ std::cout << "a disk image" << std::endl;
+ abort();
+ }
+
+ // Load raw 2d for disk images.
+ template <typename T>
+ inline
+ void load_raw_2d_contiguous(std::ifstream& file, disk_ima<T>& ima,
const std::string& filename)
+ {
+ ima.pos_() = file.tellg();
+ ima.file_() = filename;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::io::pnm
+
+ } // end of namespace mln::io
+
+} // end of namespace mln
+
+
+#endif // ! MLN_IO_PNM_LOAD_DISK_IMA_HH
Index: trunk/milena/sandbox/fabien/mln/core/image/disk_ima.hh
===================================================================
--- trunk/milena/sandbox/fabien/mln/core/image/disk_ima.hh (revision 4544)
+++ trunk/milena/sandbox/fabien/mln/core/image/disk_ima.hh (revision 4545)
@@ -638,6 +638,7 @@
# include <mln/make/image.hh>
+# include <mln/io/pnm/load_disk_ima.hh>
#endif // ! MLN_CORE_IMAGE_DISK_IMA_HH