---
milena/ChangeLog | 5 +++
.../achromatism.hh => mln/fun/v2v/rgb_to_luma.hh} | 32 ++++++++++++-------
2 files changed, 25 insertions(+), 12 deletions(-)
copy milena/{sandbox/green/mln/fun/v2v/achromatism.hh => mln/fun/v2v/rgb_to_luma.hh}
(67%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index c4bed2c..edefc8e 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,8 @@
+2011-03-01 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ * mln/fun/v2v/rgb_to_luma.hh: New function for grayscale
+ conversion.
+
2011-02-17 Guillaume Lazzara <z(a)lrde.epita.fr>
* mln/util/array.hh: Add last() method.
diff --git a/milena/sandbox/green/mln/fun/v2v/achromatism.hh
b/milena/mln/fun/v2v/rgb_to_luma.hh
similarity index 67%
copy from milena/sandbox/green/mln/fun/v2v/achromatism.hh
copy to milena/mln/fun/v2v/rgb_to_luma.hh
index 72b545c..304a798 100644
--- a/milena/sandbox/green/mln/fun/v2v/achromatism.hh
+++ b/milena/mln/fun/v2v/rgb_to_luma.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,10 +23,10 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_FUN_V2V_ACHROMATISM_HH
-# define MLN_FUN_V2V_ACHROMATISM_HH
+#ifndef MLN_FUN_V2V_RGB_TO_LUMA_HH
+# define MLN_FUN_V2V_RGB_TO_LUMA_HH
-# include <mln/value/rgb8.hh>
+# include <mln/value/rgb.hh>
namespace mln
{
@@ -37,22 +37,30 @@ namespace mln
namespace v2v
{
- struct achromatism : public Function_v2v< achromatism >
+ template <typename T_luma>
+ struct rgb_to_luma : public Function_v2v< rgb_to_luma<T_luma> >
{
- typedef float result;
+ typedef T_luma result;
+
+ template <typename T_rgb>
+ T_luma operator()(const T_rgb& rgb) const;
- float operator()(const value::rgb8 rgb) const;
};
+
# ifndef MLN_INCLUDE_ONLY
- float achromatism::operator()(const value::rgb8 rgb) const
+ template <typename T_luma>
+ template <typename T_rgb>
+ inline
+ T_luma
+ rgb_to_luma<T_luma>::operator()(const T_rgb& rgb) const
{
- return (math::abs(rgb.red() - rgb.green())
- + math::abs(rgb.red() - rgb.blue())
- + math::abs(rgb.green() - rgb.blue()))/3.0;
+ float luma = 0.299 * rgb.red() + 0.587 * rgb.green() + 0.114 * rgb.blue();
+ return unsigned(luma + 0.49999);
}
+
# endif // !MLN_INCLUDE_ONLY
} // end of namespace fun::v2v
@@ -61,4 +69,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_FUN_V2V_ACHROMATISM_HH
+#endif // ! MLN_FUN_V2V_RGB_TO_LUMA_HH
--
1.5.6.5