Olena-patches
Threads by month
- ----- 2026 -----
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
* mln/upscaling/art/scale2x.hh,
* mln/upscaling/art/scale3x.hh: New routines.
* tests/Makefile.am,
* tests/upscaling/Makefile.am,
* tests/upscaling/art/Makefile.am,
* tests/upscaling/art/scale2x.cc,
* tests/upscaling/art/scale3x.cc: New associated tests.
---
milena/ChangeLog | 13 ++
milena/mln/upscaling/art/scale2x.hh | 151 ++++++++++++++++++++++
milena/mln/upscaling/art/scale3x.hh | 218 ++++++++++++++++++++++++++++++++
milena/tests/Makefile.am | 1 +
milena/tests/upscaling/Makefile.am | 24 ++++
milena/tests/upscaling/art/Makefile.am | 32 +++++
milena/tests/upscaling/art/scale2x.cc | 59 +++++++++
milena/tests/upscaling/art/scale3x.cc | 61 +++++++++
8 files changed, 559 insertions(+), 0 deletions(-)
create mode 100644 milena/mln/upscaling/art/scale2x.hh
create mode 100644 milena/mln/upscaling/art/scale3x.hh
create mode 100644 milena/tests/upscaling/Makefile.am
create mode 100644 milena/tests/upscaling/art/Makefile.am
create mode 100644 milena/tests/upscaling/art/scale2x.cc
create mode 100644 milena/tests/upscaling/art/scale3x.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 3100c37..19c3edd 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,18 @@
2009-09-22 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add new upscaling algorithms.
+
+ * mln/upscaling/art/scale2x.hh,
+ * mln/upscaling/art/scale3x.hh: New routines.
+
+ * tests/Makefile.am,
+ * tests/upscaling/Makefile.am,
+ * tests/upscaling/art/Makefile.am,
+ * tests/upscaling/art/scale2x.cc,
+ * tests/upscaling/art/scale3x.cc: New associated tests.
+
+2009-09-22 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
* mln/core/alias/dpoint2d.hh: Add new dpoint2d aliases.
2009-09-22 Fabien Freling <fabien.freling(a)lrde.epita.fr>
diff --git a/milena/mln/upscaling/art/scale2x.hh b/milena/mln/upscaling/art/scale2x.hh
new file mode 100644
index 0000000..6805943
--- /dev/null
+++ b/milena/mln/upscaling/art/scale2x.hh
@@ -0,0 +1,151 @@
+// 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_UPSCALING_ART_SCALE2X_HH
+# define MLN_UPSCALING_ART_SCALE2X_HH
+
+/// \file
+///
+/// 2X upscaling algorithm for pixel art images.
+
+
+# include <mln/core/concept/box.hh>
+# include <mln/core/concept/image.hh>
+# include <mln/core/alias/neighb2d.hh>
+# include <mln/core/alias/dpoint2d.hh>
+
+# include <mln/extension/adjust_duplicate.hh>
+
+
+namespace mln
+{
+
+ namespace upscaling
+ {
+
+ namespace art
+ {
+
+ /*! \brief 2X upscaling algorithm for pixel art images.
+
+ \param[in] input An image.
+
+ \return An upscaled image.
+
+
+ Source:
+ http://en.wikipedia.org/wiki/Pixel_art_scaling_algorithms
+
+ */
+ template <typename I>
+ mln_concrete(I)
+ scale2x(const Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ mln_concrete(I)
+ scale2x(const Image<I>& input_)
+ {
+ trace::entering("mln::upscaling::art::scale2x");
+
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+ mlc_is_a(mln_domain(I), Box)::check();
+
+ extension::adjust_duplicate(input, 1);
+
+ mln_domain(I) ext_domain(input.domain().pmin() * 2,
+ input.domain().pmax() * 2
+ + mln::down_right);
+
+ mln_concrete(I) output(ext_domain);
+
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ {
+
+ // A --\ 1 2
+ // C P B --/ 3 4
+ // D
+ mln_site(I)
+ pA = p + mln::up,
+ pB = p + mln::right,
+ pC = p + mln::left,
+ pD = p + mln::down,
+ pOut = p * 2;
+
+ // IF C==A AND C!=D AND A!=B => 1=A
+ if (input(pC) == input(pA)
+ && input(pC) != input(pD)
+ && input(pA) != input(pB))
+ output(pOut) = input(pA);
+ else
+ output(pOut) = input(p);
+
+ // IF A==B AND A!=C AND B!=D => 2=B
+ if (input(pA) == input(pB)
+ && input(pA) != input(pC)
+ && input(pB) != input(pD))
+ output(pOut + mln::right) = input(pB);
+ else
+ output(pOut + mln::right) = input(p);
+
+ // IF D==C AND D!=B AND C!=A => 3=C
+ if (input(pD) == input(pC)
+ && input(pD) != input(pB)
+ && input(pC) != input(pA))
+ output(pOut + mln::down) = input(pC);
+ else
+ output(pOut + mln::down) = input(p);
+
+ // IF B==D AND B!=A AND D!=C => 4=D
+ if (input(pB) == input(pD)
+ && input(pB) != input(pA)
+ && input(pD) != input(pC))
+ output(pOut + mln::down_right) = input(pD);
+ else
+ output(pOut + mln::down_right) = input(p);
+
+ }
+
+ trace::exiting("mln::upscaling::art::scale2x");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace mln::upscaling::art
+
+ } // end of namespace mln::upscaling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_UPSCALING_ART_SCALE2X_HH
diff --git a/milena/mln/upscaling/art/scale3x.hh b/milena/mln/upscaling/art/scale3x.hh
new file mode 100644
index 0000000..042dd28
--- /dev/null
+++ b/milena/mln/upscaling/art/scale3x.hh
@@ -0,0 +1,218 @@
+// 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_UPSCALING_ART_SCALE3X_HH
+# define MLN_UPSCALING_ART_SCALE3X_HH
+
+/// \file
+///
+/// 3X upscaling algorithm for pixel art images.
+
+
+# include <mln/core/concept/box.hh>
+# include <mln/core/concept/image.hh>
+# include <mln/core/alias/neighb2d.hh>
+# include <mln/core/alias/dpoint2d.hh>
+
+# include <mln/extension/adjust_duplicate.hh>
+
+
+namespace mln
+{
+
+ namespace upscaling
+ {
+
+ namespace art
+ {
+
+ /*! \brief 3X upscaling algorithm for pixel art images.
+
+ \param[in] input An image.
+
+ \return An upscaled image.
+
+
+ Source:
+ http://en.wikipedia.org/wiki/Pixel_art_scaling_algorithms
+
+ */
+ template <typename I>
+ mln_concrete(I)
+ scale3x(const Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ mln_concrete(I)
+ scale3x(const Image<I>& input_)
+ {
+ trace::entering("mln::upscaling::art::scale3x");
+
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+ mlc_is_a(mln_domain(I), Box)::check();
+
+ extension::adjust_duplicate(input, 1);
+
+ mln_domain(I) ext_domain(input.domain().pmin() * 3,
+ input.domain().pmax() * 3
+ + 2 * mln::down_right);
+
+ mln_concrete(I) output(ext_domain);
+
+
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ {
+
+ // A B C --\ 1 2 3
+ // D E F > 4 5 6
+ // G H I --/ 7 8 9
+ mln_site(I)
+ pA = p + mln::up_left,
+ pB = p + mln::up,
+ pC = p + mln::up_right,
+ pD = p + mln::left,
+ pE = p,
+ pF = p + mln::right,
+ pG = p + mln::down_left,
+ pH = p + mln::down,
+ pI = p + mln::down_right,
+ pOut = p * 3 + mln::down_right;
+
+ // IF D==B AND D!=H AND B!=F => 1=D
+ if (input(pD) == input(pB)
+ && input(pD) != input(pH)
+ && input(pB) != input(pF))
+ output(pOut + mln::up_left) = input(pD);
+ else
+ output(pOut + mln::up_left) = input(p);
+
+ // IF (D==B AND D!=H AND B!=F AND E!=C) OR (B==F AND B!=D
+ // AND F!=H AND E!=A) 2=B
+ if ((input(pD) == input(pB)
+ && input(pD) != input(pH)
+ && input(pB) != input(pF)
+ && input(pE) != input(pC))
+ || (input(pB) == input(pF)
+ && input(pB) != input(pD)
+ && input(pF) != input(pH)
+ && input(pE) != input(pA)))
+ output(pOut + mln::up) = input(pB);
+ else
+ output(pOut + mln::up) = input(p);
+
+ // IF B==F AND B!=D AND F!=H => 3=F
+ if (input(pB) == input(pF)
+ && input(pB) != input(pD)
+ && input(pF) != input(pH))
+ output(pOut + mln::up_right) = input(pF);
+ else
+ output(pOut + mln::up_right) = input(p);
+
+ // IF (H==D AND H!=F AND D!=B AND E!=A) OR (D==B AND D!=H
+ // AND B!=F AND E!=G) 4=D
+ if ((input(pH) == input(pD)
+ && input(pH) != input(pF)
+ && input(pD) != input(pB)
+ && input(pE) != input(pA))
+ || (input(pD) == input(pB)
+ && input(pD) != input(pH)
+ && input(pB) != input(pF)
+ && input(pE) != input(pG)))
+ output(pOut + mln::left) = input(pD);
+ else
+ output(pOut + mln::left) = input(p);
+
+ // 5=E
+ output(pOut) = input(p);
+
+ // IF (B==F AND B!=D AND F!=H AND E!=I) OR (F==H AND F!=B
+ // AND H!=D AND E!=C) 6=F
+ if ((input(pB) == input(pF)
+ && input(pB) != input(pD)
+ && input(pF) != input(pH)
+ && input(pE) != input(pI))
+ || (input(pF) == input(pH)
+ && input(pF) != input(pB)
+ && input(pH) != input(pD)
+ && input(pE) != input(pC)))
+ output(pOut + mln::right) = input(pF);
+ else
+ output(pOut + mln::right) = input(p);
+
+ // IF H==D AND H!=F AND D!=B => 7=D
+ if (input(pH) == input(pD)
+ && input(pH) != input(pF)
+ && input(pD) != input(pB))
+ output(pOut + mln::down_left) = input(pD);
+ else
+ output(pOut + mln::down_left) = input(p);
+
+
+ // IF (F==H AND F!=B AND H!=D AND E!=G) OR (H==D AND H!=F
+ // AND D!=B AND E!=I) 8=H
+ if ((input(pF) == input(pH)
+ && input(pF) != input(pB)
+ && input(pH) != input(pD)
+ && input(pE) != input(pG))
+ || (input(pH) == input(pD)
+ && input(pH) != input(pF)
+ && input(pD) != input(pB)
+ && input(pE) != input(pI)))
+ output(pOut + mln::down) = input(pH);
+ else
+ output(pOut + mln::down) = input(p);
+
+
+ // IF F==H AND F!=B AND H!=D => 9=F
+ if (input(pF) == input(pH)
+ && input(pF) != input(pB)
+ && input(pH) != input(pD))
+ output(pOut + mln::down_right) = input(pF);
+ else
+ output(pOut + mln::down_right) = input(p);
+
+ }
+
+ trace::exiting("mln::upscaling::art::scale3x");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace mln::upscaling::art
+
+ } // end of namespace mln::upscaling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_UPSCALING_ART_SCALE3X_HH
diff --git a/milena/tests/Makefile.am b/milena/tests/Makefile.am
index 39987d0..562078e 100644
--- a/milena/tests/Makefile.am
+++ b/milena/tests/Makefile.am
@@ -59,6 +59,7 @@ SUBDIRS = \
trait \
transform \
unit_test \
+ upscaling \
util \
value \
win \
diff --git a/milena/tests/upscaling/Makefile.am b/milena/tests/upscaling/Makefile.am
new file mode 100644
index 0000000..dbe5a89
--- /dev/null
+++ b/milena/tests/upscaling/Makefile.am
@@ -0,0 +1,24 @@
+# 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/>.
+#
+
+## Process this file through Automake to create Makefile.in.
+
+include $(top_srcdir)/milena/tests/tests.mk
+
+SUBDIRS = \
+ art
+
diff --git a/milena/tests/upscaling/art/Makefile.am b/milena/tests/upscaling/art/Makefile.am
new file mode 100644
index 0000000..e001aaa
--- /dev/null
+++ b/milena/tests/upscaling/art/Makefile.am
@@ -0,0 +1,32 @@
+# 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/>.
+#
+
+## Process this file through Automake to create Makefile.in.
+
+include $(top_srcdir)/milena/tests/tests.mk
+
+
+check_PROGRAMS = \
+ scale2x \
+ scale3x
+
+
+scale2x_SOURCES = scale2x.cc
+scale3x_SOURCES = scale3x.cc
+
+
+TESTS = $(check_PROGRAMS)
diff --git a/milena/tests/upscaling/art/scale2x.cc b/milena/tests/upscaling/art/scale2x.cc
new file mode 100644
index 0000000..1db0298
--- /dev/null
+++ b/milena/tests/upscaling/art/scale2x.cc
@@ -0,0 +1,59 @@
+// 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.
+
+/// \file
+///
+/// \brief Test of the upscaling::art::scale2x routine.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/data/compare.hh>
+
+#include <mln/upscaling/art/scale2x.hh>
+
+int main()
+{
+ using namespace mln;
+
+ bool rvals[4][8] = {
+ {0, 0, 0, 0, 0, 0, 1, 1},
+ {0, 0, 0, 0, 0, 0, 1, 1},
+ {1, 1, 1, 0, 0, 0, 1, 1},
+ {1, 1, 1, 1, 0, 0, 1, 1},
+ };
+
+
+ bool vals[2][4] = {
+ {0, 0, 0, 1},
+ {1, 1, 0, 1}
+ };
+
+ image2d<bool> ref = make::image(rvals);
+ image2d<bool> input = make::image(vals);
+
+
+ input = upscaling::art::scale2x(input);
+
+ mln_assertion(input == ref);
+}
diff --git a/milena/tests/upscaling/art/scale3x.cc b/milena/tests/upscaling/art/scale3x.cc
new file mode 100644
index 0000000..dbcde5c
--- /dev/null
+++ b/milena/tests/upscaling/art/scale3x.cc
@@ -0,0 +1,61 @@
+// 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.
+
+/// \file
+///
+/// \brief Test of the upscaling::art::scale3x routine.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/data/compare.hh>
+
+#include <mln/upscaling/art/scale3x.hh>
+
+int main()
+{
+ using namespace mln;
+
+
+ bool rvals[6][12] = {
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1},
+ {1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
+ {1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1},
+ {1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1}
+ };
+
+
+ bool vals[2][4] = {
+ {0, 0, 0, 1},
+ {1, 1, 0, 1}
+ };
+
+ image2d<bool> ref = make::image(rvals);
+ image2d<bool> input = make::image(vals);
+
+ input = upscaling::art::scale3x(input);
+
+ mln_assertion(input == ref);
+}
--
1.5.6.5
1
0
22 Sep '09
---
milena/ChangeLog | 4 ++++
milena/mln/core/alias/dpoint2d.hh | 13 ++++++++++++-
2 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 21734a8..3100c37 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,7 @@
+2009-09-22 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ * mln/core/alias/dpoint2d.hh: Add new dpoint2d aliases.
+
2009-09-22 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Fix HSL values in test.
diff --git a/milena/mln/core/alias/dpoint2d.hh b/milena/mln/core/alias/dpoint2d.hh
index 687ae55..2dbd864 100644
--- a/milena/mln/core/alias/dpoint2d.hh
+++ b/milena/mln/core/alias/dpoint2d.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -59,6 +60,11 @@ namespace mln
extern const dpoint2d left;
extern const dpoint2d right;
+ extern const dpoint2d up_left;
+ extern const dpoint2d up_right;
+ extern const dpoint2d down_left;
+ extern const dpoint2d down_right;
+
/// \}
@@ -70,6 +76,11 @@ namespace mln
const dpoint2d left = dpoint2d( 0, -1 );
const dpoint2d right = dpoint2d( 0, +1 );
+ const dpoint2d up_left = dpoint2d( -1, -1 );
+ const dpoint2d up_right = dpoint2d( -1, +1 );
+ const dpoint2d down_left = dpoint2d( +1, -1 );
+ const dpoint2d down_right = dpoint2d( +1, +1 );
+
# endif // ! MLN_INCLUDE_ONLY
--
1.5.6.5
1
0
* green/mln/io/plot/save_histo_sh.hh (save_histo_sh<2d>) : New func.
---
trunk/milena/sandbox/ChangeLog | 6 +++
.../sandbox/green/mln/io/plot/save_histo_sh.hh | 42 +++++++++++++++++++-
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog
index 06426ad..16bbebb 100644
--- a/trunk/milena/sandbox/ChangeLog
+++ b/trunk/milena/sandbox/ChangeLog
@@ -1,5 +1,11 @@
2009-09-22 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
+ Adapt styles. Need some 2d code.
+ * green/mln/io/plot/save_histo_sh.hh (save_histo_sh<2d>) : New func.
+
+2009-09-22 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
Fix bug in histo3d_hsl count method.
* green/mln/accu/stat/histo3d_hsl.hh (take) : Fix bug.
diff --git a/trunk/milena/sandbox/green/mln/io/plot/save_histo_sh.hh b/trunk/milena/sandbox/green/mln/io/plot/save_histo_sh.hh
index e2d26e1..cfd3446 100644
--- a/trunk/milena/sandbox/green/mln/io/plot/save_histo_sh.hh
+++ b/trunk/milena/sandbox/green/mln/io/plot/save_histo_sh.hh
@@ -62,6 +62,10 @@ namespace mln
template <typename I>
void save_histo_sh(const image1d<I>& img, const std::string& filename);
+
+ template <typename I>
+ void save_histo_sh(const image2d<I>& img, const std::string& filename);
+
/// \brief Save an histogram image3d as a gnuplot script shell.
/// \param[in] img the 3d image which contains the data to save.
/// \param[in] filename the name of the unix script shell.
@@ -122,13 +126,47 @@ namespace mln
template <typename I>
inline
+ void save_histo_sh(const image2d<I>& img, const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save_histo_sh<2d>");
+ mln_precondition(img.is_valid());
+
+ std::ofstream out(filename.c_str());
+ mln_piter(image2d<I>) p(img.domain());
+
+ out << "#!/bin/sh" << std::endl;
+ out << "####################################" << std::endl;
+ out << "# Columns = (x,y,val) #" << std::endl;
+ out << "####################################" << std::endl;
+ out << std::endl;
+ out << "gnuplot <<EOF" << std::endl;
+ out << "set terminal x11 persist 1" << std::endl;
+ out << "splot '-' with points palette pointtype 0" << std::endl;
+
+ for_all(p)
+ //if (0 < img(p))
+ {
+ out << p.row() << " ";
+ out << p.col() << " ";
+ out << img(p) << std::endl;
+ }
+ out << "e" << std::endl;
+ out << "EOF" << std::endl;
+
+ out.close();
+ trace::exiting("mln::io::plot::save_histo_sh<2d>");
+ }
+
+
+ template <typename I>
+ inline
void save_histo_sh(const image3d<I>& img, const std::string& filename)
{
- trace::entering("mln::io::plot::save_histo_sh<3d>")
+ trace::entering("mln::io::plot::save_histo_sh<3d>");
mln_precondition(img.is_valid());
std::ofstream out(filename.c_str());
- mln_piter(I) p(img.domain());
+ mln_piter(image3d<I>) p(img.domain());
out << "#!/bin/sh" << std::endl;
out << "####################################" << std::endl;
--
1.5.6.5
1
0
---
trunk/milena/ChangeLog | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/trunk/milena/ChangeLog b/trunk/milena/ChangeLog
index da1d6c2..21734a8 100644
--- a/trunk/milena/ChangeLog
+++ b/trunk/milena/ChangeLog
@@ -189,6 +189,12 @@
* tests/geom/Makefile.am,
* tests/geom/translate.cc: New test.
+2009-09-15 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
+ Fix ISO C++ compilation problem : L101.
+
+ * mln/io/plot/load.hh (load) : Update source file.
+
2009-09-14 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Disable tiled2d image support (still experimental).
--
1.5.6.5
1
0
* green/mln/accu/stat/histo3d_hsl.hh (take) : Fix bug.
* green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc
(count_histo, mean_histo, var_histo, test_integration): Fix bug.
---
trunk/milena/sandbox/ChangeLog | 17 ++++
.../sandbox/green/mln/accu/stat/histo3d_hsl.hh | 20 ++++-
.../tests/accu/stat/histo3d_hsl/histo3d_hsl.cc | 92 +++++++++++--------
3 files changed, 87 insertions(+), 42 deletions(-)
diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog
index df395ef..06426ad 100644
--- a/trunk/milena/sandbox/ChangeLog
+++ b/trunk/milena/sandbox/ChangeLog
@@ -1,3 +1,20 @@
+2009-09-22 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
+ Fix bug in histo3d_hsl count method.
+
+ * green/mln/accu/stat/histo3d_hsl.hh (take) : Fix bug.
+ * green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc
+ (count_histo, mean_histo, var_histo, test_integration): Fix bug.
+
+2009-09-22 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
+ Put the basis of a general gnuplot shell export function.
+
+ * green/mln/io/plot/save_image_sh.hh : New library file.
+ * green/tests/io/plot/save_image_sh : New directory.
+ * green/tests/io/plot/save_image_sh/Makefile : New Makefile.
+ * green/tests/io/plot/save_image_sh/save_image_sh.cc : New unit tests.
+
2009-09-21 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Add disk_ima test, improve HSL operations.
diff --git a/trunk/milena/sandbox/green/mln/accu/stat/histo3d_hsl.hh b/trunk/milena/sandbox/green/mln/accu/stat/histo3d_hsl.hh
index c8e71ac..f29a725 100644
--- a/trunk/milena/sandbox/green/mln/accu/stat/histo3d_hsl.hh
+++ b/trunk/milena/sandbox/green/mln/accu/stat/histo3d_hsl.hh
@@ -277,9 +277,23 @@ namespace mln
// mln::trait::value_<argument>::get_comp_0(t);
// is def::coord1d the type of x, y, z ??
- unsigned x = (t.hue() - min_hue)/q;
- unsigned y = (t.lum() - min_lum)/q;
- unsigned z = (t.sat() - min_sat)/q;
+ unsigned x = (t.hue() - min_hue)/step_hue;
+ unsigned y = (t.lum() - min_lum)/step_lum;
+ unsigned z = (t.sat() - min_sat)/step_sat;
+
+
+ std::cout << "H : " << t.hue() << std::endl;
+ std::cout << "L : " << t.lum() << std::endl;
+ std::cout << "S : " << t.sat() << std::endl;
+
+ std::cout << "step_hue : " << step_hue << std::endl;
+ std::cout << "step_lum : " << step_lum << std::endl;
+ std::cout << "step_sat : " << step_sat << std::endl;
+
+ std::cout << "X : " << x << std::endl;
+ std::cout << "Y : " << y << std::endl;
+ std::cout << "Z : " << z << std::endl;
+
// faire attention avec les histoires de points et leurs coordonnées
++count_(point3d(z, x, y));
diff --git a/trunk/milena/sandbox/green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc b/trunk/milena/sandbox/green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc
index 27a6b64..47b3900 100644
--- a/trunk/milena/sandbox/green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc
+++ b/trunk/milena/sandbox/green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc
@@ -9,6 +9,7 @@
#include <mln/io/ppm/load.hh>
#include <mln/io/ppm/save.hh>
+#include <mln/io/pfm/save.hh>
#include <mln/io/plot/save.hh>
#include <mln/data/compute.hh>
@@ -196,18 +197,26 @@ double count_histo(const mln::image3d<unsigned>& img)
return result;
}
-mln::algebra::vec<3,float> conv(const mln::algebra::vec<3,float>& vec)
+mln::algebra::vec<3,float> conv(const mln::algebra::vec<3,float>& vec,
+ const unsigned q)
{
mln::algebra::vec<3,float> result;
- result[0] = vec[2];
- result[1] = vec[0];
- result[2] = vec[1];
+ /*
+ result[0] = vec[2] * (360.0/q);
+ result[1] = vec[0] * (1.0/q);
+ result[2] = vec[1] * (1.0/q);
+ */
+
+ result[0] = (vec[0]+0.5) * (360.0/q);
+ result[1] = (vec[1]+0.5) * (1.0/q);
+ result[2] = (vec[2]+0.5) * (1.0/q);
return result;
}
-mln::algebra::vec<3,float> mean_histo(const mln::image3d<unsigned>& img)
+mln::algebra::vec<3,float> mean_histo(const mln::image3d<unsigned>& img,
+ const unsigned q)
{
mln_precondition(img.is_valid());
typedef mln::algebra::vec<3,float> vec3f;
@@ -220,7 +229,7 @@ mln::algebra::vec<3,float> mean_histo(const mln::image3d<unsigned>& img)
for_all(p)
{
count += img(p);
- sum += conv((vec3f)p) * img(p);
+ sum += conv((vec3f)p, q) * img(p);
}
result = sum / count;
@@ -252,21 +261,22 @@ double var_histo(const mln::image3d<unsigned>& img)
return result;
}
-mln::algebra::mat<3,3,float> var_histo2(const mln::image3d<unsigned>& img)
+mln::algebra::mat<3,3,float> var_histo2(const mln::image3d<unsigned>& img,
+ const unsigned q)
{
mln_precondition(img.is_valid());
typedef mln::algebra::vec<3,float> vec3f;
typedef mln::algebra::mat<3,3,float> mat3f;
double count = count_histo(img);
- vec3f mean = mean_histo(img);
+ vec3f mean = mean_histo(img,q);
vec3f point;
mat3f result = mln::literal::zero;
mln_piter_(mln::image3d<unsigned>) p(img.domain());
for_all(p)
{
- point = conv((vec3f)p) - mean;
+ point = conv((vec3f)p, q) - mean;
result += img(p) * (point * point.t());
}
@@ -287,26 +297,19 @@ hslf_2_vec3f::operator()(const mln::value::hsl_f& hsl) const
return mln::make::vec(hsl.hue(), hsl.lum(), hsl.sat());
}
-
-template <typename A, typename I, typename F>
-mln_result(A)
-compute(mln::Accumulator<A>& a_,
- const mln::Image<I>& input_,
- const mln::Function_v2v<F>& fn_)
+struct hslf_2_h : public mln::Function_v2v< hslf_2_h >
{
- A& a = exact(a_);
- const I& input = exact(input_);
- const F& fn = exact(fn_);
-
- mln_piter(I) p(input.domain());
- for_all(p)
- a.take(fn(input(p)));
+ typedef float result;
+ result operator()(const mln::value::hsl_f& hsl) const;
+};
- return a.result();
+float
+hslf_2_h::operator()(const mln::value::hsl_f& hsl) const
+{
+ return hsl.hue();
}
-
-template <unsigned n>
+template <unsigned n, unsigned q>
void test_integration()
{
typedef mln::value::rgb8 rgb8;
@@ -314,31 +317,41 @@ void test_integration()
typedef mln::value::hsl_f hsl_f;
typedef mln::algebra::vec<3,float> vec3f;
typedef mln::algebra::mat<3,3,float> mat3f;
- typedef mln::accu::math::count<hsl_f> count;
- typedef mln::accu::math::sum<hsl_f,vec3f> sum;
- typedef mln::accu::stat::mean<hsl_f,vec3f,vec3f> mean;
+ typedef mln::accu::math::count<vec3f> count;
+ typedef mln::accu::math::sum<vec3f,vec3f> sum;
+ typedef mln::accu::stat::mean<vec3f,vec3f,vec3f> mean;
typedef mln::accu::stat::var<vec3f> var;
mln::image2d<rgb8> img_fst;
mln::image2d<rgbn> img_sec;
- mln::image2d<hsl_f> img_ref;
+ mln::image2d<hsl_f> img_thd;
+ mln::image2d<vec3f> img_ref;
mln::image3d<unsigned> img_res;
- mln::io::ppm::load(img_fst, OLENA_IMG_PATH"/lena.ppm");
+ mln::image2d<float> img_sav;
+
+ //mln::io::ppm::load(img_fst, OLENA_IMG_PATH"/lena.ppm")
+ mln::io::ppm::load(img_fst, OLENA_IMG_PATH"/fly.ppm");
img_sec = mln::data::transform(img_fst, mln::fun::v2v::rgb8_to_rgbn<n>());
- img_ref = mln::data::transform(img_sec,mln::fun::v2v::f_rgb_to_hsl_<hsl_f>());
+ img_thd = mln::data::transform(img_sec,mln::fun::v2v::f_rgb_to_hsl_<hsl_f>());
+
+ img_sav = mln::data::transform(img_thd, hslf_2_h());
+ mln::io::plot::save_histo_sh(img_sav, "fly2.sh");
- const double count_ref = compute(count(), img_ref, hslf_2_vec3f());
+ img_ref = mln::data::transform(img_thd, hslf_2_vec3f());
+
+ const double count_ref = mln::data::compute(count(), img_ref);
// const vec3f sum_ref = mln::data::compute(sum(), img_ref);
- const vec3f mean_ref = compute(mean(), img_ref, hslf_2_vec3f());
- const mat3f var_ref = compute(var(), img_ref, hslf_2_vec3f());
-
- img_res = mln::data::compute(mln::accu::stat::histo3d_hsl<n,hsl_f>(),img_ref);
+ const vec3f mean_ref = mln::data::compute(mean(), img_ref);
+ const mat3f var_ref = mln::data::compute(var(), img_ref);
+ img_res = mln::data::compute(mln::accu::stat::histo3d_hsl<q,hsl_f>(),img_thd);
+
+ mln::io::plot::save_histo_sh(img_res, "fly3.sh");
const double count_res = count_histo(img_res);
- const vec3f mean_res = mean_histo(img_res);
- const mat3f var_res = var_histo2(img_res);
+ const vec3f mean_res = mean_histo(img_res, q);
+ const mat3f var_res = var_histo2(img_res, q);
std::cout << "count_ref : " << count_ref << std::endl;
std::cout << "mean_ref : " << mean_ref << std::endl;
@@ -350,6 +363,7 @@ void test_integration()
mln_assertion(count_ref == count_res);
+
/*
mln_assertion(0.0001 > abs(mean_ref[0] - mean_res[0]));
mln_assertion(0.0001 > abs(mean_ref[1] - mean_res[1]));
@@ -402,7 +416,7 @@ int main()
test_initialization<3>();
test_take_argument<3>();
test_take_other<3>();
- test_integration<3>();
+ test_integration<3,7>();
return 0;
}
--
1.5.6.5
1
0
22 Sep '09
* green/mln/io/plot/save_image_sh.hh : New library file.
* green/tests/io/plot/save_image_sh : New directory.
* green/tests/io/plot/save_image_sh/Makefile : New Makefile.
* green/tests/io/plot/save_image_sh/save_image_sh.cc : New unit tests.
---
trunk/milena/sandbox/ChangeLog | 14 -
.../sandbox/green/mln/io/plot/save_image_sh.hh | 856 ++++++++++++++++++++
.../green/tests/io/plot/save_image_sh/Makefile.am | 148 ++++
.../tests/io/plot/save_image_sh/save_image_sh.cc | 662 +++++++++++++++
4 files changed, 1666 insertions(+), 14 deletions(-)
create mode 100644 trunk/milena/sandbox/green/mln/io/plot/save_image_sh.hh
create mode 100644 trunk/milena/sandbox/green/tests/io/plot/save_image_sh/Makefile.am
create mode 100644 trunk/milena/sandbox/green/tests/io/plot/save_image_sh/save_image_sh.cc
diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog
index 944d3af..df395ef 100644
--- a/trunk/milena/sandbox/ChangeLog
+++ b/trunk/milena/sandbox/ChangeLog
@@ -54,20 +54,6 @@
starting from (0,0).
Initialize image extension correctly.
-2009-09-15 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
-
- Fix bug in histo3d_rgb (parameters'order in Point's constructor)
-
- * green/mln/accu/stat/histo3d_hsl.hh
- (take) : Fix point's call.
- * green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc
- (conv) : Delete func.
- * green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc
- (mean_histo, var_histo2) : Update func.
-
- * green/mln/io/plot/save_histo_sh.hh : .
- * green/mln/io/plot/save_image_sh.hh : New library file.
-
2009-09-14 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
Fix bug in histo3d_rgb (parameters'order in Point's constructor)
diff --git a/trunk/milena/sandbox/green/mln/io/plot/save_image_sh.hh b/trunk/milena/sandbox/green/mln/io/plot/save_image_sh.hh
new file mode 100644
index 0000000..62f6652
--- /dev/null
+++ b/trunk/milena/sandbox/green/mln/io/plot/save_image_sh.hh
@@ -0,0 +1,856 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// 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_PLOT_SAVE_IMAGE_SH_HH
+#define MLN_IO_PLOT_SAVE_IMAGE_SH_HH
+
+/// \file
+///
+/// \brief Define some functions to export to gnuplot format as a script shell.
+///
+/// Theses routines are dedicated to image visualization. The aim is to display
+/// image whatever the value used as pixel. The behaviour of gnuplot is more
+/// like xv than imageMagick. A Gnuplot script shell file is a text dump file
+/// with a preambule to let gnuplot interpret data. As a script shell, you can
+/// launch it (don't forget the permissions), and every thing is packed in it.
+/// The script file call gnuplot in batch mode, the result window persists and
+/// that's all.
+///
+
+#include <fstream>
+#include <string>
+
+#include <mln/trace/entering.hh>
+#include <mln/trace/exiting.hh>
+#include <mln/core/macros.hh>
+#include <mln/core/contract.hh>
+#include <mln/core/image/image1d.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+
+#include <mln/geom/min_row.hh>
+#include <mln/geom/max_row.hh>
+#include <mln/geom/min_col.hh>
+#include <mln/geom/max_col.hh>
+#include <mln/value/int_u.hh>
+#include <mln/value/int_s.hh>
+#include <mln/value/rgb.hh>
+#include <mln/value/hsl.hh>
+#include <mln/value/hsi.hh>
+
+
+namespace mln
+{
+
+ namespace io
+ {
+
+ namespace plot
+ {
+
+ /// \brief Save an image as a gnuplot script shell.
+ ///
+ /// Every thing is save. The image could be 1d, 2d or 3d. The value of
+ /// the pixels could be int_u<n>, int_s<n>, float, double, hsl_f, hsl_d,
+ /// hsi_f, hsi_d and rgb<n>.
+ ///
+ /// \param[in] img the image which contains the data to save.
+ /// \param[in] filename the name of the unix script shell.
+ /// \return the status of the opening file operation.
+ ///
+ /// The result depends on the permission to save the file with
+ /// filename parameter as unix path. The script shell file must have the
+ /// permission to execute (chmod 755). Launch the script shell to call
+ /// gnuplot in batchmode with fine parameters.
+
+ template <typename I>
+ bool save_image_sh(const Image<I>& img, const std::string& filename);
+
+ } // end of namespace mln::accu::stat
+
+ } // end of namespace mln::accu
+
+
+ namespace io
+ {
+
+ namespace plot
+ {
+
+#ifndef MLN_INCLUDE_ONLY
+
+
+ //------------------------------------------------------------------------
+ // save_image_sh(const image2d<bool>&, const std::string&)
+ //------------------------------------------------------------------------
+
+ inline
+ bool save_image_sh_dispatch_overload(const image2d< bool >& img,
+ const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save_image_sh<image2d<bool>>");
+ mln_precondition(img.is_valid());
+
+ std::ofstream out(filename.c_str());
+ bool result = !out.fail();
+ unsigned min_row = geom::min_row(img);
+ unsigned max_row = geom::max_row(img);
+ unsigned min_col = geom::min_col(img);
+ unsigned max_col = geom::max_col(img);
+
+ if (result)
+ {
+ mln_piter_(image2d< bool >) p(img.domain());
+
+ // Output data prelude (terminal X11, image).
+ out << "#!/bin/sh" << std::endl;
+ out << "####################################" << std::endl;
+ out << "# Columns = (x, y, bool) #" << std::endl;
+ out << "####################################" << std::endl;
+ out << std::endl;
+ out << "gnuplot <<EOF" << std::endl;
+ out << "set terminal x11 persist 1" << std::endl;
+ out << "set palette gray" << std::endl;
+ out << "set xrange [" << min_col;
+ out << ":" << max_col;
+ out << "]" << std::endl;
+ out << "set yrange [-" << max_row;
+ out << ":" << min_row;
+ out << "]" << std::endl;
+ out << "plot '-' using (\\$2):(-\\$1):(\\$3) with image" << std::endl;
+
+ // Output data.
+ for_all(p)
+ {
+ out << p.row() << " ";
+ out << p.col() << " ";
+ out << img(p) << std::endl;
+ }
+
+ // Close gnuplot data stream.
+ out << "e" << std::endl;
+ out << "EOF" << std::endl;
+
+ out.close();
+ }
+ else
+ {
+ std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename;
+ std::cerr << " couldn't be opened !!" << std::endl;
+ }
+
+ trace::exiting("mln::io::plot::save_image_sh<image2d<bool>>");
+ return result;
+ }
+
+ //------------------------------------------------------------------------
+ // save_image_sh(const image2d<float>&, const std::string&)
+ //------------------------------------------------------------------------
+
+ inline
+ bool save_image_sh_dispatch_overload(const image2d<float>& img,
+ const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save_image_sh<image2d<float>>");
+ mln_precondition(img.is_valid());
+
+ std::ofstream out(filename.c_str());
+ bool result = !out.fail();
+ unsigned min_row = geom::min_row(img);
+ unsigned max_row = geom::max_row(img);
+ unsigned min_col = geom::min_col(img);
+ unsigned max_col = geom::max_col(img);
+
+ if (result)
+ {
+ mln_piter_(image2d< float >) p(img.domain());
+
+ // Output data prelude (terminal X11, image).
+ out << "#!/bin/sh" << std::endl;
+ out << "####################################" << std::endl;
+ out << "# Columns = (x, y, float) #" << std::endl;
+ out << "####################################" << std::endl;
+ out << std::endl;
+ out << "gnuplot <<EOF" << std::endl;
+ out << "set terminal x11 persist 1" << std::endl;
+ out << "set palette gray" << std::endl;
+ out << "set xrange [" << min_col;
+ out << ":" << max_col;
+ out << "]" << std::endl;
+ out << "set yrange [-" << max_row;
+ out << ":" << min_row;
+ out << "]" << std::endl;
+ out << "plot '-' using (\\$2):(-\\$1):(\\$3) with image" << std::endl;
+
+ // Output data.
+ for_all(p)
+ {
+ out << p.row() << " ";
+ out << p.col() << " ";
+ out << img(p) << std::endl;
+ }
+
+ // Close gnuplot data stream.
+ out << "e" << std::endl;
+ out << "EOF" << std::endl;
+
+ out.close();
+ }
+ else
+ {
+ std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename;
+ std::cerr << " couldn't be opened !!" << std::endl;
+ }
+
+ trace::exiting("mln::io::plot::save_image_sh<image2d<float>>");
+ return result;
+ }
+
+ //------------------------------------------------------------------------
+ // save_image_sh(const image2d<double>&, const std::string&)
+ //------------------------------------------------------------------------
+
+ inline
+ bool save_image_sh_dispatch_overload(const image2d<double>& img,
+ const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save_image_sh<image2d<double>>");
+ mln_precondition(img.is_valid());
+
+ std::ofstream out(filename.c_str());
+ bool result = !out.fail();
+ unsigned min_row = geom::min_row(img);
+ unsigned max_row = geom::max_row(img);
+ unsigned min_col = geom::min_col(img);
+ unsigned max_col = geom::max_col(img);
+
+ if (result)
+ {
+ mln_piter_(image2d< double >) p(img.domain());
+
+ // Output data prelude (terminal X11, image).
+ out << "#!/bin/sh" << std::endl;
+ out << "####################################" << std::endl;
+ out << "# Columns = (x, y, double) #" << std::endl;
+ out << "####################################" << std::endl;
+ out << std::endl;
+ out << "gnuplot <<EOF" << std::endl;
+ out << "set terminal x11 persist 1" << std::endl;
+ out << "set palette gray" << std::endl;
+ out << "set xrange [" << min_col;
+ out << ":" << max_col;
+ out << "]" << std::endl;
+ out << "set yrange [-" << max_row;
+ out << ":" << min_row;
+ out << "]" << std::endl;
+ out << "plot '-' using (\\$2):(-\\$1):(\\$3) with image" << std::endl;
+
+ // Output data.
+ for_all(p)
+ {
+ out << p.row() << " ";
+ out << p.col() << " ";
+ out << img(p) << std::endl;
+ }
+
+ // Close gnuplot data stream.
+ out << "e" << std::endl;
+ out << "EOF" << std::endl;
+
+ out.close();
+ }
+ else
+ {
+ std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename;
+ std::cerr << " couldn't be opened !!" << std::endl;
+ }
+
+ trace::exiting("mln::io::plot::save_image_sh<image2d<double>>");
+ return result;
+ }
+
+ //------------------------------------------------------------------------
+ // save_image_sh(const image2d<int_u<n>>&, const std::string&)
+ //------------------------------------------------------------------------
+
+ template <unsigned n>
+ inline
+ bool save_image_sh_dispatch_overload(const image2d<value::int_u<n> >& img,
+ const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save_image_sh<image2d<int_u<n>>");
+ mln_precondition(img.is_valid());
+
+ std::ofstream out(filename.c_str());
+ bool result = !out.fail();
+ unsigned min_row = geom::min_row(img);
+ unsigned max_row = geom::max_row(img);
+ unsigned min_col = geom::min_col(img);
+ unsigned max_col = geom::max_col(img);
+
+ if (result)
+ {
+ mln_piter(image2d< value::int_u<n> >) p(img.domain());
+
+ // Output data prelude (terminal X11, image).
+ out << "#!/bin/sh" << std::endl;
+ out << "####################################" << std::endl;
+ out << "# Columns = (x, y, int_u<n>) #" << std::endl;
+ out << "####################################" << std::endl;
+ out << std::endl;
+ out << "gnuplot <<EOF" << std::endl;
+ out << "set terminal x11 persist 1" << std::endl;
+ out << "set palette gray" << std::endl;
+ out << "set xrange [" << min_col;
+ out << ":" << max_col;
+ out << "]" << std::endl;
+ out << "set yrange [-" << max_row;
+ out << ":" << min_row;
+ out << "]" << std::endl;
+ out << "plot '-' using (\\$2):(-\\$1):(\\$3) with image" << std::endl;
+
+ // Output data.
+ for_all(p)
+ {
+ out << p.row() << " ";
+ out << p.col() << " ";
+ out << img(p) << std::endl;
+ }
+
+ // Close gnuplot data stream.
+ out << "e" << std::endl;
+ out << "EOF" << std::endl;
+
+ out.close();
+ }
+ else
+ {
+ std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename;
+ std::cerr << " couldn't be opened !!" << std::endl;
+ }
+
+ trace::exiting("mln::io::plot::save_image_sh<image2d<int_u<n>>");
+ return result;
+ }
+
+ //------------------------------------------------------------------------
+ // save_image_sh(const image2d<int_s<n>>&, const std::string&)
+ //------------------------------------------------------------------------
+
+ template <unsigned n>
+ inline
+ bool save_image_sh_dispatch_overload(const image2d<value::int_s<n> >& img,
+ const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save_image_sh<image2d<int_s<n>>");
+ mln_precondition(img.is_valid());
+
+ std::ofstream out(filename.c_str());
+ bool result = !out.fail();
+ unsigned min_row = geom::min_row(img);
+ unsigned max_row = geom::max_row(img);
+ unsigned min_col = geom::min_col(img);
+ unsigned max_col = geom::max_col(img);
+
+ if (result)
+ {
+ mln_piter(image2d< value::int_s<n> >) p(img.domain());
+
+ // Output data prelude (terminal X11, image).
+ out << "#!/bin/sh" << std::endl;
+ out << "####################################" << std::endl;
+ out << "# Columns = (x, y, int_s<n>) #" << std::endl;
+ out << "####################################" << std::endl;
+ out << std::endl;
+ out << "gnuplot <<EOF" << std::endl;
+ out << "set terminal x11 persist 1" << std::endl;
+ out << "set palette gray" << std::endl;
+ out << "set xrange [" << min_col;
+ out << ":" << max_col;
+ out << "]" << std::endl;
+ out << "set yrange [-" << max_row;
+ out << ":" << min_row;
+ out << "]" << std::endl;
+ out << "plot '-' using 2:(-\\$1):3 with image" << std::endl;
+
+ // Output data.
+ for_all(p)
+ {
+ out << p.row() << " ";
+ out << p.col() << " ";
+ out << img(p) << std::endl;
+ }
+
+ // Close gnuplot data stream.
+ out << "e" << std::endl;
+ out << "EOF" << std::endl;
+
+ out.close();
+ }
+ else
+ {
+ std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename;
+ std::cerr << " couldn't be opened !!" << std::endl;
+ }
+
+ trace::exiting("mln::io::plot::save_image_sh<image2d<int_s<n>>");
+ return result;
+ }
+
+ //------------------------------------------------------------------------
+ // save_image_sh(const image2d<rgb<n>>&, const std::string&)
+ //------------------------------------------------------------------------
+
+ template <unsigned n>
+ inline
+ bool save_image_sh_dispatch_overload(const image2d<value::rgb<n> >& img,
+ const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save_image_sh<image2d<rgb<n>>");
+ mln_precondition(img.is_valid());
+
+ std::ofstream out(filename.c_str());
+ bool result = !out.fail();
+ unsigned min_row = geom::min_row(img);
+ unsigned max_row = geom::max_row(img);
+ unsigned min_col = geom::min_col(img);
+ unsigned max_col = geom::max_col(img);
+
+ if (result)
+ {
+ mln_piter(image2d< value::int_u<n> >) p(img.domain());
+
+ // Output data prelude (terminal X11, image).
+ out << "#!/bin/sh" << std::endl;
+ out << "####################################" << std::endl;
+ out << "# Columns = (x, y, r, g, b) #" << std::endl;
+ out << "####################################" << std::endl;
+ out << std::endl;
+ out << "gnuplot <<EOF" << std::endl;
+ out << "set terminal x11 persist 1" << std::endl;
+ out << "set xrange [" << min_col;
+ out << ":" << max_col;
+ out << "]" << std::endl;
+ out << "set yrange [-" << max_row;
+ out << ":" << min_row;
+ out << "]" << std::endl;
+ out << "plot '-' using 2:(-\\$1):3:4:5 with rgbimage" << std::endl;
+
+ // Output data.
+ for_all(p)
+ {
+ out << p.row() << " ";
+ out << p.col() << " ";
+ out << img(p).red() << " ";
+ out << img(p).green() << " ";
+ out << img(p).blue() << std::endl;
+ }
+
+ // Close gnuplot data stream.
+ out << "e" << std::endl;
+ out << "EOF" << std::endl;
+
+ out.close();
+ }
+ else
+ {
+ std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename;
+ std::cerr << " couldn't be opened !!" << std::endl;
+ }
+
+ trace::exiting("mln::io::plot::save_image_sh<image2d<rgb<n>>");
+ return result;
+ }
+
+ //------------------------------------------------------------------------
+ // save_image_sh(const image2d<hsl_<T,T,T>>&, const std::string&)
+ //------------------------------------------------------------------------
+
+ template <typename T>
+ inline
+ bool save_image_sh(const image2d<mln::value::hsl_<T,T,T> >& img,
+ const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save_image_sh<image2d<hsl>>");
+ mln_precondition(img.is_valid());
+
+ std::ofstream out(filename.c_str());
+ bool result = !out.fail();
+ unsigned min_row = geom::min_row(img);
+ unsigned max_row = geom::max_row(img);
+ unsigned min_col = geom::min_col(img);
+ unsigned max_col = geom::max_col(img);
+
+ typedef mln::value::hsl_<T,T,T> hsl;
+
+ if (result)
+ {
+ mln_piter(image2d< hsl >) p(img.domain());
+
+ // Output data prelude (terminal X11, image).
+ out << "#!/bin/sh" << std::endl;
+ out << "####################################" << std::endl;
+ out << "# Columns = (x, y, val) #" << std::endl;
+ out << "####################################" << std::endl;
+ out << std::endl;
+ out << "gnuplot <<EOF" << std::endl;
+ out << "q(l,s) = (l < 0.5)? (l*(1+s)) : (l+s-(l*s))" << std::endl;
+ out << "p(l,s) = (2.0 * l - q(l,s))" << std::endl;
+ out << "n(x) = (x < 0)?(x+1) : (x > 1)?(x-1) : (x)"<< std::endl;
+ out << std::endl;
+ out << "c(p,q,t) = (t < (1.0/6.0))?(p+(q-p)*6.0*t):\\" << std::endl;
+ out << " (t < (1.0/2.0))?(q) :\\" << std::endl;
+ out << " (t < (2.0/3.0))?(p+(q-p)*6.0*((2.0/3.0)-t)):\\" << std::endl;
+ out << " (p)" << std::endl;
+ out << std::endl;
+ out << "r(h,s,l) = c(p(l,s),q(l,s),n(h/360.0+1.0/3.0))"<< std::endl;
+ out << "g(h,s,l) = c(p(l,s),q(l,s),n(h/360.0))" << std::endl;
+ out << "b(h,s,l) = c(p(l,s),q(l,s),n(h/360.0-1.0/3.0))"<< std::endl;
+ out << std::endl;
+ out << "set terminal x11 persist 1" << std::endl;
+ out << "set palette gray" << std::endl;
+ out << "set xrange [" << min_col;
+ out << ":" << max_col;
+ out << "]" << std::endl;
+ out << "set yrange [-" << max_row;
+ out << ":" << min_row;
+ out << "]" << std::endl;
+ out << "plot '-' using 2:(-\\$1):(r(\\$3,\\$4,\\$5)):\\" << std::endl;
+ out << " (g(\\$3,\\$4,\\$5)):\\" << std::endl;
+ out << " (b(\\$3,\\$4,\\$5)) with rgbimage"<< std::endl;
+
+ // Output data.
+ for_all(p)
+ {
+ out << p.row() << " ";
+ out << p.col() << " ";
+ out << img(p).hue() << " ";
+ out << img(p).sat() << " ";
+ out << img(p).lum() << std::endl;
+ }
+
+ // Close gnuplot data stream.
+ out << "e" << std::endl;
+ out << "EOF" << std::endl;
+
+ out.close();
+ }
+ else
+ {
+ std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename;
+ std::cerr << " couldn't be opened !!" << std::endl;
+ }
+
+ trace::exiting("mln::io::plot::save_image_sh<image2d<hsl>>");
+ return result;
+ }
+
+ //------------------------------------------------------------------------
+ // save_image_sh(const image2d<hsi_<T,T,T>>&, const std::string&)
+ //------------------------------------------------------------------------
+
+ template <typename T>
+ inline
+ bool save_image_sh(const image2d<mln::value::hsi_<T,T,T> >& img,
+ const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save_image_sh<2d>vf");
+ mln_precondition(img.is_valid());
+
+ std::ofstream out(filename.c_str());
+ bool result = !out.fail();
+ unsigned min_row = geom::min_row(img);
+ unsigned max_row = geom::max_row(img);
+ unsigned min_col = geom::min_col(img);
+ unsigned max_col = geom::max_col(img);
+
+ typedef mln::value::hsi_<T,T,T> hsi;
+
+ if (result)
+ {
+ mln_piter(image2d< hsi >) p(img.domain());
+
+ // Output data prelude (terminal X11, image).
+ out << "#!/bin/sh" << std::endl;
+ out << "####################################" << std::endl;
+ out << "# Columns = (x, y, val) #" << std::endl;
+ out << "####################################" << std::endl;
+ out << std::endl;
+ out << "gnuplot <<EOF" << std::endl;
+ out << "teta(h) = (h/180.0) * pi" << std::endl;
+ out << "alpha(s,h) = s*cos(teta(h))" << std::endl;
+ out << "beta(s,h) = s*sin(teta(h))" << std::endl;
+ out << "n(x) = (x < 0)?(x+1) : (x > 1)?(x-1) : (x)"<< std::endl;
+ out << std::endl;
+ out << "c(p,q,t) = (t < (1.0/6.0))?(p+(q-p)*6.0*t):\\" << std::endl;
+ out << " (t < (1.0/2.0))?(q) :\\" << std::endl;
+ out << " (t < (2.0/3.0))?(p+(q-p)*6.0*((2.0/3.0)-t)):\\" << std::endl;
+ out << " (p)" << std::endl;
+ out << std::endl;
+ out << "r(h,s,i) = (sqrt(3.0)/3.0) * i \\" << std::endl;
+ out << " + (2.0/(sqrt(6.0))) * beta(s,h)" << std::endl;
+ out << "g(h,s,i) = (sqrt(3.0)/3.0) * i \\" << std::endl;
+ out << " + (2.0/(sqrt(2.0))) * alpha(s,h) \\"<< std::endl;
+ out << " - (1.0/(sqrt(6.0))) * beta(s,h)" << std::endl;
+ out << "b(h,s,i) = (sqrt(3.0)/3.0) * i \\" << std::endl;
+ out << " - (2.0/(sqrt(2.0))) * alpha(s,h) \\"<< std::endl;
+ out << " - (1.0/(sqrt(6.0))) * beta(s,h)" << std::endl;
+ out << std::endl;
+ out << "set terminal x11 persist 1" << std::endl;
+ out << "set palette gray" << std::endl;
+ out << "set xrange [" << min_col;
+ out << ":" << max_col;
+ out << "]" << std::endl;
+ out << "set yrange [-" << max_row;
+ out << ":" << min_row;
+ out << "]" << std::endl;
+ out << "plot '-' using 2:(-\\$1):(r(\\$3,\\$4,\\$5)):\\" << std::endl;
+ out << " (g(\\$3,\\$4,\\$5)):\\" << std::endl;
+ out << " (b(\\$3,\\$4,\\$5)) with rgbimage"<< std::endl;
+
+ // Output data.
+ for_all(p)
+ {
+ out << p.row() << " ";
+ out << p.col() << " ";
+ out << img(p).hue() << " ";
+ out << img(p).sat() << " ";
+ out << img(p).inty() << std::endl;
+ }
+
+ // Close gnuplot data stream.
+ out << "e" << std::endl;
+ out << "EOF" << std::endl;
+
+ out.close();
+ }
+ else
+ {
+ std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename;
+ std::cerr << " couldn't be opened !!" << std::endl;
+ }
+
+ trace::exiting("mln::io::plot::save_image_sh<2d>vf");
+ return result;
+ }
+
+ //------------------------------------------------------------------------
+ // save_image_sh(const image2d<I>&, const std::string&)
+ //------------------------------------------------------------------------
+
+ template <typename I>
+ inline
+ bool save_image_sh_dispatch_overload(const image2d<I>& img,
+ const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save_image_sh<image2d<I>>");
+ mln_precondition(img.is_valid());
+
+ std::ofstream out(filename.c_str());
+ bool result = !out.fail();
+
+ if (result)
+ {
+ mln_piter(image2d<I>) p(img.domain());
+
+ // Output data prelude (terminal X11, image).
+ out << "#!/bin/sh" << std::endl;
+ out << "####################################" << std::endl;
+ out << "# Columns = (x, y, builtin) #" << std::endl;
+ out << "####################################" << std::endl;
+ out << std::endl;
+ out << "gnuplot <<EOF" << std::endl;
+ out << "set terminal x11 persist 1" << std::endl;
+ out << "set pm3d" << std::endl;
+ out << "set dgrid3d 20,20,2" << std::endl;
+ out << "splot '-' with lines" << std::endl;
+
+ // Output data.
+ for_all(p)
+ {
+ out << p.col() << " ";
+ out << p.row() << " ";
+ out << img(p) << std::endl;
+ }
+
+ // Close gnuplot data stream.
+ out << "e" << std::endl;
+ out << "EOF" << std::endl;
+
+ out.close();
+ }
+ else
+ {
+ std::cerr << "ERROR[mln::io::plot::save_image_sh]:"<< filename;
+ std::cerr << " couldn't be opened !!" << std::endl;
+ }
+
+ trace::exiting("mln::io::plot::save_image_sh<image2d<I>>");
+ return result;
+ }
+
+ //------------------------------------------------------------------------
+ // save_image_sh(const image1d<I>&, const std::string&)
+ //------------------------------------------------------------------------
+
+ template <typename I>
+ inline
+ bool save_image_sh_dispatch_overload(const image1d<I>& img,
+ const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save_image_sh<image1d<I>>");
+ mln_precondition(img.is_valid());
+
+ std::ofstream out(filename.c_str());
+ bool result = !out.fail();
+
+ if (result)
+ {
+ mln_piter(image1d<I>) p(img.domain());
+
+ // Output data prelude (terminal X11, impulse).
+ out << "#!/bin/sh" << std::endl;
+ out << "##########################" << std::endl;
+ out << "# Two columns = (x, val) #" << std::endl;
+ out << "##########################" << std::endl;
+ out << std::endl;
+ out << "gnuplot <<EOF" << std::endl;
+ out << "set terminal x11 persist 1" << std::endl;
+ out << "plot '-' with impulse" << std::endl;
+
+ // Output data.
+ for_all(p)
+ {
+ out << p.ind() << " ";
+ out << img(p) << std::endl;
+ }
+
+ // Close gnuplot data stream.
+ out << "e" << std::endl;
+ out << "EOF" << std::endl;
+
+ out.close();
+ }
+ else
+ {
+ std::cerr << "ERROR[mln::io::plot::save_image_sh]:"<< filename;
+ std::cerr << " couldn't be opened !!" << std::endl;
+ }
+
+ trace::exiting("mln::io::plot::save_image_sh<image1d<I>>");
+ return result;
+ }
+
+ //------------------------------------------------------------------------
+ // save_image_sh(const image3d<I>&, const std::string&)
+ //------------------------------------------------------------------------
+
+
+ template <typename I>
+ inline
+ bool save_image_sh(const image3d<I>& img, const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save_image_sh<image3d<I>>");
+ mln_precondition(img.is_valid());
+
+ std::ofstream out(filename.c_str());
+ bool result = !out.fail();
+
+ if (result)
+ {
+ mln_piter(image3d<I>) p(img.domain());
+
+ // Output data prelude (terminal X11, pointtype 0).
+ out << "#!/bin/sh" << std::endl;
+ out << "####################################" << std::endl;
+ out << "# Columns = (x, y, z, val) #" << std::endl;
+ out << "####################################" << std::endl;
+ out << std::endl;
+ out << "gnuplot <<EOF" << std::endl;
+ out << "set terminal x11 persist 1" << std::endl;
+ out << "splot '-' with points palette pointtype 7" << std::endl;
+
+ // Output data.
+ for_all(p)
+ {
+ out << p.row() << " ";
+ out << p.col() << " ";
+ out << p.sli() << " ";
+ out << img(p) << std::endl;
+ }
+
+ // Close gnuplot data stream.
+ out << "e" << std::endl;
+ out << "EOF" << std::endl;
+
+ out.close();
+ }
+ else
+ {
+ std::cerr << "ERROR[mln::io::plot::save_image_sh]:"<< filename;
+ std::cerr << " couldn't be opened !!" << std::endl;
+ }
+
+ trace::exiting("mln::io::plot::save_image_sh<image3d<I>>");
+ return result;
+ }
+
+ //------------------------------------------------------------------------
+ // Facade.
+ //------------------------------------------------------------------------
+
+ template <typename I>
+ inline
+ bool save_image_sh_dispatch(const Image<I>& img,
+ const std::string& filename)
+ {
+ return save_image_sh_dispatch_overload(exact(img), filename);
+ }
+
+ template <typename I>
+ inline
+ bool save_image_sh(const Image<I>& img, const std::string& filename)
+ {
+ trace::entering("mln::io::plot::save_image_sh");
+
+ bool result = save_image_sh_dispatch(img, filename);
+
+ trace::exiting("mln::io::plot::save_image_sh");
+ return result;
+ }
+
+
+#endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace mln::accu::stat
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+#endif // ! MLN_IO_PLOT_SAVE_IMAGE_SH_HH
diff --git a/trunk/milena/sandbox/green/tests/io/plot/save_image_sh/Makefile.am b/trunk/milena/sandbox/green/tests/io/plot/save_image_sh/Makefile.am
new file mode 100644
index 0000000..d970989
--- /dev/null
+++ b/trunk/milena/sandbox/green/tests/io/plot/save_image_sh/Makefile.am
@@ -0,0 +1,148 @@
+#
+# Generic Makefile
+#
+
+#########
+# TOOLS #
+#########
+
+INCLUDES= -I$(HOME)/svn/oln/trunk/milena/sandbox/green
+CXXFLAGS= -ggdb -O0 -Wall -W -pedantic -ansi -pipe $(INCLUDES)
+ECHO= echo
+RM= rm
+MKDIR= mkdir -p
+CP= cp
+
+SOURCE_PATTERN= green/tests
+BUILD__PATTERN= green/build/tests
+
+
+ifeq ($(findstring $(BUILD__PATTERN),$(PWD)), $(BUILD__PATTERN))
+# Case where make is done from build directory.
+SOURCE_DIR= $(subst $(BUILD__PATTERN),$(SOURCE_PATTERN),$(PWD))
+BUILD__DIR= $(PWD)
+else
+# Case where make is done from source directory.
+SOURCE_DIR= $(PWD)
+BUILD__DIR= $(subst $(SOURCE_PATTERN),$(BUILD__PATTERN),$(PWD))
+endif
+
+SRC= $(notdir $(wildcard $(SOURCE_DIR)/*.cc))
+OLD= $(notdir $(wildcard $(SOURCE_DIR)/*~))
+OBJ= $(patsubst %.cc,%.o,$(SRC))
+SOURCE_MAKEFILE=Makefile.am
+BUILD__MAKEFILE=Makefile
+TARGET_FILE= $(notdir $(PWD))
+SOURCE_FILES= $(notdir $(wildcard $(SOURCE_DIR)/*.*))
+BUILD__FILES= $(filter-out $(SRC) $(SOURCE_MAKEFILE), $(SOURCE_FILES))
+
+BUILD__F_PATH= $(addprefix $(BUILD__DIR)/,$(BUILD__FILES))
+SOURCE_F_PATH= $(addprefix $(SOURCE_DIR)/,$(SOURCE_FILES))
+
+BUILD__M_PATH= $(addprefix $(BUILD__DIR)/,$(BUILD__MAKEFILE))
+SOURCE_M_PATH= $(addprefix $(SOURCE_DIR)/,$(SOURCE_MAKEFILE))
+
+TARGET_F_PATH= $(addprefix $(BUILD__DIR)/,$(TARGET_FILE))
+OBJ_F_PATH= $(addprefix $(BUILD__DIR)/,$(OBJ))
+SRC_F_PATH= $(addprefix $(SOURCE_DIR)/,$(SRC))
+OLD_F_PATH= $(addprefix $(SOURCE_DIR)/,$(OLD))
+
+#############
+# BOOTSTRAP #
+#############
+
+
+bootstrap: $(BUILD__DIR) $(BUILD__F_PATH) $(BUILD__M_PATH)
+
+# Create, if nessary, the destination directory
+$(BUILD__DIR):
+ $(MKDIR) $(BUILD__DIR)
+
+# Copy, if nessary, all the files, except the Makefile.am
+$(BUILD__F_PATH): $(SOURCE_F_PATH)
+ $(CP) $(addprefix $(SOURCE_DIR)/,$(@F)) $@
+
+# Copy if nessary, the Makefile.am into Makefile
+$(BUILD__M_PATH): $(SOURCE_M_PATH)
+ $(CP) $(SOURCE_M_PATH) $(BUILD__M_PATH)
+
+
+#######
+# ALL #
+#######
+
+# We assume that the call is done from the build directory.
+# With the directive vpath, hidden files are found in the source directory.
+
+all: $(TARGET_F_PATH)
+
+
+$(TARGET_F_PATH): $(OBJ_F_PATH)
+ $(LINK.cc) $< $(LOADLIBES) $(LDLIBS) -o $@
+
+$(OBJ_F_PATH):$(SRC_F_PATH)
+ $(COMPILE.cc) $(OUTPUT_OPTION) $<
+
+
+#########
+# CLEAN #
+#########
+
+# Force every time the deletion
+clean: clean_target clean_obj clean_dst clean_old #clean_make
+
+
+clean_target:
+ -@$(RM) $(TARGET_F_PATH) &> /dev/null
+
+clean_obj:
+ -@$(RM) $(OBJ_F_PATH) &> /dev/null
+
+clean_dst:
+ -@$(RM) $(BUILD_F_PATH) &> /dev/null
+
+clean_make:
+ -@$(RM) $(BUILD_M_PATH) &> /dev/null
+
+clean_old:
+ -@$(RM) $(OLD_F_PATH) &> /dev/null
+
+
+#########
+# PRINT #
+#########
+
+print: print_tools print_bootstrap
+
+print_tools:
+ @$(ECHO) "HOME = $(HOME)"
+ @$(ECHO) "INCLUDES = $(INCLUDES)"
+ @$(ECHO) "CXXFLAGS = $(CXXFLAGS)"
+ @$(ECHO) "ECHO = $(ECHO)"
+ @$(ECHO) "RM = $(RM)"
+ @$(ECHO) "MKDIR = $(MKDIR)"
+ @$(ECHO) "CP = $(CP)"
+ @$(ECHO)
+
+print_bootstrap:
+ @$(ECHO) "PWD = $(PWD)"
+ @$(ECHO) "SOURCE_PATTERN = $(SOURCE_PATTERN)"
+ @$(ECHO) "BUILD__PATTERN = $(BUILD__PATTERN)"
+ @$(ECHO) "SOURCE_DIR = $(SOURCE_DIR)"
+ @$(ECHO) "BUILD__DIR = $(BUILD__DIR)"
+ @$(ECHO) "SOURCE_MAKEFILE = $(SOURCE_MAKEFILE)"
+ @$(ECHO) "BUILD__MAKEFILE = $(BUILD__MAKEFILE)"
+ @$(ECHO) "TARGET_FILE = $(TARGET_FILE)"
+ @$(ECHO) "SOURCE_FILES = $(SOURCE_FILES)"
+ @$(ECHO) "SOURCE_F_PATH = $(SOURCE_F_PATH)"
+ @$(ECHO) "BUILD__FILES = $(BUILD__FILES)"
+ @$(ECHO) "BUILD__F_PATH = $(BUILD__F_PATH)"
+ @$(ECHO) "BUILD__M_PATH = $(BUILD__M_PATH)"
+ @$(ECHO) "SOURCE_M_PATH = $(SOURCE_M_PATH)"
+ @$(ECHO) "SRC = $(SRC)"
+ @$(ECHO) "OBJ = $(OBJ)"
+ @$(ECHO) "OLD = $(OLD)"
+ @$(ECHO) "SRC_F_PATH = $(SRC_F_PATH)"
+ @$(ECHO) "OBJ_F_PATH = $(OBJ_F_PATH)"
+ @$(ECHO) "OLD_F_PATH = $(OLD_F_PATH)"
+ @$(ECHO)
diff --git a/trunk/milena/sandbox/green/tests/io/plot/save_image_sh/save_image_sh.cc b/trunk/milena/sandbox/green/tests/io/plot/save_image_sh/save_image_sh.cc
new file mode 100644
index 0000000..c9c817b
--- /dev/null
+++ b/trunk/milena/sandbox/green/tests/io/plot/save_image_sh/save_image_sh.cc
@@ -0,0 +1,662 @@
+/// TEST SAVE_IMAGE_SH.HH
+
+#include <iostream>
+#include <limits.h>
+
+#include <mln/img_path.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+#include <mln/value/int_s8.hh>
+#include <mln/value/int_s16.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/value/rgb16.hh>
+#include <mln/value/hsl.hh>
+#include <mln/value/hsi.hh>
+#include <mln/util/array.hh>
+#include <mln/core/macros.hh>
+#include <mln/core/image/image1d.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+
+#include <mln/fun/v2v/rgb_to_hsl.hh>
+#include <mln/fun/v2v/rgb_to_hsi.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/io/pgms/load.hh>
+#include <mln/io/ppm/load.hh>
+#include <mln/io/pbm/load.hh>
+#include <mln/io/plot/save_image_sh.hh>
+#include <mln/io/plot/load.hh>
+
+#include <mln/data/transform.hh>
+#include <mln/literal/colors.hh>
+#include <mln/debug/println.hh>
+
+//------------------------------------------------------------------------------
+// TEST TO SAVE UNSIGNED 8 BITS 1D GRAYSCALE IMAGE
+//------------------------------------------------------------------------------
+
+mln::image1d<mln::value::int_u8>
+convert_array_to_image1d(const mln::util::array<mln::value::int_u8>& array)
+{
+ typedef mln::value::int_u8 int_u8;
+ typedef mln::image1d<int_u8> image1d;
+ typedef mln::util::array<int_u8> array1d;
+
+ image1d result(array.nelements());
+
+ mln_piter_(image1d) p(result.domain());
+ mln_eiter_(array1d) e(array);
+
+ for_all_2(e, p)
+ {
+ result(p) = e.element();
+ }
+
+ return result;
+}
+
+void test_save_image_sh_1d()
+{
+ typedef mln::value::int_u8 int_u8;
+ typedef mln::image1d<int_u8> image1d;
+ typedef mln::util::array<int_u8> array1d;
+
+ image1d img;
+ array1d array;
+
+ mln::io::plot::load(array, OLENA_IMG_PATH"/fly.plot");
+ img = convert_array_to_image1d(array);
+
+ // Save it were it is impossible to do it !!
+ bool ref_false = mln::io::plot::save_image_sh(img, "/dev/null/fly.sh");
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img, "fly1d.sh");
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image 1d : ok" << std::endl;
+}
+
+//------------------------------------------------------------------------------
+// Test to save image2d<bool>
+//------------------------------------------------------------------------------
+
+
+void test_save_image2d_bool()
+{
+ typedef mln::image2d<bool> image2d_bool;
+ const char* null_lena = "/dev/null/lena2d_bool.sh";
+ const char* lena = "lena2d_bool.sh";
+
+ image2d_bool img_bool;
+
+ mln::io::pbm::load(img_bool, OLENA_IMG_PATH"/lena.pbm");
+
+ // Save it were it is impossible to do it !!
+ bool ref_false = mln::io::plot::save_image_sh(img_bool, null_lena);
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img_bool, lena);
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image2d<bool>: ok" << std::endl;
+}
+
+//------------------------------------------------------------------------------
+// Test to save image2d<int_u8>
+//------------------------------------------------------------------------------
+
+
+void test_save_image2d_int_u8()
+{
+ typedef mln::value::int_u8 int_u8;
+ typedef mln::image2d<int_u8> image2d_int_u8;
+ const char* null_lena = "/dev/null/lena2d_int_u8.sh";
+ const char* lena = "lena2d_int_u8.sh";
+
+ image2d_int_u8 img_int_u8;
+
+ mln::io::pgm::load(img_int_u8, OLENA_IMG_PATH"/lena.pgm");
+
+ // Save it were it is impossible to do it !!
+ bool ref_false = mln::io::plot::save_image_sh(img_int_u8, null_lena);
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img_int_u8, lena);
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image2d<int_u8>: ok" << std::endl;
+}
+
+//------------------------------------------------------------------------------
+// Test to save image2d<int_u16>
+//------------------------------------------------------------------------------
+
+struct int_u16_to_int_u8 : mln::Function_v2v< int_u16_to_int_u8 >
+{
+ typedef mln::value::int_u16 argument;
+ typedef mln::value::int_u8 result;
+
+ result operator()(const argument& c) const
+ {
+ result res(c / 256);
+
+ return res;
+ }
+};
+
+void test_save_image2d_int_u16()
+{
+ typedef mln::value::int_u8 int_u8;
+ typedef mln::value::int_u16 int_u16;
+ typedef mln::image2d<int_u8> image2d_int_u8;
+ typedef mln::image2d<int_u16> image2d_int_u16;
+ const char* null_lena = "/dev/null/lena2d_int_u16.sh";
+ const char* lena = "lena2d_int_u16.sh";
+
+ image2d_int_u8 img_int_u8;
+ image2d_int_u16 img_int_u16;
+
+ mln::io::pgm::load(img_int_u16, OLENA_IMG_PATH"/lena_16_gnuplot.pgm");
+ //img_int_u8 = mln::data::transform(img_int_u16, int_u16_to_int_u8());
+ //mln::io::pgm::save(img_int_u8, "lena_8.pgm");
+
+ // Save it were it is impossible to do it !!
+ bool ref_false = mln::io::plot::save_image_sh(img_int_u16, null_lena);
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img_int_u16, lena);
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image2d<int_u16> : ok" << std::endl;
+}
+
+
+//------------------------------------------------------------------------------
+// Test to save image2d<int_s8>
+//------------------------------------------------------------------------------
+
+struct int_u8_to_int_s8 : mln::Function_v2v< int_u8_to_int_s8 >
+{
+ typedef mln::value::int_u8 argument;
+ typedef mln::value::int_s8 result;
+
+ result operator()(const argument& c) const
+ {
+ argument tmp_int_u8;
+ result tmp_int_s8;
+ result res;
+
+ // Note : -127 <= int_s8 <= +127
+ if (UCHAR_MAX == c)
+ {
+ res = SCHAR_MAX;
+ }
+ else if (SCHAR_MAX < c)
+ {
+ tmp_int_u8 = c - SCHAR_MAX;
+ res = static_cast<mln::value::int_s8>(tmp_int_u8);
+ }
+ else
+ {
+ tmp_int_s8 = static_cast<mln::value::int_s8>(c) - SCHAR_MAX;
+ res = tmp_int_s8;
+ }
+
+ return res;
+ }
+};
+
+
+void test_save_image2d_int_s8()
+{
+ typedef mln::value::int_s8 int_s8;
+ typedef mln::value::int_u8 int_u8;
+ typedef mln::image2d<int_s8> image2d_int_s8;
+ typedef mln::image2d<int_u8> image2d_int_u8;
+ const char* null_lena = "/dev/null/lena2d_int_s8.sh";
+ const char* lena = "lena2d_int_s8.sh";
+
+ image2d_int_s8 img_int_s8;
+ image2d_int_u8 img_int_u8;
+
+ mln::io::pgm::load(img_int_u8, OLENA_IMG_PATH"/lena.pgm");
+ img_int_s8 = mln::data::transform(img_int_u8, int_u8_to_int_s8());
+
+ // Save it were it is impossible to do it !!
+ bool ref_false = mln::io::plot::save_image_sh(img_int_s8, null_lena);
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img_int_s8, lena);
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image2d<int_s8>: ok" << std::endl;
+}
+
+//------------------------------------------------------------------------------
+// Test to save image2d<int_s16>
+//------------------------------------------------------------------------------
+
+struct int_u16_to_int_s16 : mln::Function_v2v< int_u16_to_int_s16 >
+{
+ typedef mln::value::int_u16 argument;
+ typedef mln::value::int_s16 result;
+
+ result operator()(const argument& c) const
+ {
+ argument tmp_int_u16;
+ result tmp_int_s16;
+ result res;
+
+ if (USHRT_MAX == c)
+ {
+ res = SHRT_MAX;
+ }
+ else if (SHRT_MAX < c)
+ {
+ tmp_int_u16 = c - SHRT_MAX;
+ res = static_cast<mln::value::int_s16>(tmp_int_u16);
+ }
+ else
+ {
+ tmp_int_s16 = static_cast<mln::value::int_s16>(c) - SHRT_MAX;
+ res = tmp_int_s16;
+ }
+
+ return res;
+ }
+};
+
+void test_save_image2d_int_s16()
+{
+ typedef mln::value::int_u16 int_u16;
+ typedef mln::value::int_s16 int_s16;
+ typedef mln::image2d<int_s16> image2d_int_s16;
+ typedef mln::image2d<int_u16> image2d_int_u16;
+ const char* null_lena = "/dev/null/lena2d_int_s16.sh";
+ const char* lena = "lena2d_int_s16.sh";
+
+ image2d_int_s16 img_int_s16;
+ image2d_int_u16 img_int_u16;
+
+ mln::io::pgm::load(img_int_u16, OLENA_IMG_PATH"/lena_16_gnuplot.pgm");
+ img_int_s16 = mln::data::transform(img_int_u16, int_u16_to_int_s16());
+
+ // Save it were it is impossible to do it !!
+ bool ref_false = mln::io::plot::save_image_sh(img_int_s16, null_lena);
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img_int_s16, lena);
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image2d<int_s16> : ok" << std::endl;
+}
+
+
+//------------------------------------------------------------------------------
+// Test to save image2d<float>
+//------------------------------------------------------------------------------
+
+struct int_u8_to_float : mln::Function_v2v< int_u8_to_float >
+{
+ typedef mln::value::int_u8 argument;
+ typedef float result;
+
+ result operator()(const argument& c) const
+ {
+ result res = static_cast<float>(c)/3;
+
+ return res;
+ }
+};
+
+void test_save_image2d_float()
+{
+ typedef mln::value::int_u8 int_u8;
+ typedef mln::image2d<float> image2d_float;
+ typedef mln::image2d<int_u8> image2d_int_u8;
+ const char* null_lena = "/dev/null/lena2d_float.sh";
+ const char* lena = "lena2d_float.sh";
+
+ image2d_int_u8 img_int_u8;
+ image2d_float img_float;
+
+ mln::io::pgm::load(img_int_u8, OLENA_IMG_PATH"/lena.pgm");
+ img_float = mln::data::transform(img_int_u8, int_u8_to_float());
+
+ // Save it were it is impossible to do it !!
+ bool ref_false = mln::io::plot::save_image_sh(img_float, null_lena);
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img_float, lena);
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image2d<float> : ok" << std::endl;
+}
+
+//------------------------------------------------------------------------------
+// Test to save image2d<double>
+//------------------------------------------------------------------------------
+
+struct int_u16_to_double : mln::Function_v2v< int_u16_to_double >
+{
+ typedef mln::value::int_u16 argument;
+ typedef double result;
+
+ result operator()(const argument& c) const
+ {
+ result res = static_cast<float>(c)/256;
+
+ return res;
+ }
+};
+
+void test_save_image2d_double()
+{
+ typedef mln::value::int_u16 int_u16;
+ typedef mln::image2d<double> image2d_double;
+ typedef mln::image2d<int_u16> image2d_int_u16;
+ const char* null_lena = "/dev/null/lena2d_double.sh";
+ const char* lena = "lena2d_double.sh";
+
+ image2d_int_u16 img_int_u16;
+ image2d_double img_double;
+
+ mln::io::pgm::load(img_int_u16, OLENA_IMG_PATH"/lena_16_gnuplot.pgm");
+ img_double = mln::data::transform(img_int_u16, int_u16_to_double());
+
+ // Save it were it is impossible to do it !!
+ bool ref_false = mln::io::plot::save_image_sh(img_double, null_lena);
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img_double, lena);
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image2d<double> : ok" << std::endl;
+}
+
+
+
+//------------------------------------------------------------------------------
+// Test to save image2d<rgb8>
+//------------------------------------------------------------------------------
+
+void test_save_image2d_rgb8()
+{
+ typedef mln::value::rgb8 rgb8;
+ typedef mln::image2d<rgb8> image2d_rgb8;
+ const char* null_lena = "/dev/null/lena2d_rgb8.sh";
+ const char* lena = "lena2d_rgb8.sh";
+
+ image2d_rgb8 img_rgb8;
+
+ mln::io::ppm::load(img_rgb8, OLENA_IMG_PATH"/lena.ppm");
+
+ // Save it were it is impossible to do it !!
+ bool ref_false = mln::io::plot::save_image_sh(img_rgb8, null_lena);
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img_rgb8, lena);
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image2d<rgb8> : ok" << std::endl;
+}
+
+//------------------------------------------------------------------------------
+// Test to save image2d<rgb16>
+//------------------------------------------------------------------------------
+
+struct rgb16_to_int_u16 : mln::Function_v2v< rgb16_to_int_u16 >
+{
+ typedef mln::value::rgb16 argument;
+ typedef mln::value::int_u16 result;
+
+
+ result operator()(const argument& c) const
+ {
+ result res((c.red() + c.green() + c.blue())/3);
+
+ return res;
+ }
+};
+
+void test_save_image2d_rgb16()
+{
+ typedef mln::value::rgb16 rgb16;
+ typedef mln::value::int_u16 int_u16;
+ typedef mln::image2d<rgb16> image2d_rgb16;
+ typedef mln::image2d<int_u16> image2d_int_u16;
+ const char* null_lena = "/dev/null/lena2d_rgb16.sh";
+ const char* lena = "lena2d_rgb16.sh";
+ //const char* lena2 = "lena2d_int_u16.sh";
+
+
+ image2d_rgb16 img_rgb16;
+ image2d_int_u16 img_int_u16;
+
+ mln::io::ppm::load(img_rgb16, OLENA_IMG_PATH"/lena_16.ppm");
+ //img_int_u16 = mln::data::transform(img_rgb16, rgb16_to_int_u16());
+ //mln::io::pgm::save(img_int_u16, "lena_16.pgm");
+
+ // Save it were it is impossible to do it !!
+ bool ref_false=mln::io::plot::save_image_sh(img_rgb16, null_lena);
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img_rgb16, lena);
+ // mln::io::plot::save_image_sh(img_int_u16, lena2);
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image2d<rgb16> : ok" << std::endl;
+}
+
+
+//------------------------------------------------------------------------------
+// Test to save image2d<hsl_f>
+//------------------------------------------------------------------------------
+
+void test_save_image2d_hsl_f()
+{
+ typedef mln::value::hsl_f hsl_f;
+ typedef mln::value::rgb8 rgb8;
+ typedef mln::image2d<hsl_f> image2d_hsl_f;
+ typedef mln::image2d<rgb8> image2d_rgb8;
+ typedef mln::fun::v2v::f_rgb_to_hsl_<hsl_f> rgb_to_hsl;
+
+ const char* null_lena = "/dev/null/lena2d_hsl_f.sh";
+ const char* lena = "lena2d_hsl_f.sh";
+ image2d_hsl_f img_hsl_f;
+ image2d_rgb8 img_rgb8;
+
+ mln::io::ppm::load(img_rgb8, OLENA_IMG_PATH"/lena.ppm");
+ //mln::data::fill(img_rgb8, mln::literal::red);
+ //mln::data::fill(img_rgb8, mln::literal::green);
+ //mln::data::fill(img_rgb8, mln::literal::blue);
+ img_hsl_f = mln::data::transform(img_rgb8, rgb_to_hsl());
+
+
+ // Save it were it is impossible to do it !!
+ bool ref_false = mln::io::plot::save_image_sh(img_hsl_f, null_lena);
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img_hsl_f, lena);
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image2d<hsl_f> : ok" << std::endl;
+}
+
+//------------------------------------------------------------------------------
+// Test to save image2d<hsl_d>
+//------------------------------------------------------------------------------
+
+void test_save_image2d_hsl_d()
+{
+ typedef mln::value::hsl_d hsl_d;
+ typedef mln::value::rgb16 rgb16;
+ typedef mln::image2d<hsl_d> image2d_hsl_d;
+ typedef mln::image2d<rgb16> image2d_rgb16;
+ typedef mln::fun::v2v::f_rgb_to_hsl_<hsl_d> rgb_to_hsl;
+
+ const char* null_lena = "/dev/null/lena2d_hsl_d.sh";
+ const char* lena = "lena2d_hsl_d.sh";
+ image2d_hsl_d img_hsl_d;
+ image2d_rgb16 img_rgb16;
+
+ mln::io::ppm::load(img_rgb16, OLENA_IMG_PATH"/lena_16.ppm");
+ //mln::data::fill(img_rgb16, mln::literal::red);
+ //mln::data::fill(img_rgb16, mln::literal::green);
+ //mln::data::fill(img_rgb16, mln::literal::blue);
+ img_hsl_d = mln::data::transform(img_rgb16, rgb_to_hsl());
+
+
+ // Save it were it is impossible to do it !!
+ bool ref_false = mln::io::plot::save_image_sh(img_hsl_d, null_lena);
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img_hsl_d, lena);
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image2d<hsl_d> : ok" << std::endl;
+}
+
+
+//------------------------------------------------------------------------------
+// Test to save image2d<hsi_f>
+//------------------------------------------------------------------------------
+
+void test_save_image2d_hsi_f()
+{
+ typedef mln::value::hsi_f hsi_f;
+ typedef mln::value::rgb8 rgb8;
+ typedef mln::image2d<hsi_f> image2d_hsi_f;
+ typedef mln::image2d<rgb8> image2d_rgb8;
+ typedef mln::fun::v2v::f_rgb_to_hsi_<hsi_f> rgb_to_hsi;
+
+ const char* null_lena = "/dev/null/lena2d_hsi_f.sh";
+ const char* lena = "lena2d_hsi_f.sh";
+ image2d_hsi_f img_hsi_f;
+ image2d_rgb8 img_rgb8;
+
+ mln::io::ppm::load(img_rgb8, OLENA_IMG_PATH"/lena.ppm");
+ //mln::data::fill(img_rgb8, mln::literal::red);
+ //mln::data::fill(img_rgb8, mln::literal::green);
+ //mln::data::fill(img_rgb8, mln::literal::blue);
+ img_hsi_f = mln::data::transform(img_rgb8, rgb_to_hsi());
+
+
+ // Save it were it is impossible to do it !!
+ bool ref_false = mln::io::plot::save_image_sh(img_hsi_f, null_lena);
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img_hsi_f, lena);
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image2d<hsi_f> : ok" << std::endl;
+}
+
+//------------------------------------------------------------------------------
+// Test to save image2d<hsi_d>
+//------------------------------------------------------------------------------
+
+void test_save_image2d_hsi_d()
+{
+ typedef mln::value::hsi_d hsi_d;
+ typedef mln::value::rgb16 rgb16;
+ typedef mln::image2d<hsi_d> image2d_hsi_d;
+ typedef mln::image2d<rgb16> image2d_rgb16;
+ typedef mln::fun::v2v::f_rgb_to_hsi_<hsi_d> rgb_to_hsi;
+
+ const char* null_lena = "/dev/null/lena2d_hsi_d.sh";
+ const char* lena = "lena2d_hsi_d.sh";
+ image2d_hsi_d img_hsi_d;
+ image2d_rgb16 img_rgb16;
+
+ mln::io::ppm::load(img_rgb16, OLENA_IMG_PATH"/lena_16.ppm");
+ //mln::data::fill(img_rgb16, mln::literal::red);
+ //mln::data::fill(img_rgb16, mln::literal::green);
+ //mln::data::fill(img_rgb16, mln::literal::blue);
+ img_hsi_d = mln::data::transform(img_rgb16, rgb_to_hsi());
+
+
+ // Save it were it is impossible to do it !!
+ bool ref_false = mln::io::plot::save_image_sh(img_hsi_d, null_lena);
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img_hsi_d, lena);
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image2d<hsi_d> : ok" << std::endl;
+}
+
+//------------------------------------------------------------------------------
+// TEST TO SAVE 8 BITS 3D RGB IMAGE
+//------------------------------------------------------------------------------
+
+void test_save_image_sh_3d()
+{
+ typedef mln::value::int_u8 int_u8;
+ typedef mln::image3d<int_u8> image3d;
+ typedef mln::util::array<std::string> array1d;
+
+ image3d img;
+ array1d array;
+
+ for (unsigned i = 0; i < 5; i++)
+ array.append(OLENA_IMG_PATH"/fly.pgm");
+
+ mln::io::pgms::load(img, array);
+
+ // Save it were it is impossible to do it !!
+ bool ref_false = mln::io::plot::save_image_sh(img, "/dev/null/fly3d.sh");
+
+ // Save it where we have the full permissions.
+ bool ref_true = mln::io::plot::save_image_sh(img, "fly3d.sh");
+
+ mln_assertion(true == ref_true);
+ mln_assertion(false == ref_false);
+ std::cout << "save image 3d : ok" << std::endl;
+}
+
+
+int main()
+{
+ test_save_image_sh_1d();
+
+ test_save_image2d_bool();
+
+ test_save_image2d_int_u8();
+ test_save_image2d_int_u16();
+
+ test_save_image2d_int_s8();
+ test_save_image2d_int_s16();
+
+ test_save_image2d_float();
+ test_save_image2d_double();
+
+ test_save_image2d_rgb8();
+ test_save_image2d_rgb16();
+
+ test_save_image2d_hsl_f();
+ test_save_image2d_hsl_d();
+
+ test_save_image2d_hsi_f();
+ test_save_image2d_hsi_d();
+
+ test_save_image_sh_3d();
+
+ return 0;
+}
--
1.5.6.5
1
0
* mln/io/plot/load.hh (load) : Update source file.
---
trunk/milena/mln/io/plot/load.hh | 5 ++++-
trunk/milena/sandbox/ChangeLog | 14 ++++++++++++++
2 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/trunk/milena/mln/io/plot/load.hh b/trunk/milena/mln/io/plot/load.hh
index f13a3b6..2b381e4 100644
--- a/trunk/milena/mln/io/plot/load.hh
+++ b/trunk/milena/mln/io/plot/load.hh
@@ -97,7 +97,10 @@ namespace mln
arr.clear();
std::ifstream file_in(filename.c_str());
- int MAX_LENGTH = 100;
+ // int MAX_LENGTH = 100;
+ // ISO C++ CAN'T COMPILE WITH VARIABLE LENGTH ARRAY !!
+ // THUS MAKE IT CONSTANT
+ const int MAX_LENGTH = 100;
char line[MAX_LENGTH];
char delims[] = " ";
char *result = NULL;
diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog
index df395ef..944d3af 100644
--- a/trunk/milena/sandbox/ChangeLog
+++ b/trunk/milena/sandbox/ChangeLog
@@ -54,6 +54,20 @@
starting from (0,0).
Initialize image extension correctly.
+2009-09-15 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
+ Fix bug in histo3d_rgb (parameters'order in Point's constructor)
+
+ * green/mln/accu/stat/histo3d_hsl.hh
+ (take) : Fix point's call.
+ * green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc
+ (conv) : Delete func.
+ * green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc
+ (mean_histo, var_histo2) : Update func.
+
+ * green/mln/io/plot/save_histo_sh.hh : .
+ * green/mln/io/plot/save_image_sh.hh : New library file.
+
2009-09-14 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
Fix bug in histo3d_rgb (parameters'order in Point's constructor)
--
1.5.6.5
1
0
22 Sep '09
* green/mln/accu/stat/histo3d_rgb.hh
(take) : Fix point's call.
* green/tests/accu/stat/histo3d_rgb/histo3d_rgb.cc
(conv) : Delete func.
* green/tests/accu/stat/histo3d_rgb/histo3d_rgb.cc
(mean_histo, var_histo2) : Update func.
---
trunk/milena/sandbox/ChangeLog | 11 ++++++++++
.../sandbox/green/mln/accu/stat/histo3d_rgb.hh | 3 +-
.../tests/accu/stat/histo3d_rgb/histo3d_rgb.cc | 22 +------------------
3 files changed, 15 insertions(+), 21 deletions(-)
diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog
index cdf5a60..df395ef 100644
--- a/trunk/milena/sandbox/ChangeLog
+++ b/trunk/milena/sandbox/ChangeLog
@@ -56,6 +56,17 @@
2009-09-14 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+ Fix bug in histo3d_rgb (parameters'order in Point's constructor)
+
+ * green/mln/accu/stat/histo3d_rgb.hh
+ (take) : Fix point's call.
+ * green/tests/accu/stat/histo3d_rgb/histo3d_rgb.cc
+ (conv) : Delete func.
+ * green/tests/accu/stat/histo3d_rgb/histo3d_rgb.cc
+ (mean_histo, var_histo2) : Update func.
+
+2009-09-14 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
Move stats directory in doc/examples.
* green/doc/examples/stats : New directory.
diff --git a/trunk/milena/sandbox/green/mln/accu/stat/histo3d_rgb.hh b/trunk/milena/sandbox/green/mln/accu/stat/histo3d_rgb.hh
index 8a10c0b..461870a 100644
--- a/trunk/milena/sandbox/green/mln/accu/stat/histo3d_rgb.hh
+++ b/trunk/milena/sandbox/green/mln/accu/stat/histo3d_rgb.hh
@@ -247,7 +247,8 @@ namespace mln
// Just convert a greyscale value (int_u8 like) to a position for an
// iterator on the resulting image.
- ++count_(point3d(t.red(), t.green(), t.blue()));
+ // Take care to the constructor : Point(slice, row, column)
+ ++count_(point3d(t.blue(), t.red(), t.green()));
trace::exiting("mln::accu::stat::histo3d_rgb<V>::take");
}
diff --git a/trunk/milena/sandbox/green/tests/accu/stat/histo3d_rgb/histo3d_rgb.cc b/trunk/milena/sandbox/green/tests/accu/stat/histo3d_rgb/histo3d_rgb.cc
index 114a52d..eb87332 100644
--- a/trunk/milena/sandbox/green/tests/accu/stat/histo3d_rgb/histo3d_rgb.cc
+++ b/trunk/milena/sandbox/green/tests/accu/stat/histo3d_rgb/histo3d_rgb.cc
@@ -185,17 +185,6 @@ double count_histo(const mln::image3d<unsigned>& img)
return result;
}
-mln::algebra::vec<3,float> conv(const mln::algebra::vec<3,float>& vec)
-{
- mln::algebra::vec<3,float> result;
-
- result[0] = vec[2];
- result[1] = vec[0];
- result[2] = vec[1];
-
- return result;
-}
-
mln::algebra::vec<3,float> mean_histo(const mln::image3d<unsigned>& img)
{
mln_precondition(img.is_valid());
@@ -208,14 +197,8 @@ mln::algebra::vec<3,float> mean_histo(const mln::image3d<unsigned>& img)
for_all(p)
{
- /*
- std::cout << "(1) " << p << std::endl;
- std::cout << "(2) " << (vec3f)p << std::endl;
- std::cout << "(3) " << conv((vec3f)p) << std::endl;
- */
count += img(p);
- sum += conv((vec3f)p) * img(p);
- // sum += p.to_vec() * img(p);
+ sum += p.to_vec() * img(p);
}
result = sum / count;
@@ -261,8 +244,7 @@ mln::algebra::mat<3,3,float> var_histo2(const mln::image3d<unsigned>& img)
for_all(p)
{
- // point = p.to_vec() - mean;
- point = conv((vec3f)p) - mean;
+ point = p.to_vec() - mean;
result += img(p) * (point * point.t());
}
--
1.5.6.5
1
0
* green/doc/examples/stats : New directory.
* green/doc/examples/stats/Makefile.am : Copy makefile.
* green/doc/examples/stats/stats.cc : Copy source file.
* green/stats/stats.cc : Remove source file.
* green/stats/Makefile.am : Remove makefile.
* green/stats : Remove directory.
---
trunk/milena/sandbox/ChangeLog | 12 ++++++++++++
.../green/{ => doc/examples}/stats/Makefile.am | 0
.../green/{ => doc/examples}/stats/stats.cc | 0
3 files changed, 12 insertions(+), 0 deletions(-)
rename trunk/milena/sandbox/green/{ => doc/examples}/stats/Makefile.am (100%)
rename trunk/milena/sandbox/green/{ => doc/examples}/stats/stats.cc (100%)
diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog
index a8ad105..cdf5a60 100644
--- a/trunk/milena/sandbox/ChangeLog
+++ b/trunk/milena/sandbox/ChangeLog
@@ -54,6 +54,18 @@
starting from (0,0).
Initialize image extension correctly.
+2009-09-14 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
+ Move stats directory in doc/examples.
+
+ * green/doc/examples/stats : New directory.
+ * green/doc/examples/stats/Makefile.am : Copy makefile.
+ * green/doc/examples/stats/stats.cc : Copy source file.
+
+ * green/stats/stats.cc : Remove source file.
+ * green/stats/Makefile.am : Remove makefile.
+ * green/stats : Remove directory.
+
2009-09-13 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
Save work in progress for histo and hsl. Everything is updated.
diff --git a/trunk/milena/sandbox/green/stats/Makefile.am b/trunk/milena/sandbox/green/doc/examples/stats/Makefile.am
similarity index 100%
rename from trunk/milena/sandbox/green/stats/Makefile.am
rename to trunk/milena/sandbox/green/doc/examples/stats/Makefile.am
diff --git a/trunk/milena/sandbox/green/stats/stats.cc b/trunk/milena/sandbox/green/doc/examples/stats/stats.cc
similarity index 100%
rename from trunk/milena/sandbox/green/stats/stats.cc
rename to trunk/milena/sandbox/green/doc/examples/stats/stats.cc
--
1.5.6.5
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-09-22 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Fix HSL values in test.
* tests/fun/v2v/hsl_to_rgb.cc: Fix HSL values.
---
hsl_to_rgb.cc | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Index: trunk/milena/tests/fun/v2v/hsl_to_rgb.cc
===================================================================
--- trunk/milena/tests/fun/v2v/hsl_to_rgb.cc (revision 4515)
+++ trunk/milena/tests/fun/v2v/hsl_to_rgb.cc (revision 4516)
@@ -41,8 +41,8 @@
rgb8 ref[][2] = { { rgb8(0,0,0), rgb8(255,255,255) },
{ rgb8(128,128,128), rgb8(90,90, 90) } };
- hsl_f dat[][2] = { { hsl_f(0,0,0), hsl_f(0,0,255) },
- { hsl_f(0,0,128), hsl_f(0,0,90) } };
+ hsl_f dat[][2] = { { hsl_f(0,0,0), hsl_f(0,0,1.0) },
+ { hsl_f(0,0,128.0 / 255.0), hsl_f(0,0,90.0 / 255.0) } };
image2d<rgb8> ref_ima = make::image(ref);
image2d<hsl_f> ima = make::image(dat);
1
0