Index: integre/ChangeLog
from Giovanni Palma <giovanni(a)lrde.epita.fr>
* ntg/color/yuv.hh: Change the working interval.
* ntg/color/yiq.hh: Change the working interval.
* ntg/color/xyz.hh: Change the Z upperbound value.
* ntg/color/nrgb.hh: Change the working interval.
* ntg/color/hsi.hh: Change the Saturation upper bound value.
Index: metalic/ChangeLog
from Astrid Wang <astrid(a)lrde.epita.fr>
* mlc/array/1d.hh: Add member function name(). Fix types in member
function normalize(). Add basic arithmetic operators.
* mlc/array/2d.hh: Likewise.
* mlc/array/3d.hh: Likewise.
Index: olena/ChangeLog
from Giovanni Palma <giovanni(a)lrde.epita.fr>
* oln/convert/nrgbhsi.hh: Remove file.
* oln/convert/nrgbhsl.hh: Remove file.
* oln/convert/nrgbhsv.h: Remove file.
* oln/convert/nrgbyiq.hh: Remove file.
* oln/convert/nrgbyuv.hh: Remove file.
* oln/convert/rgbyiq.hh: Add file. Add RGB to YIQ conversion code.
* oln/convert/rgbyuv.hh: Add file. Add RGB to YUV conversion code.
* oln/convert/rgbhsi.hh: Add file. Add RGB to HSI conversion code.
* oln/convert/rgbhsl.hh: Add file. Add RGB to HSL conversion code.
* oln/convert/rgbhsv.hh: Add file. Add RGB to HSV conversion code.
* Makefile.am: Make new file Referenced.
* tests/convert/Makefile.am: Remove tests on obsolete
functions. Add test on new functions.
* oln/convert/rgbxyz.hh: Correct the RGB to XYZ conversion.
* oln/convert/nrgbxyz.hh: Make it obsolete.
+2004-01-21 Astrid Wang <astrid(a)lrde.epita.fr>
+
+ * oln/snakes/snakes_base.hh,
+ * oln/snakes/snakes_base.hxx,
+ * oln/snakes/segment.hh,
+ * oln/snakes/segment.hxx,
+ * oln/snakes/node.hh,
+ * oln/snakes/node.hxx,
+ * oln/snakes/energies.hh,
+ * oln/snakes/energies.hxx,
+ * oln/snakes/greedy.hh,
+ * oln/snakes/greedy.hxx: New.
+
+2004-01-19 Astrid Wang <astrid(a)lrde.epita.fr>
+
+ * oln/core/point2d.hxx: Fix member function minus().
+ * oln/core/abstract/dpoint.hh: Add member function norm2().
+
2003-12-09 Nicolas Burrus <burrus_n(a)lrde.epita.fr>
* tests/core/Makefile.am: Put fftw libraries in LDADD instead of
Index: olena/oln/convert/nrgbxyz.hh
--- olena/oln/convert/nrgbxyz.hh Thu, 07 Aug 2003 02:08:21 +0200 david (oln/16_nrgbxyz.hh
1.11 640)
+++ olena/oln/convert/nrgbxyz.hh Thu, 22 Jan 2004 15:54:07 +0100 palma_g
(oln/16_nrgbxyz.hh 1.11 640)
@@ -48,6 +48,9 @@
namespace convert {
+ /*!
+ ** obsolete a composition should be performed with nrgb->rgb and rgb->xyz
+ */
template <unsigned inbits, unsigned outbits>
struct f_nrgb_to_xyz
: public abstract::color_conversion<3, inbits, nrgb_traits,
@@ -88,6 +91,9 @@
return f(v);
}
+ /*!
+ ** obsolete a composition should be performed with xyz->rgb and rgb->nrgb
+ */
template<unsigned inbits, unsigned outbits>
struct f_xyz_to_nrgb
: public abstract::color_conversion<3, inbits, xyz_traits,
Index: olena/oln/convert/rgbxyz.hh
--- olena/oln/convert/rgbxyz.hh Thu, 07 Aug 2003 02:08:21 +0200 david (oln/19_rgbxyz.hh
1.11 640)
+++ olena/oln/convert/rgbxyz.hh Thu, 22 Jan 2004 15:48:00 +0100 palma_g (oln/19_rgbxyz.hh
1.11 640)
@@ -59,7 +59,7 @@
vec<3, float> in = v.to_float();
vec<3, float> out;
out[xyz_X] = 0.490 * in[rgb_R] + 0.310 * in[rgb_G] + 0.200 * in[rgb_B];
- out[xyz_Y] = 0.177 * in[rgb_R] + 0.813 * in[rgb_G] + 0.011 * in[rgb_B];
+ out[xyz_Y] = 0.177 * in[rgb_R] + 0.812 * in[rgb_G] + 0.011 * in[rgb_B];
out[xyz_Z] = 0.010 * in[rgb_G] + 0.990 * in[rgb_B];
return out;
}
@@ -95,9 +95,9 @@
out[rgb_R] =
2.365 * in[xyz_X] - 0.896 * in[xyz_Y] - 0.468 * in[xyz_Z];
out[rgb_G] =
- - 0.515 * in[xyz_X] + 1.425 * in[xyz_Y] + 0.088 * in[xyz_Z];
+ - 0.515 * in[xyz_X] + 1.425 * in[xyz_Y] + 0.089 * in[xyz_Z];
out[rgb_B] =
- 0.005 * in[xyz_X] - 0.014 * in[xyz_Y] + 1.009 * in[xyz_Z];
+ 0.005 * in[xyz_X] - 0.014 * in[xyz_Y] + 1.01 * in[xyz_Z];
return out;
}
Index: olena/oln/core/abstract/dpoint.hh
--- olena/oln/core/abstract/dpoint.hh Thu, 07 Aug 2003 02:08:21 +0200 david
(oln/d/28_dpoint.hh 1.16 640)
+++ olena/oln/core/abstract/dpoint.hh Thu, 22 Jan 2004 21:39:15 +0100 palma_g
(oln/d/28_dpoint.hh 1.17 640)
@@ -30,6 +30,7 @@
# include <mlc/type.hh>
# include <oln/core/coord.hh>
+# include <ntg/real/builtin_float.hh>
namespace oln {
@@ -135,6 +136,16 @@
return true;
}
+ ntg::float_d
+ norm2(void) const
+ {
+ double norm = 0;
+
+ for (unsigned i = 0; i < dim; ++i)
+ norm += nth(i) * nth(i);
+ return sqrt(norm);
+ }
+
static std::string
name()
{
Index: olena/oln/core/point2d.hxx
--- olena/oln/core/point2d.hxx Mon, 28 Jul 2003 14:14:03 +0200 david (oln/c/29_point2d.hx
1.5 640)
+++ olena/oln/core/point2d.hxx Thu, 22 Jan 2004 21:40:42 +0100 palma_g
(oln/c/29_point2d.hx 1.6 640)
@@ -114,7 +114,7 @@
inline point2d
point2d::minus() const
{
- point2d p(row(), col());
+ point2d p(-row(), -col());
return p;
}
Index: metalic/mlc/array/1d.hh
--- metalic/mlc/array/1d.hh Thu, 07 Aug 2003 02:37:23 +0200 burrus_n (oln/f/23_array1d.hh
1.10 640)
+++ metalic/mlc/array/1d.hh Thu, 22 Jan 2004 21:39:18 +0100 palma_g (oln/f/23_array1d.hh
1.11 640)
@@ -31,9 +31,10 @@
# include <mlc/contract.hh>
# include <mlc/cmp.hh>
# include <mlc/array/objs.hh>
-
+# include <ntg/basics.hh>
# include <iostream>
+
// impl
# include <mlc/array/1d.hxx>
@@ -79,20 +80,28 @@
}
+ // Name
+
+ static std::string
+ name()
+ {
+ return std::string("array1d< Info, ") + ntg_name(T) + "
>";
+ }
+
+
//
// Operations on array
//
- typedef array1d<Info_,float> to_float; // FIXME : argh
-
// Normalize (absolute values -> relative values)
- to_float normalize()
+ array1d<Info_, ntg::float_s>
+ normalize()
{
- to_float tmp;
- float sum = 0.f; // FIXME: float only?
- const float epsilon = 0.01f; // FIXME : epsilon should be global
+ array1d<Info_, ntg::float_s> tmp;
+ ntg::float_s sum = 0.f;
+ const ntg::float_s epsilon = 0.01f; // FIXME : epsilon should be global
unsigned i;
for (i = 0; i < Info_::card; ++i)
sum += this->buffer_[i];
@@ -122,6 +131,59 @@
}
+ // Operators
+
+ // FIXME: This code should be factorized between 1d, 2d and 3d.
+ // Think of a mechanism similar to apply() and apply2().
+
+ template <class U>
+ array1d< Info, ntg_return_type(times, T, U) >
+ operator*(U w)
+ {
+ array1d< Info, ntg_return_type(times, T, U) > tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] * w;
+ return tmp;
+ }
+
+ template <class U>
+ array1d< Info, ntg_return_type(div, T, U) >
+ operator/(U w)
+ {
+ array1d< Info, ntg_return_type(div, T, U) > tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] / w;
+ return tmp;
+ }
+
+ self operator+(const self& rhs) const
+ {
+ self tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] + rhs.buffer_[i];
+ return tmp;
+ }
+ self& operator+=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info::card; ++i)
+ this->buffer_[i] += rhs.buffer_[i];
+ return *this;
+ }
+
+ self operator-(const self& rhs) const
+ {
+ self tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] - rhs.buffer_[i];
+ return tmp;
+ }
+ self& operator-=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info::card; ++i)
+ this->buffer_[i] -= rhs.buffer_[i];
+ return *this;
+ }
+
//
// Accessors
@@ -179,7 +241,6 @@
return *(buffer_ + Info_::center + i);
}
-
protected:
T buffer_[Info_::card];
@@ -202,8 +263,18 @@
// starter objects
- static internal::array1d_start_<int> ints_1d =
internal::array1d_start_<int>();
- static internal::array1d_start_<float> floats_1d =
internal::array1d_start_<float>();
+ // FIXME: what about other types? Replace this by a function
+ // returning a starter.
+
+# define array1d_starter(T) \
+ static internal::array1d_start_<T> T##s_1d =
internal::array1d_start_<T>()
+
+ array1d_starter(int); // ints_1d
+ array1d_starter(float); // floats_1d
+
+
+
+ // print
template<class Info, class T>
std::ostream& operator<<(std::ostream& ostr, const array1d<Info,
T>& rhs)
Index: metalic/mlc/array/2d.hh
--- metalic/mlc/array/2d.hh Thu, 07 Aug 2003 02:37:23 +0200 burrus_n (oln/f/21_array2d.hh
1.10 640)
+++ metalic/mlc/array/2d.hh Thu, 22 Jan 2004 21:39:19 +0100 palma_g (oln/f/21_array2d.hh
1.11 640)
@@ -31,6 +31,7 @@
# include <mlc/array/objs.hh>
# include <mlc/contract.hh>
# include <mlc/cmp.hh>
+# include <ntg/basics.hh>
# include <iostream>
@@ -78,19 +79,30 @@
return *this;
}
+
+ // Name
+
+ static std::string
+ name()
+ {
+ return std::string("array2d< Info, ") + ntg_name(T) + "
>";
+ }
+
+
+
//
// Operations on array
//
- typedef array2d<Info_, float> to_float; // FIXME : argh
// Normalize (absolute values -> relative values)
- to_float normalize()
+ array2d<Info_, ntg::float_s>
+ normalize()
{
- to_float tmp;
- float sum = 0.f; // FIXME: float only?
- const float epsilon = 0.01f; // FIXME : epsilon should be global
+ array2d<Info_, ntg::float_s> tmp;
+ ntg::float_s sum = 0.f;
+ const ntg::float_s epsilon = 0.01f; // FIXME : epsilon should be global
unsigned i;
for (i = 0; i < Info_::card; ++i)
sum += this->buffer_[i];
@@ -138,6 +150,60 @@
return tmp;
}
+ // Operators
+
+ // FIXME: This code should be factorized between 1d, 2d and 3d.
+ // Think of a mechanism similar to apply() and apply2().
+
+ template <class U>
+ array2d< Info, ntg_return_type(times, T, U) >
+ operator*(U w)
+ {
+ array2d< Info, ntg_return_type(times, T, U) > tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] * w;
+ return tmp;
+ }
+
+ template <class U>
+ array2d< Info, ntg_return_type(div, T, U) >
+ operator/(U w)
+ {
+ array2d< Info, ntg_return_type(div, T, U) > tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] / w;
+ return tmp;
+ }
+
+ self operator+(const self& rhs) const
+ {
+ self tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] + rhs.buffer_[i];
+ return tmp;
+ }
+ self& operator+=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info::card; ++i)
+ this->buffer_[i] += rhs.buffer_[i];
+ return *this;
+ }
+
+ self operator-(const self& rhs) const
+ {
+ self tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] - rhs.buffer_[i];
+ return tmp;
+ }
+ self& operator-=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info::card; ++i)
+ this->buffer_[i] -= rhs.buffer_[i];
+ return *this;
+ }
+
+
//
// Accessors
//
@@ -200,8 +266,6 @@
lesseq< nrow, Info_::nrows - Info_::center_row - 1 >::ensure();
lesseq< -Info_::center_col, ncol >::ensure();
lesseq< ncol, Info_::ncols - Info_::center_col - 1 >::ensure();
-
- // FIXME: return *(buffer_ + Info_::center + (row * Info_::ncols) + col);
return *(buffer_ + Info_::center + (nrow * Info_::ncols) + ncol);
}
@@ -228,8 +292,17 @@
// starter objects
- static internal::array2d_start_<int> ints_2d =
internal::array2d_start_<int>();
- static internal::array2d_start_<float> floats_2d =
internal::array2d_start_<float>();
+ // FIXME: what about other types? Replace this by a function
+ // returning a starter.
+
+# define array2d_starter(T) \
+ static internal::array2d_start_<T> T##s_2d =
internal::array2d_start_<T>()
+
+ array2d_starter(int); // ints_2d
+ array2d_starter(float); // floats_2d
+
+
+ // print
template<class Info, class T>
std::ostream& operator<<(std::ostream& ostr, const array2d<Info,
T>& rhs)
Index: metalic/mlc/array/3d.hh
--- metalic/mlc/array/3d.hh Thu, 07 Aug 2003 02:37:23 +0200 burrus_n (oln/f/19_array3d.hh
1.11 640)
+++ metalic/mlc/array/3d.hh Thu, 22 Jan 2004 21:39:19 +0100 palma_g (oln/f/19_array3d.hh
1.12 640)
@@ -31,6 +31,7 @@
# include <mlc/array/objs.hh>
# include <mlc/contract.hh>
# include <mlc/cmp.hh>
+# include <ntg/basics.hh>
# include <iostream>
@@ -82,20 +83,28 @@
}
+ // Name
+
+ static std::string
+ name()
+ {
+ return std::string("array3d< Info, ") + ntg_name(T) + "
>";
+ }
+
+
//
// Operations on array
//
- typedef array3d<Info_, float> to_float; // FIXME : argh
-
// Normalize (absolute values -> relative values)
- to_float normalize()
+ array3d<Info_, ntg::float_s>
+ normalize()
{
- to_float tmp;
- float sum = 0.f; // FIXME: float only?
- const float epsilon = 0.01f; // FIXME : epsilon should be global
+ array3d<Info_, ntg::float_s> tmp;
+ ntg::float_s sum = 0.f;
+ const ntg::float_s epsilon = 0.01f; // FIXME : epsilon should be global
unsigned i;
for (i = 0; i < Info_::card; ++i)
sum += this->buffer_[i];
@@ -119,7 +128,7 @@
operator-() const
{
enum { new_center = Info_::card - Info_::center - 1 };
- array3d<array3d_info< Info::nplanes, Info_::nrows, Info_::ncols, new_center,
Info_::i>,T> tmp;
+ array3d<array3d_info< Info_::nplanes, Info_::nrows, Info_::ncols, new_center,
Info_::i>,T> tmp;
for (unsigned i = 0; i < Info_::card; ++i)
tmp[Info_::card - i - 1] = this->operator[](i);
@@ -129,13 +138,68 @@
// Transpose
-
array3d<Info, T> transpose() const // FIXME
{
std::cerr << "[31m===> 3D transposition not implemented yet.
<===[0m" << std::endl;
throw not_implemented_yet();
}
+
+ // Operators
+
+ // FIXME: This code should be factorized between 1d, 2d and 3d.
+ // Think of a mechanism similar to apply() and apply2().
+
+ template <class U>
+ array3d< Info, ntg_return_type(times, T, U) >
+ operator*(U w)
+ {
+ array3d< Info, ntg_return_type(times, T, U) > tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] * w;
+ return tmp;
+ }
+
+ template <class U>
+ array3d< Info, ntg_return_type(div, T, U) >
+ operator/(U w)
+ {
+ array3d< Info, ntg_return_type(div, T, U) > tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] / w;
+ return tmp;
+ }
+
+ self operator+(const self& rhs) const
+ {
+ self tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] + rhs.buffer_[i];
+ return tmp;
+ }
+ self& operator+=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info::card; ++i)
+ this->buffer_[i] += rhs.buffer_[i];
+ return *this;
+ }
+
+ self operator-(const self& rhs) const
+ {
+ self tmp;
+ for (unsigned i = 0; i < Info::card; ++i)
+ tmp[i] = this->buffer_[i] - rhs.buffer_[i];
+ return tmp;
+ }
+ self& operator-=(const self& rhs)
+ {
+ for (unsigned i = 0; i < Info::card; ++i)
+ this->buffer_[i] -= rhs.buffer_[i];
+ return *this;
+ }
+
+
+
// template<class U> int operator,(U); // FIXME: why this?
//
@@ -207,8 +271,6 @@
lesseq< nrow, Info_::nrows - Info_::center_row - 1 >::ensure();
lesseq< -Info_::center_col, ncol >::ensure();
lesseq< ncol, Info_::ncols - Info_::center_col - 1 >::ensure();
-
- //FIXME: return *(buffer_ + Info_::center + (nplane * Info::nrows *
Info::ncols) + (row * Info::ncols) + col);
return *(buffer_ + Info_::center + (nplane * Info::nrows * Info::ncols) + (nrow *
Info::ncols) + ncol);
}
@@ -235,8 +297,17 @@
// starter objects
- static internal::array3d_start_<int> ints_3d =
internal::array3d_start_<int>();
- static internal::array3d_start_<float> floats_3d =
internal::array3d_start_<float>();
+ // FIXME: what about other types? Replace this by a function
+ // returning a starter.
+
+# define array3d_starter(T) \
+ static internal::array3d_start_<T> T##s_3d =
internal::array3d_start_<T>()
+
+ array3d_starter(int); // ints_3d
+ array3d_starter(float); // floats_3d
+
+
+ // print
template<class Info, class T>
std::ostream& operator<<(std::ostream& ostr, const array3d<Info,
T>& rhs)
@@ -256,6 +327,7 @@
return ostr;
}
+
} // end of mlc
#endif // ! METALIC_ARRAY_3D_HH
Index: integre/ntg/color/hsi.hh
--- integre/ntg/color/hsi.hh Mon, 28 Jul 2003 18:24:48 +0200 burrus_n (oln/i/20_hsi.hh
1.3.1.6 640)
+++ integre/ntg/color/hsi.hh Thu, 22 Jan 2004 17:26:30 +0100 palma_g (oln/i/20_hsi.hh
1.3.1.6 640)
@@ -45,7 +45,7 @@
template<> struct hsi_traits<hsi_S>
{
static float lower_bound() { return 0.; }
- static float upper_bound() { return 1.0801234; } //sqrt(7. / 6)
+ static float upper_bound() { return 0.816497; } //2 / sqrt(6)
};
template<> struct hsi_traits<hsi_I>
Index: integre/ntg/color/nrgb.hh
--- integre/ntg/color/nrgb.hh Wed, 30 Jul 2003 18:49:16 +0200 burrus_n (oln/i/19_nrgb.hh
1.5.1.5 640)
+++ integre/ntg/color/nrgb.hh Thu, 22 Jan 2004 17:50:09 +0100 palma_g (oln/i/19_nrgb.hh
1.5.1.5 640)
@@ -45,9 +45,29 @@
};
template<unsigned icomp> struct nrgb_traits;
- template<> struct nrgb_traits<nrgb_R> : public interval<0,1> {};
- template<> struct nrgb_traits<nrgb_G> : public interval<0,1> {};
- template<> struct nrgb_traits<nrgb_B> : public interval<0,1> {};
+ template<>
+ struct nrgb_traits<nrgb_R>
+ {
+ static float lower_bound() { return 0;}
+ static float upper_bound() { return 1.0885004;}
+ };
+
+
+ template<>
+ struct nrgb_traits<nrgb_G>
+ {
+ static float lower_bound() { return -0.3321984;}
+ static float upper_bound() { return 1.3189264;}
+ };
+
+
+ template<>
+ struct nrgb_traits<nrgb_B>
+ {
+ static float lower_bound() { return -0.0688480;}
+ static float upper_bound() { return 0.904727;}
+ };
+
typedef color<3,8,nrgb_traits> nrgb_8;
typedef color<3,16,nrgb_traits> nrgb_16;
Index: integre/ntg/color/xyz.hh
--- integre/ntg/color/xyz.hh Mon, 28 Jul 2003 18:24:48 +0200 burrus_n (oln/i/24_xyz.hh
1.3.1.6 640)
+++ integre/ntg/color/xyz.hh Thu, 22 Jan 2004 15:49:51 +0100 palma_g (oln/i/24_xyz.hh
1.3.1.6 640)
@@ -43,12 +43,7 @@
template<unsigned icomp> struct xyz_traits;
template<> struct xyz_traits<xyz_X> : public interval<0,1> {};
template<> struct xyz_traits<xyz_Y> : public interval<0,1> {};
-
- template<> struct xyz_traits<xyz_Z>
- {
- static float lower_bound() { return 0.; }
- static float upper_bound() { return 1.2; }
- };
+ template<> struct xyz_traits<xyz_Z> : public interval<0,1> {};
typedef color<3,8,xyz_traits> xyz_8;
typedef color<3,16,xyz_traits> xyz_16;
Index: integre/ntg/color/yiq.hh
--- integre/ntg/color/yiq.hh Mon, 28 Jul 2003 18:24:48 +0200 burrus_n (oln/i/23_yiq.hh
1.3.1.6 640)
+++ integre/ntg/color/yiq.hh Thu, 22 Jan 2004 18:59:48 +0100 palma_g (oln/i/23_yiq.hh
1.3.1.6 640)
@@ -45,14 +45,14 @@
template<> struct yiq_traits<yiq_I>
{
- static float lower_bound() { return -.6; }
- static float upper_bound() { return .6; }
+ static float lower_bound() { return -.4192; }
+ static float upper_bound() { return .5346; }
};
template<> struct yiq_traits<yiq_Q>
{
- static float lower_bound() { return -.6; }
- static float upper_bound() { return .6; }
+ static float lower_bound() { return -.6783; }
+ static float upper_bound() { return .6527; }
};
typedef color<3,8,yiq_traits> yiq_8;
Index: integre/ntg/color/yuv.hh
--- integre/ntg/color/yuv.hh Mon, 28 Jul 2003 18:24:48 +0200 burrus_n (oln/i/25_yuv.hh
1.3.1.6 640)
+++ integre/ntg/color/yuv.hh Thu, 22 Jan 2004 16:23:56 +0100 palma_g (oln/i/25_yuv.hh
1.3.1.6 640)
@@ -44,14 +44,14 @@
template<> struct yuv_traits<yuv_Y> : public interval<0,1> {};
template<> struct yuv_traits<yuv_U>
{
- static float lower_bound() { return -0.45; }
- static float upper_bound() { return 0.45; }
+ static float lower_bound() { return -0.517; }
+ static float upper_bound() { return 0.437; }
};
template<> struct yuv_traits<yuv_V>
{
- static float lower_bound() { return -0.62; }
- static float upper_bound() { return 0.62; }
+ static float lower_bound() { return -0.576; }
+ static float upper_bound() { return 0.654; }
};
typedef color<3,8,yuv_traits> yuv_8;
Index: olena/tests/convert/Makefile.am
--- olena/tests/convert/Makefile.am Fri, 01 Aug 2003 02:45:53 +0200 burrus_n
(oln/f/0_Makefile.a 1.13 640)
+++ olena/tests/convert/Makefile.am Thu, 22 Jan 2004 19:22:42 +0100 palma_g
(oln/f/0_Makefile.a 1.13 640)
@@ -4,74 +4,74 @@
include ../check/Makefile.check
check_PROGRAMS = \
- 8-nrgb-hsi \
- 8-nrgb-hsl \
- 8-nrgb-hsv \
- 8-nrgb-xyz \
- 8-nrgb-yiq \
- 8-nrgb-yuv \
+ 8-rgb-hsi \
+ 8-rgb-hsl \
+ 8-rgb-hsv \
+ 8-rgb-xyz \
+ 8-rgb-yiq \
+ 8-rgb-yuv \
8-rgb-nrgb \
8-rgb-xyz \
- f-8-nrgb-hsi \
- f-8-nrgb-hsl \
- f-8-nrgb-hsv \
- f-8-nrgb-xyz \
- f-8-nrgb-yiq \
- f-8-nrgb-yuv \
+ f-8-rgb-hsi \
+ f-8-rgb-hsl \
+ f-8-rgb-hsv \
+ f-8-rgb-xyz \
+ f-8-rgb-yiq \
+ f-8-rgb-yuv \
f-8-rgb-nrgb \
f-8-rgb-xyz
-XFAIL_TESTS = 8-rgb-nrgb$(EXEEXT)
+# XFAIL_TESTS = 8-rgb-nrgb$(EXEEXT)
## FIXME: Ideally, each _SOURCES should be defined as $(CONVSOURCES), with
## CONVSOURCES = convcomp.cc convcomp.hh
## but this triggers a bug in Automake 1.6.
-8_nrgb_hsi_SOURCES = conv.cc conv.hh
-8_nrgb_hsi_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=hsi -DEM=5
+8_rgb_hsi_SOURCES = conv.cc conv.hh
+8_rgb_hsi_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=hsi -DEM=5
-8_nrgb_hsl_SOURCES = conv.cc conv.hh
-8_nrgb_hsl_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=hsl -DEM=5
+8_rgb_hsl_SOURCES = conv.cc conv.hh
+8_rgb_hsl_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=hsl -DEM=5
-8_nrgb_hsv_SOURCES = conv.cc conv.hh
-8_nrgb_hsv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=hsv -DEM=3
+8_rgb_hsv_SOURCES = conv.cc conv.hh
+8_rgb_hsv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=hsv -DEM=3
-8_nrgb_xyz_SOURCES = conv.cc conv.hh
-8_nrgb_xyz_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=xyz -DEM=5
+8_rgb_xyz_SOURCES = conv.cc conv.hh
+8_rgb_xyz_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=xyz -DEM=5
-8_nrgb_yiq_SOURCES = conv.cc conv.hh
-8_nrgb_yiq_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=yiq -DEM=5
+8_rgb_yiq_SOURCES = conv.cc conv.hh
+8_rgb_yiq_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=yiq -DEM=6
-8_nrgb_yuv_SOURCES = conv.cc conv.hh
-8_nrgb_yuv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=yuv -DEM=6
+8_rgb_yuv_SOURCES = conv.cc conv.hh
+8_rgb_yuv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=yuv -DEM=6
8_rgb_nrgb_SOURCES = conv.cc conv.hh
8_rgb_nrgb_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=nrgb -DEM=6
-8_rgb_xyz_SOURCES = conv.cc conv.hh
-8_rgb_xyz_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=xyz -DEM=4
+# 8_rgb_xyz_SOURCES = conv.cc conv.hh
+# 8_rgb_xyz_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=xyz -DEM=4
-f_8_nrgb_hsi_SOURCES = convcomp.cc convcomp.hh
-f_8_nrgb_hsi_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=hsi -DEM=17.8723 -DEV=1099.78
+f_8_rgb_hsi_SOURCES = convcomp.cc convcomp.hh
+f_8_rgb_hsi_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=hsi -DEM=17.8723 -DEV=1099.78
-f_8_nrgb_hsl_SOURCES = convcomp.cc convcomp.hh
-f_8_nrgb_hsl_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=hsl -DEM=5.90563 -DEV=152.583
+f_8_rgb_hsl_SOURCES = convcomp.cc convcomp.hh
+f_8_rgb_hsl_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=hsl -DEM=5.90563 -DEV=152.583
-f_8_nrgb_hsv_SOURCES = convcomp.cc convcomp.hh
-f_8_nrgb_hsv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=hsv -DEM=1.10193 -DEV=74.3924
+f_8_rgb_hsv_SOURCES = convcomp.cc convcomp.hh
+f_8_rgb_hsv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=hsv -DEM=1.10193 -DEV=74.3924
-f_8_nrgb_xyz_SOURCES = convcomp.cc convcomp.hh
-f_8_nrgb_xyz_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=xyz -DEM=0.952448 -DEV=4.04194
+# f_8_nrgb_xyz_SOURCES = convcomp.cc convcomp.hh
+# f_8_nrgb_xyz_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=xyz -DEM=0.952448
-DEV=4.04194
-f_8_nrgb_yiq_SOURCES = convcomp.cc convcomp.hh
-f_8_nrgb_yiq_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=yiq -DEM=2.11554 -DEV=18.7004
+f_8_rgb_yiq_SOURCES = convcomp.cc convcomp.hh
+f_8_rgb_yiq_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=yiq -DEM=2.11554 -DEV=18.7004
-f_8_nrgb_yuv_SOURCES = convcomp.cc convcomp.hh
-f_8_nrgb_yuv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=nrgb -DDEST=yuv -DEM=5.20401 -DEV=1.36447
+f_8_rgb_yuv_SOURCES = convcomp.cc convcomp.hh
+f_8_rgb_yuv_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=yuv -DEM=5.20401 -DEV=1.36447
f_8_rgb_nrgb_SOURCES = convcomp.cc convcomp.hh
-f_8_rgb_nrgb_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=nrgb -DEM=0.426287 -DEV=1.97667
+f_8_rgb_nrgb_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=nrgb -DEM=0.692094 -DEV=0.329154
f_8_rgb_xyz_SOURCES = convcomp.cc convcomp.hh
f_8_rgb_xyz_CPPFLAGS = $(AM_CPPFLAGS) -DSRC=rgb -DDEST=xyz -DEM=0.865949 -DEV=0.356157
Index: olena/oln/Makefile.am
--- olena/oln/Makefile.am Thu, 27 Nov 2003 10:33:30 +0100 burrus_n (oln/q/47_Makefile.a
1.3.1.1.1.6.1.6 640)
+++ olena/oln/Makefile.am Thu, 22 Jan 2004 17:47:32 +0100 palma_g (oln/q/47_Makefile.a
1.3.1.1.1.6.1.6 640)
@@ -25,11 +25,11 @@
convert/conversion_ng_se.hh \
convert/force.hh \
convert/nrgbxyz.hh \
- convert/nrgbyiq.hh \
- convert/nrgbyuv.hh \
- convert/nrgbhsi.hh \
- convert/nrgbhsl.hh \
- convert/nrgbhsv.hh \
+ convert/rgbyiq.hh \
+ convert/rgbyuv.hh \
+ convert/rgbhsi.hh \
+ convert/rgbhsl.hh \
+ convert/rgbhsv.hh \
convert/rgbnrgb.hh \
convert/rgbxyz.hh \
convert/stretch.hh \
Index: olena/oln/convert/rgbhsv.hh
--- olena/oln/convert/rgbhsv.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/convert/rgbhsv.hh Thu, 22 Jan 2004 17:35:48 +0100 palma_g
(oln/j/35_rgbhsv.hh 644)
@@ -0,0 +1,188 @@
+// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+
+#ifndef OLENA_CONVERT_RGBHSV_HH
+# define OLENA_CONVERT_RGBHSV_HH
+
+# include <oln/basics.hh>
+# include <oln/convert/abstract/colorconv.hh>
+
+# include <ntg/basics.hh>
+# include <ntg/color/rgb.hh>
+# include <ntg/color/hsv.hh>
+
+# include <mlc/contract.hh>
+
+# include <sstream>
+
+/*-----------------------------------------------------------------.
+| The formulas used here come from ``Color Conversion Algorithms'' |
+`-----------------------------------------------------------------*/
+
+namespace oln {
+
+ using namespace ntg;
+
+ namespace convert {
+
+ template<unsigned inbits, unsigned outbits>
+ struct f_rgb_to_hsv
+ : public abstract::color_conversion<3, inbits, rgb_traits,
+ 3, outbits, hsv_traits, f_rgb_to_hsv<inbits, outbits> >
+ {
+ color<3, outbits, hsv_traits>
+ doit(const color<3, inbits, rgb_traits>& v) const
+ {
+ vec<3, float> in = v.to_float();
+ vec<3, float> out;
+ float max_in = std::max(in[rgb_R], std::max(in[rgb_B], in[rgb_G]));
+ float min_in = std::min(in[rgb_R], std::min(in[rgb_B], in[rgb_G]));
+ float delta = max_in - min_in;
+
+
+ out[hsv_V] = max_in;
+
+ if (max_in != 0)
+ out[hsv_S] = delta / max_in;
+ else
+ out[hsv_S] = 0;
+
+ if (out[hsv_S] == 0)
+ out[hsv_H] = -1; // undefined
+ else {
+ if (in[rgb_R] == max_in)
+ out[hsv_H] = (in[rgb_G] - in[rgb_B]) / delta;
+ else if (in[rgb_G] == max_in)
+ out[hsv_H] = 2 + (in[rgb_B] - in[rgb_R]) / delta;
+ else
+ out[hsv_H] = 4 + (in[rgb_R] - in[rgb_G]) / delta;
+ out[hsv_H] *= 60;
+ if (out[hsv_H] < 0)
+ out[hsv_H] += 360;
+ }
+
+ return out;
+ }
+
+ static std::string
+ name()
+ {
+ std::ostringstream s;
+ s << "f_rgb_to_hsv<" << inbits << ", " <<
outbits << '>';
+ s.str();
+ }
+ };
+
+ template <unsigned inbits, unsigned outbits>
+ color<3, outbits, hsv_traits>
+ rgb_to_hsv(const color<3, inbits, rgb_traits>& v)
+ {
+ f_rgb_to_hsv<inbits, outbits> f;
+ return f(v);
+ }
+
+ template<unsigned inbits, unsigned outbits>
+ struct f_hsv_to_rgb
+ : public abstract::color_conversion<3, inbits, hsv_traits,
+ 3, outbits, rgb_traits, f_hsv_to_rgb<inbits, outbits> >
+ {
+ color<3, outbits, rgb_traits>
+ doit(const color<3, inbits, hsv_traits>& v) const
+ {
+ vec<3, float> in = v.to_float();
+ vec<3, float> out;
+
+ if(in[hsv_S] == 0)
+ out[rgb_G] = out[rgb_B] = out[rgb_R] = in[hsv_V];
+ else
+ {
+ in[hsv_H] /= 60;
+ int i = (int)floor (in[hsv_H]);
+ float f = in[hsv_H] - i;
+ float p = in[hsv_V] * (1 - in[hsv_S]);
+ float q = in[hsv_V] * (1 - in[hsv_S] * f);
+ float t = in[hsv_V] * (1 - in[hsv_S] * (1 - f));
+
+ switch (i){
+ case 0:
+ case 6:
+ out[rgb_R] = in[hsv_V];
+ out[rgb_G] = t;
+ out[rgb_B] = p;
+ break;
+ case 1:
+ out[rgb_R] = q;
+ out[rgb_G] = in[hsv_V];
+ out[rgb_B] = p;
+ break;
+ case 2:
+ out[rgb_R] = p;
+ out[rgb_G] = in[hsv_V];
+ out[rgb_B] = t;
+ break;
+ case 3:
+ out[rgb_R] = p;
+ out[rgb_G] = q;
+ out[rgb_B] = in[hsv_V];
+ break;
+ case 4:
+ out[rgb_R] = t;
+ out[rgb_G] = p;
+ out[rgb_B] = in[hsv_V];
+ break;
+ default:
+ out[rgb_R] = in[hsv_V];
+ out[rgb_G] = p;
+ out[rgb_B] = q;
+ break;
+ }
+ }
+ return out;
+ }
+
+ static std::string
+ name()
+ {
+ std::ostringstream s;
+ s << "f_hsv_to_rgb<" << inbits << ", " <<
outbits << '>';
+ s.str();
+ }
+ };
+
+ template <unsigned inbits, unsigned outbits>
+ color<3, outbits, rgb_traits>
+ hsv_to_rgb(const color<3, inbits, hsv_traits>& v)
+ {
+ f_hsv_to_rgb<inbits, outbits> f;
+ return f(v);
+ }
+
+ } // convert
+} // oln
+
+#endif // OLENA_CONVERT_RGBHSV_HH
Index: olena/oln/convert/rgbhsl.hh
--- olena/oln/convert/rgbhsl.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/convert/rgbhsl.hh Thu, 22 Jan 2004 18:37:35 +0100 palma_g
(oln/j/36_rgbhsl.hh 644)
@@ -0,0 +1,185 @@
+// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+
+#ifndef OLENA_CONVERT_NRGBHSL_HH
+# define OLENA_CONVERT_NRGBHSL_HH
+
+# include <oln/basics.hh>
+# include <oln/convert/abstract/colorconv.hh>
+
+# include <ntg/basics.hh>
+# include <ntg/color/nrgb.hh>
+# include <ntg/color/hsl.hh>
+
+# include <mlc/contract.hh>
+
+# include <cstdlib>
+# include <sstream>
+
+/*------------------------------------------------------------------.
+| The formulas used here come from ``Color space conversion''; Paul |
+| Bourke. |
+`------------------------------------------------------------------*/
+namespace oln {
+
+ using namespace ntg;
+
+ namespace convert {
+ template<unsigned inbits, unsigned outbits>
+ struct f_rgb_to_hsl
+ : public abstract::color_conversion<3, inbits, rgb_traits,
+ 3, outbits, hsl_traits, f_rgb_to_hsl<inbits, outbits> >
+ {
+ color<3, outbits, hsl_traits>
+ doit(const color<3, inbits, rgb_traits>& v) const
+ {
+ vec<3, float> in = v.to_float();
+ vec<3, float> out;
+
+ float max_in = ntg::max(in[rgb_R], std::max(in[rgb_B], in[rgb_G]));
+ float min_in = ntg::min(in[rgb_R], std::min(in[rgb_B], in[rgb_G]));
+ float diff = max_in-min_in;
+
+ out[hsl_L] = (max_in + min_in) / 2;
+ if (std::abs(diff) <= FLT_EPSILON){
+ out[hsl_S] = 0;
+ out[hsl_H] = 0; // undefined
+ }
+ else {
+ if (out[hsl_L] <= 0.5)
+ out[hsl_S] = diff / (max_in + min_in);
+ else
+ out[hsl_S] = diff / (2 - max_in - min_in);
+
+
+ float r_dist = (max_in - in[rgb_R]) / diff;
+ float g_dist = (max_in - in[rgb_G]) / diff;
+ float b_dist = (max_in - in[rgb_B]) / diff;
+
+ if (in[rgb_R] == max_in)
+ out[hsl_H] = b_dist - g_dist;
+ else if(in[rgb_G] == max_in)
+ out[hsl_H] = 2 + r_dist - b_dist;
+ else if(in[rgb_B] == max_in)
+ out[hsl_H] = 4 + g_dist - r_dist;
+
+ out[hsl_H] *= 60;
+ if(out[hsl_H] < 0)
+ out[hsl_H] += 360;
+ }
+ return out;
+ }
+
+ static std::string
+ name()
+ {
+ std::ostringstream s;
+ s << "f_rgb_to_hsl<" << inbits << ", " <<
outbits << '>';
+ s.str();
+ }
+ };
+
+ template <unsigned inbits, unsigned outbits>
+ color<3, inbits, hsl_traits>
+ rgb_to_hsl(const color<3, outbits, rgb_traits>& v)
+ {
+ f_rgb_to_hsl<inbits, outbits> f;
+ return f(v);
+ }
+
+ namespace internal {
+ float
+ RGB(float q1, float q2, float hue)
+ {
+ if (hue >= 360)
+ hue -= 360;
+ if (hue < 0)
+ hue += 360;
+ if (hue < 60)
+ return q1 + (q2 - q1) * hue / 60;
+ else if (hue < 180)
+ return q2;
+ else if (hue < 240)
+ return q1 + (q2 - q1) * (240 - hue) / 60;
+ else
+ return q1;
+ }
+ }
+
+ template<unsigned inbits, unsigned outbits>
+ struct f_hsl_to_rgb
+ : public abstract::color_conversion<3, inbits, hsl_traits,
+ 3, outbits, rgb_traits, f_hsl_to_rgb<inbits, outbits> >
+ {
+ color<3, outbits, rgb_traits>
+ doit(const color<3, inbits, hsl_traits>& v) const
+ {
+ vec<3, float> in = v.to_float();
+ vec<3, float> out;
+ float p2;
+
+ if(in[hsl_L] < 0.5)
+ p2 = in[hsl_L] * (1+in[hsl_S]);
+ else
+ p2 = in[hsl_L] + in[hsl_S] - (in[hsl_L] * in[hsl_S]);
+
+ float p1 = 2 * in[hsl_L] - p2;
+
+ if(in[hsl_S] == 0)
+ out[rgb_R] = out[rgb_G] = out[rgb_B] = in[hsl_L];
+ else
+ {
+ out[rgb_R] = internal::RGB(p1, p2, in[hsl_H] + 120);
+ out[rgb_G] = internal::RGB(p1, p2, in[hsl_H]);
+ out[rgb_B] = internal::RGB(p1, p2, in[hsl_H] - 120);
+ }
+
+ return out;
+ }
+
+ static std::string
+ name()
+ {
+ std::ostringstream s;
+ s << "f_hsl_to_rgb<" << inbits << ", " <<
outbits << '>';
+ s.str();
+ }
+ };
+
+ template<unsigned inbits, unsigned outbits>
+ color<3, outbits, rgb_traits>
+ hsl_to_rgb(const color<3, inbits, hsl_traits>& v)
+ {
+ f_hsl_to_rgb<inbits, outbits> f;
+ return f(v);
+ }
+
+ } // convert
+} // oln
+
+#endif // OLENA_CONVERT_RGBHSL_HH
Index: olena/oln/convert/rgbhsi.hh
--- olena/oln/convert/rgbhsi.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/convert/rgbhsi.hh Thu, 22 Jan 2004 16:39:38 +0100 palma_g
(oln/j/37_rgbhsi.hh 644)
@@ -0,0 +1,136 @@
+// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+
+#ifndef OLENA_CONVERT_RGBHSI_HH
+# define OLENA_CONVERT_RGBHSI_HH
+
+# include <oln/convert/abstract/colorconv.hh>
+
+# include <ntg/basics.hh>
+# include <ntg/color/rgb.hh>
+# include <ntg/color/hsi.hh>
+
+# include <sstream>
+
+/*--------------------------------------------------------------.
+| The formulas used here come from ``Digital Image Processing |
+| Algorithms and Applications'', I. Pitas; Wiley-Interscience. |
+`--------------------------------------------------------------*/
+
+namespace oln {
+
+ using namespace ntg;
+
+ namespace convert {
+
+ static const float sqrt3_3 = sqrt(3) / 3;
+ static const float inv_sqrt6 = 1 / sqrt(6);
+ static const float inv_sqrt2 = 1 / sqrt(2);
+
+ template<unsigned inbits, unsigned outbits>
+ struct f_rgb_to_hsi
+ : public abstract::color_conversion<3, inbits, rgb_traits,
+ 3, outbits, hsi_traits, f_rgb_to_hsi<inbits, outbits> >
+ {
+ color<3, inbits, hsi_traits>
+ doit(const color<3, outbits, rgb_traits>& v) const
+ {
+ vec<3, float> in = v.to_float();
+ vec<3, float> out;
+ out[hsi_I] =
+ sqrt3_3 * in[rgb_R] + sqrt3_3 * in[rgb_G] + sqrt3_3 * in[rgb_B];
+ const float v1 = inv_sqrt2 * in[rgb_G] - inv_sqrt2 * in[rgb_B];
+ const float v2 = 2 * inv_sqrt6 * in[rgb_R] - inv_sqrt6 * in[rgb_G]
+ - inv_sqrt6 * in[rgb_B];
+ out[hsi_H] = atan2(v2, v1) / M_PI * 180.0;
+ if (out[hsi_H] < 0)
+ out[hsi_H] += 360.0;
+ assert(out[hsi_H] >= 0);
+ out[hsi_S] = sqrt(v1 * v1 + v2 * v2);
+ return out;
+ }
+
+ static std::string
+ name()
+ {
+ std::ostringstream s;
+ s << "f_rgb_to_hsi<" << inbits << ", " <<
outbits << '>';
+ s.str();
+ }
+ };
+
+ template <unsigned inbits, unsigned outbits>
+ color<3, outbits, hsi_traits>
+ rgb_to_hsi(const color<3, inbits, rgb_traits>& v)
+ {
+ f_rgb_to_hsi<inbits, outbits> f;
+
+ return f(v);
+ }
+
+ template<unsigned inbits, unsigned outbits>
+ struct f_hsi_to_rgb
+ : public abstract::color_conversion<3, inbits, hsi_traits,
+ 3, outbits, rgb_traits, f_hsi_to_rgb<inbits, outbits> >
+ {
+ color<3, outbits, rgb_traits>
+ doit(const color<3, inbits, hsi_traits>& v) const
+ {
+ vec<3, float> in = v.to_float();
+ vec<3, float> out;
+ const float h = in[hsi_H] / 180.0 * M_PI;
+ const float v1 = in[hsi_S] * cos(h);
+ const float v2 = in[hsi_S] * sin(h);
+ out[rgb_R] = sqrt3_3 * in[hsi_I] + 2 * inv_sqrt6 * v2;
+ out[rgb_G] = sqrt3_3 * in[hsi_I] + inv_sqrt2 * v1 - inv_sqrt6 * v2;
+ out[rgb_B] = sqrt3_3 * in[hsi_I] - inv_sqrt2 * v1 - inv_sqrt6 * v2;
+ return out;
+ }
+
+ static std::string
+ name()
+ {
+ std::ostringstream s;
+ s << "f_hsi_to_rgb<" << inbits << ", " <<
outbits << '>';
+ s.str();
+ }
+ };
+
+ template <unsigned inbits, unsigned outbits>
+ color<3, outbits, rgb_traits>
+ hsi_to_rgb (const color<3, inbits, hsi_traits>& v)
+ {
+ f_hsi_to_rgb<inbits, outbits> f;
+
+ return f(v);
+ }
+
+ } // convert
+} // oln
+
+#endif // OLENA_CONVERT_RGBHSI_HH
Index: olena/oln/convert/rgbyuv.hh
--- olena/oln/convert/rgbyuv.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/convert/rgbyuv.hh Thu, 22 Jan 2004 16:28:30 +0100 palma_g
(oln/j/38_rgbyuv.hh 644)
@@ -0,0 +1,126 @@
+// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+
+#ifndef OLENA_CONVERT_NRGBYUV_HH
+# define OLENA_CONVERT_NRGBYUV_HH
+
+# include <oln/convert/abstract/colorconv.hh>
+
+# include <ntg/color/rgb.hh>
+# include <ntg/color/yuv.hh>
+# include <ntg/basics.hh>
+
+# include <sstream>
+
+/*---------------------------------------------------------------.
+| The formulas used here come from ``Colour Space Conversions'', |
+| IAdrian Ford and Alan Roberts; August 11,1998. |
+`---------------------------------------------------------------*/
+
+namespace oln {
+
+ using namespace ntg;
+
+ namespace convert {
+
+ template <unsigned inbits, unsigned outbits>
+ struct f_rgb_to_yuv
+ : public abstract::color_conversion<3, inbits, rgb_traits,
+ 3, outbits, yuv_traits, f_rgb_to_yuv<inbits, outbits> >
+ {
+ color<3, outbits, yuv_traits>
+ doit(const color<3, inbits, rgb_traits>& v) const
+ {
+ vec<3, float> in = v.to_float();
+ vec<3, float> out;
+ out[yuv_Y] =
+ + 0.177 * in[rgb_R] + 0.813 * in[rgb_G] + 0.01 * in[rgb_B];
+ out[yuv_U] =
+ - 0.083 * in[rgb_R] - 0.434 * in[rgb_G] + 0.437 * in[rgb_B];
+ out[yuv_V] =
+ + 0.583 * in[rgb_R] - 0.576 * in[rgb_G] + 0.071 * in[rgb_B];
+ return out;
+ }
+
+ static std::string
+ name()
+ {
+ std::ostringstream s;
+ s << "f_rgb_to_yuv<" << inbits << ", " <<
outbits << '>';
+ s.str();
+ }
+ };
+
+ template <unsigned inbits, unsigned outbits>
+ color<3, outbits, yuv_traits>
+ rgb_to_yuv(const color<3, inbits, rgb_traits>& v)
+ {
+ f_rgb_to_yuv<inbits, outbits> f;
+
+ return f(v);
+ }
+
+ template<unsigned inbits, unsigned outbits>
+ struct f_yuv_to_rgb
+ : public abstract::color_conversion<3, inbits, yuv_traits,
+ 3, outbits, rgb_traits, f_yuv_to_rgb<inbits, outbits> >
+ {
+ color<3, outbits, rgb_traits>
+ doit(const color<3, inbits, yuv_traits>& v) const
+ {
+ vec<3, float> in = v.to_float();
+ vec<3, float> out;
+ out[rgb_R] = 0.8702 * in[yuv_Y] - 0.2487 * in[yuv_U] + 1.4250 * in[yuv_V];
+ out[rgb_G] = 1.0259 * in[yuv_Y] + 0.0259 * in[yuv_U] - 0.3072 * in[yuv_V];
+ out[rgb_B] = 1.1837 * in[yuv_Y] + 2.2642 * in[yuv_U] - 0.0359 * in[yuv_V];
+
+ return out;
+ }
+
+ static std::string
+ name()
+ {
+ std::ostringstream s;
+ s << "f_yuv_to_rgb<" << inbits << ", " <<
outbits << '>';
+ s.str();
+ }
+ };
+
+ template <unsigned inbits, unsigned outbits>
+ color<3, outbits, rgb_traits>
+ yuv_to_rgb(const color<3, inbits, yuv_traits>& v)
+ {
+ f_yuv_to_rgb<inbits, outbits> f;
+
+ return f(v);
+ }
+
+ } // convert
+} // oln
+
+#endif // OLENA_CONVERT_RGBYUV_HH
Index: olena/oln/convert/rgbyiq.hh
--- olena/oln/convert/rgbyiq.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/convert/rgbyiq.hh Thu, 22 Jan 2004 16:35:28 +0100 palma_g
(oln/j/39_rgbyiq.hh 644)
@@ -0,0 +1,125 @@
+// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+
+#ifndef OLENA_CONVERT_RGBYIQ_HH
+# define OLENA_CONVERT_RGBYIQ_HH
+
+# include <oln/convert/abstract/colorconv.hh>
+
+# include <ntg/color/rgb.hh>
+# include <ntg/color/yiq.hh>
+# include <ntg/basics.hh>
+
+# include <sstream>
+
+/*--------------------------------------------------------------.
+| The formulas used here come from ``Digital Image Processing |
+| Algorithms and Applications'', I. Pitas; Wiley-Interscience. |
+`--------------------------------------------------------------*/
+
+namespace oln {
+
+ using namespace ntg;
+
+ namespace convert {
+
+ template<unsigned inbits, unsigned outbits>
+ struct f_rgb_to_yiq
+ : public abstract::color_conversion<3, inbits, rgb_traits,
+ 3, outbits, yiq_traits, f_rgb_to_yiq<inbits, outbits> >
+ {
+ color<3, inbits, yiq_traits>
+ doit(const color<3, outbits, rgb_traits>& v) const
+ {
+ vec<3, float> in = v.to_float();
+ vec<3, float> out;
+ out[yiq_Y] =
+ 0.1768 * in[rgb_R] + 0.8130 * in[rgb_G] + 0.0101 * in[rgb_B];
+ out[yiq_I] =
+ 0.5346 * in[rgb_R] - 0.2461 * in[rgb_G] - 0.1791 * in[rgb_B];
+ out[yiq_Q] =
+ 0.2474 * in[rgb_R] - 0.6783 * in[rgb_G] + 0.4053 * in[rgb_B];
+ return out;
+ }
+
+ static std::string
+ name()
+ {
+ std::ostringstream s;
+ s << "f_rgb_to_yiq<" << inbits << ", " <<
outbits << '>';
+ s.str();
+ }
+ };
+
+ template <unsigned inbits, unsigned outbits>
+ color<3, outbits, yiq_traits>
+ rgb_to_yiq(const color<3, inbits, rgb_traits>& v)
+ {
+ f_rgb_to_yiq<inbits, outbits> f;
+
+ return f(v);
+ }
+
+ template<unsigned inbits, unsigned outbits>
+ struct f_yiq_to_rgb
+ : public abstract::color_conversion<3, inbits, yiq_traits,
+ 3, outbits, rgb_traits, f_yiq_to_rgb<inbits, outbits> >
+ {
+ color<3, inbits, rgb_traits>
+ doit(const color<3, outbits, yiq_traits>& v) const
+ {
+ vec<3, float> in = v.to_float();
+ vec<3, float> out;
+ out[rgb_R] = 0.87 * in[yiq_Y] + 1.3223 * in[yiq_I] + 0.5628 * in[yiq_Q];
+ out[rgb_G] = 1.026 * in[yiq_Y] - 0.2718 * in[yiq_I] - 0.1458 * in[yiq_Q];
+ out[rgb_B] = 1.186 * in[yiq_Y] - 1.2620 * in[yiq_I] + 1.8795 * in[yiq_Q];
+ return out;
+ }
+
+ static std::string
+ name()
+ {
+ std::ostringstream s;
+ s << "f_yiq_to_rgb<" << inbits << ", " <<
outbits << '>';
+ s.str();
+ }
+ };
+
+ template <unsigned inbits, unsigned outbits>
+ color<3, outbits, rgb_traits>
+ yiq_to_rgb(const color<3, inbits, yiq_traits>& v)
+ {
+ f_yiq_to_rgb<inbits, outbits> f;
+
+ return f(v);
+ }
+
+ } // convert
+} // oln
+
+#endif // OLENA_CONVERT_RGBYIQ_HH
Index: olena/oln/snakes/snakes_base.hxx
--- olena/oln/snakes/snakes_base.hxx Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/snakes/snakes_base.hxx Thu, 22 Jan 2004 21:39:24 +0100 palma_g
(oln/f/11_snakes_bas 1.1 644)
@@ -0,0 +1,84 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_SNAKES_SNAKES_BASE_HXX
+# define OLENA_SNAKES_SNAKES_BASE_HXX
+
+#include <oln/morpho/gradient.hh>
+
+namespace oln {
+
+ namespace snakes {
+
+ template <class algorithm>
+ snake<algorithm>::snake(const image_type& image,
+ std::list<point_type> initial_contour,
+ ntg::float_s alpha,
+ ntg::float_s beta,
+ ntg::float_s gamma,
+ ntg::float_s khi = 0.0f) :
+ s(initial_contour), a(alpha, beta, gamma, khi),
+ alpha(alpha), beta(beta), gamma(gamma), khi(khi)
+ {
+ gradient = morpho::fast::beucher_gradient(image, win_c8p());
+ };
+
+ template <class algorithm>
+ std::list<typename snake<algorithm>::point_type>
+ snake<algorithm>::contour(void) const
+ {
+ return s.contour();
+ }
+
+ template <class algorithm>
+ ntg::float_s
+ snake<algorithm>::energy(void) const
+ {
+ return s.energy(gradient);
+ }
+
+ template <class algorithm>
+ inline
+ int
+ snake<algorithm>::update_snake(void)
+ {
+ return a.update_snake(gradient, *this);
+ }
+
+ template <class algorithm>
+ inline
+ void
+ snake<algorithm>::converge(void)
+ {
+ a.converge(gradient, *this);
+ }
+
+ } // end snakes
+
+} // end oln
+
+#endif // !OLENA_SNAKES_SNAKES_BASE_HXX
Index: olena/oln/snakes/snakes_base.hh
--- olena/oln/snakes/snakes_base.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/snakes/snakes_base.hh Thu, 22 Jan 2004 21:39:25 +0100 palma_g
(oln/f/50_snakes_bas 1.1 644)
@@ -0,0 +1,124 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_SNAKES_SNAKES_BASE_HH
+# define OLENA_SNAKES_SNAKES_BASE_HH
+
+#include <oln/snakes/segment.hh>
+
+namespace oln {
+
+ namespace snakes {
+
+ template <class algorithm>
+ class snake
+ {
+ public:
+ typedef typename algorithm::image_type image_type;
+ typedef typename image_type::point_type point_type;
+
+ public:
+ snake(const image_type& image,
+ std::list<point_type> initial_contour,
+ ntg::float_s alpha,
+ ntg::float_s beta,
+ ntg::float_s gamma,
+ ntg::float_s khi);
+
+ public:
+ std::list<point_type>
+ contour(void) const;
+ ///< Return the points of the snake.
+
+ ntg::float_s
+ energy(void) const;
+ ///< Return the snake energy. This is not algorithm-dependant.
+
+ public:
+ int
+ update_snake(void);
+ ///< Calling this method causes the snake to execute one
+ ///< step. If the method is not iterative, it should fail
+ ///< to compile.
+
+ void
+ converge(void);
+ ///< Calling this method causes the snake to converge. It
+ ///< does so by delegating the method to the algorithm.
+
+ private:
+ segment<image_type> s;
+ ///< The current point list, I mean the one that is returned
+ ///< when nodes() is called and the one on which energy() computes
+ ///< the global energy. Implementations that use several segments
+ ///< should just do so in the algorithm class.
+
+ algorithm a;
+ ///< This one is just the instance that holds algorithm-specific
+ //< information, that is to say nearly every information.
+
+ private:
+ ///< Image gradient.
+ image_type gradient;
+
+ private:
+ ///< Each energy is weighted by a its own coefficient.
+ ntg::float_s alpha; ///< Weight of the continuity energy.
+ ntg::float_s beta; ///< Weight of the curvature energy.
+ ntg::float_s gamma; ///< Weight of the image energy.
+ ntg::float_s khi; ///< Weight of the image energy.
+
+ private:
+ friend
+ int
+ algorithm::update_snake(const typename algorithm::image_type&, snake&);
+
+ friend
+ void
+ algorithm::converge(const typename algorithm::image_type&, snake&);
+
+ friend
+ std::ostream&
+ ::operator<< <>(std::ostream&, const snake&);
+ };
+
+ } // end snakes
+
+} // end oln
+
+template <class algorithm>
+std::ostream& operator<<(std::ostream& os,
+ const oln::snakes::snake<algorithm>& s)
+{
+ os << "Snake:" << std::endl;
+ os << s.s;
+ return os;
+}
+
+#include <oln/snakes/snakes_base.hxx>
+
+#endif // !OLENA_SNAKES_SNAKES_BASE_HH
Index: olena/oln/snakes/energies.hxx
--- olena/oln/snakes/energies.hxx Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/snakes/energies.hxx Thu, 22 Jan 2004 21:40:50 +0100 palma_g
(oln/j/21_energies.h 1.1 664)
@@ -0,0 +1,82 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_SNAKES_ENERGIES_HXX
+# define OLENA_SNAKES_ENERGIES_HXX
+
+namespace oln {
+
+ namespace snakes {
+
+
+ template <class I>
+ inline
+ ntg::float_s
+ continuity_energy<I>::compute(const I&,
+ const node<I>& prev,
+ const node<I>& current,
+ const node<I>&)
+ {
+ ntg::float_s d = *average_dist - (current - prev).norm2();
+ return d > 0 ? d : -d;
+ }
+
+ template <class I>
+ inline
+ ntg::float_s
+ curvature_energy<I>::compute(const I&,
+ const node<I>& prev,
+ const node<I>& current,
+ const node<I>& next)
+ {
+ typename I::point_type twice_current;
+
+ twice_current.row() = 2 * current.row();
+ twice_current.col() = 2 * current.col();
+ return (next + (prev - twice_current) -
+ typename I::point_type(0,0)).norm2();
+ }
+
+ template <class I>
+ inline
+ ntg::float_s
+ image_energy<I>::compute(const I& gradient,
+ const node<I>&,
+ const node<I>& current,
+ const node<I>&)
+ {
+ // FIXME: Add magic trick: if there is very little gradient difference,
+ // don't pay too much attention to it.
+ // If max_gradient < min_gradient + 5: max_gradient = min_gradient + 5
+ return ntg_sup_val(oln_value_type(I)) - gradient[current];
+ }
+
+ } // end snakes
+
+} // end oln
+
+#endif // !OLENA_SNAKES_ENERGIES_HXX
Index: olena/oln/snakes/energies.hh
--- olena/oln/snakes/energies.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/snakes/energies.hh Thu, 22 Jan 2004 21:39:25 +0100 palma_g
(oln/j/22_energies.h 1.1 664)
@@ -0,0 +1,163 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_SNAKES_ENERGIES_HH
+# define OLENA_SNAKES_ENERGIES_HH
+
+namespace oln {
+
+ namespace snakes {
+
+ template <class I>
+ class energy
+ {
+ public:
+ energy() {}
+ energy(void *) {}
+
+ public:
+ ntg::float_s
+ compute(const I&, const node<I>&, const node<I>&, const
node<I>&)
+ {
+ // This is intended to cause an error. The user must define a
+ // member function named `compute()' for each external energy,
+ // otherwise the following method will be compiled and cause an
+ // error.
+ user_defined_external_energy_functor::compute();
+ return 0.f;
+ }
+
+ public:
+ static void* cookie() { return 0; };
+
+ private:
+ struct user_defined_external_energy_functor{};
+ };
+
+
+ template <class I>
+ class continuity_energy : public energy<I>
+ {
+ public:
+ typedef I image_type;
+
+ public:
+ continuity_energy(ntg::float_s* average_dist) :
+ average_dist(average_dist) {}
+
+ public:
+ inline
+ ntg::float_s
+ compute(const I&,
+ const node<I>& prev,
+ const node<I>& current,
+ const node<I>&);
+
+ private:
+ ntg::float_s* average_dist;
+ };
+
+
+ template <class I>
+ class curvature_energy : public energy<I>
+ {
+ public:
+ typedef I image_type;
+
+ public:
+ curvature_energy(void *) {}
+
+ public:
+ static inline
+ ntg::float_s
+ compute(const I&,
+ const node<I>& prev,
+ const node<I>& current,
+ const node<I>& next);
+ };
+
+
+ template <class I>
+ class image_energy : public energy<I>
+ {
+ public:
+ typedef I image_type;
+
+ public:
+ image_energy(void*) {}
+
+ public:
+ static inline
+ ntg::float_s
+ compute(const I& gradient,
+ const node<I>&,
+ const node<I>& current,
+ const node<I>&);
+ };
+
+
+ // This macro allows the user to define his own external energy.
+#define oln_snakes_define_external_energy(Energy, Gradient, PrevNode, CurrentNode,
NextNode) \
+ \
+template<class I> \
+class Energy : public energy<I> \
+{ \
+public: \
+ typedef I image_type; \
+ \
+public: \
+ Energy(void*) {} \
+ \
+public: \
+ ::ntg::float_s \
+ compute(const I& gradient, \
+ const ::oln::snakes::node<I>&, \
+ const ::oln::snakes::node<I>&, \
+ const ::oln::snakes::node<I>&); \
+}; \
+ \
+template<class I> \
+::ntg::float_s \
+Energy<I>::compute(const I& Gradient, \
+ const ::oln::snakes::node<I>& PrevNode, \
+ const ::oln::snakes::node<I>& CurrentNode, \
+ const ::oln::snakes::node<I>& NextNode)
+
+
+ // Default external energy.
+ oln_snakes_define_external_energy(dummy_energy,,,,)
+ {
+ return 0;
+ }
+
+ } // end snakes
+
+} // end oln
+
+#include <oln/snakes/energies.hxx>
+
+#endif // !OLENA_SNAKES_ENERGIES_HH
Index: olena/oln/snakes/segment.hxx
--- olena/oln/snakes/segment.hxx Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/snakes/segment.hxx Thu, 22 Jan 2004 21:39:26 +0100 palma_g
(oln/j/23_segment.hx 1.1 644)
@@ -0,0 +1,132 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_SNAKES_SEGMENT_HXX
+# define OLENA_SNAKES_SEGMENT_HXX
+
+namespace oln {
+
+ namespace snakes {
+
+ template <class I>
+ segment<I>::segment(std::list<point_type>& initial_contour) :
+ prev_segment(*this), next_segment(*this)
+ {
+ for (typename std::list<point_type>::const_iterator
+ it = initial_contour.begin();
+ it != initial_contour.end();
+ ++it)
+ nodes.push_back(*it);
+ }
+
+ template <class I>
+ inline
+ ntg::float_s
+ segment<I>::energy(const I& gradient) const
+ {
+ ntg::float_s e = 0.f;
+ typename segment<I>::const_iter_type p = nodes.begin();
+ typename segment<I>::const_iter_type c = nodes.begin();
+ typename segment<I>::const_iter_type n = nodes.begin();
+
+ ++n;
+ e += c->energy(gradient, prev_node(), *n);
+ for (++c, ++n; n != nodes.end(); ++p, ++c, ++n)
+ e += c->energy(gradient, *p, *n);
+ e += c->energy(gradient, *p, next_node());
+ return e;
+ }
+
+ template <class I>
+ std::list<typename segment<I>::point_type>
+ segment<I>::contour(void) const
+ {
+ std::list<point_type> result;
+
+ for (typename segment<I>::const_iter_type it = nodes.begin();
+ it != nodes.end(); ++it)
+ result.push_back(*it);
+ return result;
+ }
+
+ template <class I>
+ typename segment<I>::const_iter_type
+ segment<I>::begin(void) const
+ {
+ return nodes.begin();
+ }
+ template <class I>
+ typename segment<I>::iter_type
+ segment<I>::begin(void)
+ {
+ return nodes.begin();
+ }
+
+ template <class I>
+ typename segment<I>::const_iter_type
+ segment<I>::end(void) const
+ {
+ return nodes.end();
+ }
+ template <class I>
+ typename segment<I>::iter_type
+ segment<I>::end(void)
+ {
+ return nodes.end();
+ }
+
+ template <class I>
+ const node<I>
+ segment<I>::prev_node(void) const
+ {
+ return prev_segment.back();
+ }
+ template <class I>
+ const node<I>
+ segment<I>::next_node(void) const
+ {
+ return next_segment.front();
+ }
+
+ template <class I>
+ const node<I>
+ segment<I>::front(void) const
+ {
+ return nodes.front();
+ }
+ template <class I>
+ const node<I>
+ segment<I>::back(void) const
+ {
+ return nodes.back();
+ }
+
+ } // end snakes
+
+} // end oln
+
+#endif // !OLENA_SNAKES_SEGMENT_HXX
Index: olena/oln/snakes/greedy.hxx
--- olena/oln/snakes/greedy.hxx Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/snakes/greedy.hxx Thu, 22 Jan 2004 21:39:26 +0100 palma_g
(oln/j/24_greedy.hxx 1.1 644)
@@ -0,0 +1,210 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_SNAKES_GREEDY_HXX
+# define OLENA_SNAKES_GREEDY_HXX
+
+namespace oln {
+
+ namespace snakes {
+
+
+ template <int N, class I, template<typename> class external_energy>
+ greedy<N, I, external_energy>::greedy(ntg::float_s alpha,
+ ntg::float_s beta,
+ ntg::float_s gamma,
+ ntg::float_s khi) :
+ continuity_e(&average_dist),
+ curvature_e(curvature_energy<I>::cookie()),
+ image_e(image_energy<I>::cookie()),
+ external_e(external_energy<I>::cookie()),
+ alpha(alpha), beta(beta), gamma(gamma), khi(khi)
+ {
+ }
+
+
+ template <int N, class I, template<typename> class external_energy>
+ int
+ greedy<N, I, external_energy>::
+ update_snake(const I& gradient, snake<greedy<N, I, external_energy>
>& s)
+ {
+ /// This place is left void to make room for a future extension
+ /// where a snake will be able to hold several segments.
+ average_dist = compute_average_dist(s.s);
+ return update_segment(gradient, s.s);
+ }
+
+ template <int N, class I, template<typename> class external_energy>
+ void
+ greedy<N, I, external_energy>::
+ converge(const I& gradient, snake<greedy<N, I, external_energy>
>& s)
+ {
+ // FIXME: think of a real stop condition.
+ unsigned i = 0;
+ while (threshold < update_segment(gradient, s.s))
+ {
+ average_dist = compute_average_dist(s.s);
+ std::cout << i << ' ' << s.s << std::endl;
+ ++i;
+ };
+ }
+
+ template <int N, class I, template<typename> class external_energy>
+ int
+ greedy<N, I, external_energy>::update_segment(const I& gradient,
+ segment<I>& s)
+ {
+ int nb_updates = 0;
+ typename segment<I>::iter_type p = s.begin();
+ typename segment<I>::iter_type c = s.begin();
+ typename segment<I>::iter_type n = s.begin();
+
+ ++n;
+ nb_updates += update_node(gradient, s.prev_node(), *c, *n) ? 1 : 0;
+ for (++c, ++n; n != s.end(); ++p, ++c, ++n)
+ nb_updates += update_node(gradient, *p, *c, *n) ? 1 : 0;
+ nb_updates += update_node(gradient, *p, *c, s.next_node()) ? 1 : 0;
+ return nb_updates;
+ }
+
+ template <int N, class I, template<typename> class external_energy>
+ bool
+ greedy<N, I, external_energy>::update_node(const I& gradient,
+ const node<I>& prev,
+ node<I>& current,
+ const node<I>& next)
+ ///< Return whether the point has changed or not.
+ {
+ store_type energy;
+ ntg::float_s minimum = ntg_sup_val(ntg::float_s);
+ dpoint2d minimum_location;
+
+ energy = compute_and_normalize_energy<continuity_energy<I> >
+ (gradient, prev, current, next, continuity_e) * alpha;
+ energy += compute_and_normalize_energy<curvature_energy<I> >
+ (gradient, prev, current, next, curvature_e) * beta;
+ energy += compute_and_normalize_energy<image_energy<I> >
+ (gradient, prev, current, next, image_e) * gamma;
+ energy += compute_and_normalize_energy<external_energy<I> >
+ (gradient, prev, current, next, external_e) * khi;
+
+ window2d::iter_type it(neighborhood);
+ for_all(it)
+ {
+ if (minimum > energy(it.cur().col(), it.cur().row()))
+ {
+ minimum = energy(it.cur().col(), it.cur().row());
+ minimum_location = it;
+ }
+ }
+ if (0 != minimum_location.col() || 0 != minimum_location.row())
+ {
+ current += minimum_location;
+ return true;
+ }
+ return false;
+ }
+
+
+ template <int N, class I, template<typename> class external_energy>
+ template <class energy_functor>
+ inline
+ typename greedy<N, I, external_energy>::store_type
+ greedy<N, I, external_energy>::
+ compute_and_normalize_energy
+ (const typename energy_functor::image_type& gradient,
+ const node<typename energy_functor::image_type>& prev,
+ const node<typename energy_functor::image_type>& current,
+ const node<typename energy_functor::image_type>& next,
+ energy_functor functor)
+ {
+ store_type energy;
+ ntg::float_s energy_min = ntg_sup_val(ntg::float_s);
+ ntg::float_s energy_max = ntg_inf_val(ntg::float_s);
+
+ // Compute energy of each point of the neighborhood. Those are
+ // not normalized yet.
+ window2d::iter_type it(neighborhood);
+ for_all(it)
+ {
+ ntg::float_s e = functor.compute(gradient, prev, current + it, next);
+
+ // Find minimal and maximal energy on the fly, for we need them
+ // thereafter.
+ if (e > energy_max) energy_max = e;
+ if (e < energy_min) energy_min = e;
+ // Store it in a temporary location.
+ energy(it.cur().col(), it.cur().row()) = e;
+ }
+ if (energy_max > 0)
+ {
+ ntg::float_s invmax = 1 / (energy_max - energy_min);
+ window2d::iter_type itw(neighborhood);
+ for_all(itw)
+ {
+ ntg::float_s tmp = energy(itw.cur().col(), itw.cur().row()) -
+ energy_min;
+ tmp *= invmax;
+ energy(itw.cur().col(), itw.cur().row()) = tmp;
+ }
+ }
+ return energy;
+ }
+
+
+ template <int N, class I, template<typename> class external_energy>
+ ntg::float_s
+ greedy<N, I, external_energy>::compute_average_dist(const segment<I>&
s)
+ {
+ ntg::float_s mean = 0.f;
+
+ typename segment<I>::const_iter_type prev = s.begin();
+ typename segment<I>::const_iter_type cur = s.begin();
+ unsigned card = 0;
+ for (++cur; cur != s.end(); ++prev, ++cur)
+ {
+ mean += (*cur - *prev).norm2();
+ ++card;
+ }
+ return mean / (ntg::float_s)card;
+ }
+
+
+ template <int N, class I, template<typename> class external_energy>
+ const int greedy<N, I, external_energy>::threshold = 3; // FIXME:
+
+
+ template <int N, class I, template<typename> class external_energy>
+ window2d greedy<N, I, external_energy>::neighborhood = mk_win_square(N);
+
+
+ } // end snakes
+
+} // end oln
+
+
+#endif // !OLENA_SNAKES_GREEDY_HXX
Index: olena/oln/snakes/greedy.hh
--- olena/oln/snakes/greedy.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/snakes/greedy.hh Thu, 22 Jan 2004 21:39:26 +0100 palma_g (oln/j/25_greedy.hh
1.1 644)
@@ -0,0 +1,121 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_SNAKES_GREEDY_HH
+# define OLENA_SNAKES_GREEDY_HH
+
+#include <oln/snakes/snakes_base.hh>
+#include <oln/snakes/energies.hh>
+#include <mlc/array/2d.hh>
+
+namespace oln {
+
+ namespace snakes {
+
+ /// N is the size of the neighborhood.
+ template <int N, class I, template<typename> class external_energy =
dummy_energy>
+ class greedy
+ {
+ public:
+ typedef I image_type;
+ typedef typename I::point_type point_type;
+ typedef mlc::array2d<mlc::array2d_info<N,N>, ntg::float_s> store_type;
+ // FIXME: why only 2d?
+
+ public:
+ greedy(ntg::float_s alpha,
+ ntg::float_s beta,
+ ntg::float_s gamma,
+ ntg::float_s khi);
+
+ public:
+ inline
+ int
+ update_snake(const I& gradient, snake<greedy>& s);
+ ///< Asynchronous update for more efficient convergence.
+
+ void
+ converge(const I& gradient, snake<greedy>& s);
+
+
+ private:
+ inline
+ int
+ update_segment(const I& gradient, segment<I>& s);
+
+ inline
+ bool
+ update_node(const I& gradient,
+ const node<I>& prev, node<I>& n, const node<I>& next);
+
+ private:
+ template <class energy_functor>
+ inline
+ store_type
+ compute_and_normalize_energy
+ (const typename energy_functor::image_type& gradient,
+ const node<typename energy_functor::image_type>& prev,
+ const node<typename energy_functor::image_type>& current,
+ const node<typename energy_functor::image_type>& next,
+ energy_functor functor);
+
+ private:
+ ntg::float_s average_dist;
+ ///< Average distance between the points of the contour.
+
+ inline
+ ntg::float_s
+ compute_average_dist(const segment<I>& s);
+
+ private:
+ continuity_energy<I> continuity_e;
+ curvature_energy<I> curvature_e;
+ image_energy<I> image_e;
+ external_energy<I> external_e;
+
+ private:
+ ///< Each energy is weighted by a its own coefficient.
+ ntg::float_s alpha; ///< Weight of the continuity energy.
+ ntg::float_s beta; ///< Weight of the curvature energy.
+ ntg::float_s gamma; ///< Weight of the image energy.
+ ntg::float_s khi; ///< Weight of the image energy.
+
+ private:
+ static const int threshold;
+ // FIXME: think about a real stop condition.
+ private:
+ static window2d neighborhood;
+ // FIXME: better write an iterator on arrays.
+ };
+
+ } // end snakes
+
+} // end oln
+
+#include <oln/snakes/greedy.hxx>
+
+#endif // !OLENA_SNAKES_GREEDY_HH
Index: olena/oln/snakes/node.hh
--- olena/oln/snakes/node.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/snakes/node.hh Thu, 22 Jan 2004 21:39:26 +0100 palma_g (oln/j/32_node.hh 1.1
644)
@@ -0,0 +1,74 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_SNAKES_NODE_HH
+# define OLENA_SNAKES_NODE_HH
+
+#include <oln/basics2d.hh> // FIXME: Why only 2d?
+
+namespace oln {
+
+ namespace snakes {
+
+ template<class I>
+ class node : public I::point_type
+ {
+ public:
+ typedef typename I::point_type point_type;
+ typedef typename I::dpoint_type dpoint_type;
+
+ public:
+ node(point_type point) :
+ I::point_type(point)
+ {
+ }
+
+ public:
+ inline
+ ntg::float_s
+ energy(const I& gradient, point_type prev, point_type next) const;
+
+ private:
+ friend std::ostream&
+ ::operator<< <>(std::ostream&, const node&);
+ };
+
+ } // end snakes
+
+} // end oln
+
+
+template <class I>
+std::ostream& operator<<(std::ostream& os, const
oln::snakes::node<I>& n)
+{
+ os << "Node:" << static_cast<typename
oln::snakes::node<I>::point_type>(n);
+ return os;
+}
+
+#include <oln/snakes/node.hxx>
+
+#endif // !OLENA_SNAKES_NODE_HH
Index: olena/oln/snakes/node.hxx
--- olena/oln/snakes/node.hxx Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/snakes/node.hxx Thu, 22 Jan 2004 21:39:27 +0100 palma_g (oln/j/33_node.hxx
1.1 644)
@@ -0,0 +1,46 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_SNAKES_NODE_HXX
+# define OLENA_SNAKES_NODE_HXX
+
+namespace oln {
+
+ namespace snakes {
+
+ template <class I>
+ ntg::float_s
+ node<I>::energy(const I& gradient, point_type prev, point_type next) const
+ {
+ return 42; // FIXME: compute the real value.
+ }
+
+ } // end snakes
+
+} // end oln
+
+#endif // !OLENA_SNAKES_NODE_HXX
Index: olena/oln/snakes/segment.hh
--- olena/oln/snakes/segment.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
+++ olena/oln/snakes/segment.hh Thu, 22 Jan 2004 21:39:27 +0100 palma_g
(oln/j/34_segment.hh 1.1 644)
@@ -0,0 +1,107 @@
+// Copyright (C) 2004 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLENA_SNAKES_SEGMENT_HH
+# define OLENA_SNAKES_SEGMENT_HH
+
+#include <oln/snakes/node.hh>
+
+#include <vector>
+#include <list>
+
+namespace oln {
+
+ namespace snakes {
+
+ template <class I>
+ class segment
+ {
+ public:
+ typedef typename std::vector<node<I> >::iterator iter_type;
+ typedef typename std::vector<node<I> >::const_iterator
const_iter_type;
+ typedef typename I::point_type point_type;
+
+ public:
+ segment(std::list<point_type>& initial_contour);
+
+ public:
+ inline
+ ntg::float_s
+ energy(const I& gradient) const;
+ ///< Just iterate through the vector and sums up point energies.
+
+ public:
+ std::list<point_type>
+ contour(void) const;
+ ///< Return the points of the segment.
+
+ public:
+ const_iter_type begin(void) const;
+ iter_type begin(void);
+ ///< Return an iterator on the first node of the segment.
+ const_iter_type end(void) const;
+ iter_type end(void);
+ ///< Return an iterator on the last node of the segment.
+
+ public:
+ const node<I> prev_node(void) const;
+ ///< Node before the first node of this segment.
+ const node<I> next_node(void) const;
+ ///< Node after the next node of this segment.
+
+ private:
+ std::vector<node<I> > nodes;
+ segment& prev_segment;
+ segment& next_segment;
+
+ const node<I> front(void) const;
+ const node<I> back(void) const;
+
+ friend
+ std::ostream&
+ ::operator<< <>(std::ostream&, const segment&);
+ };
+
+ } // end snakes
+
+} // end oln
+
+
+template <class I>
+std::ostream& operator<<(std::ostream& os, const
oln::snakes::segment<I>& s)
+{
+ os << "Segment:" << std::endl;
+ for (typename oln::snakes::segment<I>::const_iter_type it = s.begin();
+ it != s.end();
+ ++it)
+ os << *it << std::endl;
+ return os;
+}
+
+#include <oln/snakes/segment.hxx>
+
+#endif // !OLENA_SNAKES_SEGMENT_HH
Index: olena/oln/convert/nrgbhsi.hh
--- olena/oln/convert/nrgbhsi.hh Thu, 07 Aug 2003 02:08:21 +0200 david (oln/15_nrgbhsi.hh
1.12 640)
+++ olena/oln/convert/nrgbhsi.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
@@ -1,136 +0,0 @@
-// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory
-//
-// This file is part of the Olena Library. This library is free
-// software; you can redistribute it and/or modify it under the terms
-// of the GNU General Public License version 2 as published by the
-// Free Software Foundation.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this library; see the file COPYING. If not, write to
-// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
-// MA 02111-1307, USA.
-//
-// As a special exception, you may use this file as part of a free
-// software library without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to
-// produce an executable, this file does not by itself cause the
-// resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-
-
-#ifndef OLENA_CONVERT_NRGBHSI_HH
-# define OLENA_CONVERT_NRGBHSI_HH
-
-# include <oln/convert/abstract/colorconv.hh>
-
-# include <ntg/basics.hh>
-# include <ntg/color/nrgb.hh>
-# include <ntg/color/hsi.hh>
-
-# include <sstream>
-
-/*--------------------------------------------------------------.
-| The formulas used here come from ``Digital Image Processing |
-| Algorithms and Applications'', I. Pitas; Wiley-Interscience. |
-`--------------------------------------------------------------*/
-
-namespace oln {
-
- using namespace ntg;
-
- namespace convert {
-
- static const float sqrt3_3 = sqrt(3) / 3;
- static const float inv_sqrt6 = 1 / sqrt(6);
- static const float inv_sqrt2 = 1 / sqrt(2);
-
- template<unsigned inbits, unsigned outbits>
- struct f_nrgb_to_hsi
- : public abstract::color_conversion<3, inbits, nrgb_traits,
- 3, outbits, hsi_traits, f_nrgb_to_hsi<inbits, outbits> >
- {
- color<3, inbits, hsi_traits>
- doit(const color<3, outbits, nrgb_traits>& v) const
- {
- vec<3, float> in = v.to_float();
- vec<3, float> out;
- out[hsi_I] =
- sqrt3_3 * in[nrgb_R] + sqrt3_3 * in[nrgb_G] + sqrt3_3 * in[nrgb_B];
- const float v1 = inv_sqrt2 * in[nrgb_G] - inv_sqrt2 * in[nrgb_B];
- const float v2 = 2 * inv_sqrt6 * in[nrgb_R] - inv_sqrt6 * in[nrgb_G]
- - inv_sqrt6 * in[nrgb_B];
- out[hsi_H] = atan2(v2, v1) / M_PI * 180.0;
- if (out[hsi_H] < 0)
- out[hsi_H] += 360.0;
- assert(out[hsi_H] >= 0);
- out[hsi_S] = sqrt(v1 * v1 + v2 * v2);
- return out;
- }
-
- static std::string
- name()
- {
- std::ostringstream s;
- s << "f_nrgb_to_hsi<" << inbits << ", "
<< outbits << '>';
- s.str();
- }
- };
-
- template <unsigned inbits, unsigned outbits>
- color<3, outbits, hsi_traits>
- nrgb_to_hsi(const color<3, inbits, nrgb_traits>& v)
- {
- f_nrgb_to_hsi<inbits, outbits> f;
-
- return f(v);
- }
-
- template<unsigned inbits, unsigned outbits>
- struct f_hsi_to_nrgb
- : public abstract::color_conversion<3, inbits, hsi_traits,
- 3, outbits, nrgb_traits, f_hsi_to_nrgb<inbits, outbits> >
- {
- color<3, outbits, nrgb_traits>
- doit(const color<3, inbits, hsi_traits>& v) const
- {
- vec<3, float> in = v.to_float();
- vec<3, float> out;
- const float h = in[hsi_H] / 180.0 * M_PI;
- const float v1 = in[hsi_S] * cos(h);
- const float v2 = in[hsi_S] * sin(h);
- out[nrgb_R] = sqrt3_3 * in[hsi_I] + 2 * inv_sqrt6 * v2;
- out[nrgb_G] = sqrt3_3 * in[hsi_I] + inv_sqrt2 * v1 - inv_sqrt6 * v2;
- out[nrgb_B] = sqrt3_3 * in[hsi_I] - inv_sqrt2 * v1 - inv_sqrt6 * v2;
- return out;
- }
-
- static std::string
- name()
- {
- std::ostringstream s;
- s << "f_hsi_to_nrgb<" << inbits << ", "
<< outbits << '>';
- s.str();
- }
- };
-
- template <unsigned inbits, unsigned outbits>
- color<3, outbits, nrgb_traits>
- hsi_to_nrgb (const color<3, inbits, hsi_traits>& v)
- {
- f_hsi_to_nrgb<inbits, outbits> f;
-
- return f(v);
- }
-
- } // convert
-} // oln
-
-#endif // OLENA_CONVERT_NRGBHSI_HH
Index: olena/oln/convert/nrgbhsl.hh
--- olena/oln/convert/nrgbhsl.hh Wed, 08 Oct 2003 23:36:51 +0200 burrus_n
(oln/12_nrgbhsl.hh 1.17 640)
+++ olena/oln/convert/nrgbhsl.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
@@ -1,187 +0,0 @@
-// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory
-//
-// This file is part of the Olena Library. This library is free
-// software; you can redistribute it and/or modify it under the terms
-// of the GNU General Public License version 2 as published by the
-// Free Software Foundation.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this library; see the file COPYING. If not, write to
-// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
-// MA 02111-1307, USA.
-//
-// As a special exception, you may use this file as part of a free
-// software library without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to
-// produce an executable, this file does not by itself cause the
-// resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-
-
-#ifndef OLENA_CONVERT_NRGBHSL_HH
-# define OLENA_CONVERT_NRGBHSL_HH
-
-# include <oln/basics.hh>
-# include <oln/convert/abstract/colorconv.hh>
-
-# include <ntg/basics.hh>
-# include <ntg/color/nrgb.hh>
-# include <ntg/color/hsl.hh>
-
-# include <mlc/contract.hh>
-
-# include <cstdlib>
-# include <sstream>
-
-/*------------------------------------------------------------------.
-| The formulas used here come from ``Color space conversion''; Paul |
-| Bourke. |
-`------------------------------------------------------------------*/
-
-namespace oln {
-
- using namespace ntg;
-
- namespace convert {
-
- template<unsigned inbits, unsigned outbits>
- struct f_nrgb_to_hsl
- : public abstract::color_conversion<3, inbits, nrgb_traits,
- 3, outbits, hsl_traits, f_nrgb_to_hsl<inbits, outbits> >
- {
- color<3, outbits, hsl_traits>
- doit(const color<3, inbits, nrgb_traits>& v) const
- {
- vec<3, float> in = v.to_float();
- vec<3, float> out;
-
- float max_in = ntg::max(in[nrgb_R], std::max(in[nrgb_B], in[nrgb_G]));
- float min_in = ntg::min(in[nrgb_R], std::min(in[nrgb_B], in[nrgb_G]));
- float diff = max_in-min_in;
-
- out[hsl_L] = (max_in + min_in) / 2;
- if (std::abs(diff) <= FLT_EPSILON){
- out[hsl_S] = 0;
- out[hsl_H] = 0; // undefined
- }
- else {
- if (out[hsl_L] <= 0.5)
- out[hsl_S] = diff / (max_in + min_in);
- else
- out[hsl_S] = diff / (2 - max_in - min_in);
-
-
- float r_dist = (max_in - in[nrgb_R]) / diff;
- float g_dist = (max_in - in[nrgb_G]) / diff;
- float b_dist = (max_in - in[nrgb_B]) / diff;
-
- if (in[nrgb_R] == max_in)
- out[hsl_H] = b_dist - g_dist;
- else if(in[nrgb_G] == max_in)
- out[hsl_H] = 2 + r_dist - b_dist;
- else if(in[nrgb_B] == max_in)
- out[hsl_H] = 4 + g_dist - r_dist;
-
- out[hsl_H] *= 60;
- if(out[hsl_H] < 0)
- out[hsl_H] += 360;
- }
- return out;
- }
-
- static std::string
- name()
- {
- std::ostringstream s;
- s << "f_nrgb_to_hsl<" << inbits << ", "
<< outbits << '>';
- s.str();
- }
- };
-
- template <unsigned inbits, unsigned outbits>
- color<3, inbits, hsl_traits>
- nrgb_to_hsl(const color<3, outbits, nrgb_traits>& v)
- {
- f_nrgb_to_hsl<inbits, outbits> f;
- return f(v);
- }
-
- namespace internal {
- float
- RGB(float q1, float q2, float hue)
- {
- if (hue >= 360)
- hue -= 360;
- if (hue < 0)
- hue += 360;
- if (hue < 60)
- return q1 + (q2 - q1) * hue / 60;
- else if (hue < 180)
- return q2;
- else if (hue < 240)
- return q1 + (q2 - q1) * (240 - hue) / 60;
- else
- return q1;
- }
- }
-
- template<unsigned inbits, unsigned outbits>
- struct f_hsl_to_nrgb
- : public abstract::color_conversion<3, inbits, hsl_traits,
- 3, outbits, nrgb_traits, f_hsl_to_nrgb<inbits, outbits> >
- {
- color<3, outbits, nrgb_traits>
- doit(const color<3, inbits, hsl_traits>& v) const
- {
- vec<3, float> in = v.to_float();
- vec<3, float> out;
- float p2;
-
- if(in[hsl_L] < 0.5)
- p2 = in[hsl_L] * (1+in[hsl_S]);
- else
- p2 = in[hsl_L] + in[hsl_S] - (in[hsl_L] * in[hsl_S]);
-
- float p1 = 2 * in[hsl_L] - p2;
-
- if(in[hsl_S] == 0)
- out[nrgb_R] = out[nrgb_G] = out[nrgb_B] = in[hsl_L];
- else
- {
- out[nrgb_R] = internal::RGB(p1, p2, in[hsl_H] + 120);
- out[nrgb_G] = internal::RGB(p1, p2, in[hsl_H]);
- out[nrgb_B] = internal::RGB(p1, p2, in[hsl_H] - 120);
- }
-
- return out;
- }
-
- static std::string
- name()
- {
- std::ostringstream s;
- s << "f_hsl_to_nrgb<" << inbits << ", "
<< outbits << '>';
- s.str();
- }
- };
-
- template<unsigned inbits, unsigned outbits>
- color<3, outbits, nrgb_traits>
- hsl_to_nrgb(const color<3, inbits, hsl_traits>& v)
- {
- f_hsl_to_nrgb<inbits, outbits> f;
- return f(v);
- }
-
- } // convert
-} // oln
-
-#endif // OLENA_CONVERT_NRGBHSL_HH
Index: olena/oln/convert/nrgbhsv.hh
--- olena/oln/convert/nrgbhsv.hh Thu, 07 Aug 2003 02:08:21 +0200 david (oln/11_nrgbhsv.hh
1.14 640)
+++ olena/oln/convert/nrgbhsv.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
@@ -1,188 +0,0 @@
-// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory
-//
-// This file is part of the Olena Library. This library is free
-// software; you can redistribute it and/or modify it under the terms
-// of the GNU General Public License version 2 as published by the
-// Free Software Foundation.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this library; see the file COPYING. If not, write to
-// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
-// MA 02111-1307, USA.
-//
-// As a special exception, you may use this file as part of a free
-// software library without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to
-// produce an executable, this file does not by itself cause the
-// resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-
-
-#ifndef OLENA_CONVERT_NRGBHSV_HH
-# define OLENA_CONVERT_NRGBHSV_HH
-
-# include <oln/basics.hh>
-# include <oln/convert/abstract/colorconv.hh>
-
-# include <ntg/basics.hh>
-# include <ntg/color/nrgb.hh>
-# include <ntg/color/hsv.hh>
-
-# include <mlc/contract.hh>
-
-# include <sstream>
-
-/*-----------------------------------------------------------------.
-| The formulas used here come from ``Color Conversion Algorithms'' |
-`-----------------------------------------------------------------*/
-
-namespace oln {
-
- using namespace ntg;
-
- namespace convert {
-
- template<unsigned inbits, unsigned outbits>
- struct f_nrgb_to_hsv
- : public abstract::color_conversion<3, inbits, nrgb_traits,
- 3, outbits, hsv_traits, f_nrgb_to_hsv<inbits, outbits> >
- {
- color<3, outbits, hsv_traits>
- doit(const color<3, inbits, nrgb_traits>& v) const
- {
- vec<3, float> in = v.to_float();
- vec<3, float> out;
- float max_in = std::max(in[nrgb_R], std::max(in[nrgb_B], in[nrgb_G]));
- float min_in = std::min(in[nrgb_R], std::min(in[nrgb_B], in[nrgb_G]));
- float delta = max_in - min_in;
-
-
- out[hsv_V] = max_in;
-
- if (max_in != 0)
- out[hsv_S] = delta / max_in;
- else
- out[hsv_S] = 0;
-
- if (out[hsv_S] == 0)
- out[hsv_H] = -1; // undefined
- else {
- if (in[nrgb_R] == max_in)
- out[hsv_H] = (in[nrgb_G] - in[nrgb_B]) / delta;
- else if (in[nrgb_G] == max_in)
- out[hsv_H] = 2 + (in[nrgb_B] - in[nrgb_R]) / delta;
- else
- out[hsv_H] = 4 + (in[nrgb_R] - in[nrgb_G]) / delta;
- out[hsv_H] *= 60;
- if (out[hsv_H] < 0)
- out[hsv_H] += 360;
- }
-
- return out;
- }
-
- static std::string
- name()
- {
- std::ostringstream s;
- s << "f_nrgb_to_hsv<" << inbits << ", "
<< outbits << '>';
- s.str();
- }
- };
-
- template <unsigned inbits, unsigned outbits>
- color<3, outbits, hsv_traits>
- nrgb_to_hsv(const color<3, inbits, nrgb_traits>& v)
- {
- f_nrgb_to_hsv<inbits, outbits> f;
- return f(v);
- }
-
- template<unsigned inbits, unsigned outbits>
- struct f_hsv_to_nrgb
- : public abstract::color_conversion<3, inbits, hsv_traits,
- 3, outbits, nrgb_traits, f_hsv_to_nrgb<inbits, outbits> >
- {
- color<3, outbits, nrgb_traits>
- doit(const color<3, inbits, hsv_traits>& v) const
- {
- vec<3, float> in = v.to_float();
- vec<3, float> out;
-
- if(in[hsv_S] == 0)
- out[nrgb_G] = out[nrgb_B] = out[nrgb_R] = in[hsv_V];
- else
- {
- in[hsv_H] /= 60;
- int i = (int)floor (in[hsv_H]);
- float f = in[hsv_H] - i;
- float p = in[hsv_V] * (1 - in[hsv_S]);
- float q = in[hsv_V] * (1 - in[hsv_S] * f);
- float t = in[hsv_V] * (1 - in[hsv_S] * (1 - f));
-
- switch (i){
- case 0:
- case 6:
- out[nrgb_R] = in[hsv_V];
- out[nrgb_G] = t;
- out[nrgb_B] = p;
- break;
- case 1:
- out[nrgb_R] = q;
- out[nrgb_G] = in[hsv_V];
- out[nrgb_B] = p;
- break;
- case 2:
- out[nrgb_R] = p;
- out[nrgb_G] = in[hsv_V];
- out[nrgb_B] = t;
- break;
- case 3:
- out[nrgb_R] = p;
- out[nrgb_G] = q;
- out[nrgb_B] = in[hsv_V];
- break;
- case 4:
- out[nrgb_R] = t;
- out[nrgb_G] = p;
- out[nrgb_B] = in[hsv_V];
- break;
- default:
- out[nrgb_R] = in[hsv_V];
- out[nrgb_G] = p;
- out[nrgb_B] = q;
- break;
- }
- }
- return out;
- }
-
- static std::string
- name()
- {
- std::ostringstream s;
- s << "f_hsv_to_nrgb<" << inbits << ", "
<< outbits << '>';
- s.str();
- }
- };
-
- template <unsigned inbits, unsigned outbits>
- color<3, outbits, nrgb_traits>
- hsv_to_nrgb(const color<3, inbits, hsv_traits>& v)
- {
- f_hsv_to_nrgb<inbits, outbits> f;
- return f(v);
- }
-
- } // convert
-} // oln
-
-#endif // OLENA_CONVERT_NRGBHSV_HH
Index: olena/oln/convert/nrgbyiq.hh
--- olena/oln/convert/nrgbyiq.hh Thu, 07 Aug 2003 02:08:21 +0200 david (oln/14_nrgbyiq.hh
1.11 640)
+++ olena/oln/convert/nrgbyiq.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
@@ -1,125 +0,0 @@
-// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory
-//
-// This file is part of the Olena Library. This library is free
-// software; you can redistribute it and/or modify it under the terms
-// of the GNU General Public License version 2 as published by the
-// Free Software Foundation.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this library; see the file COPYING. If not, write to
-// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
-// MA 02111-1307, USA.
-//
-// As a special exception, you may use this file as part of a free
-// software library without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to
-// produce an executable, this file does not by itself cause the
-// resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-
-
-#ifndef OLENA_CONVERT_NRGBYIQ_HH
-# define OLENA_CONVERT_NRGBYIQ_HH
-
-# include <oln/convert/abstract/colorconv.hh>
-
-# include <ntg/color/nrgb.hh>
-# include <ntg/color/yiq.hh>
-# include <ntg/basics.hh>
-
-# include <sstream>
-
-/*--------------------------------------------------------------.
-| The formulas used here come from ``Digital Image Processing |
-| Algorithms and Applications'', I. Pitas; Wiley-Interscience. |
-`--------------------------------------------------------------*/
-
-namespace oln {
-
- using namespace ntg;
-
- namespace convert {
-
- template<unsigned inbits, unsigned outbits>
- struct f_nrgb_to_yiq
- : public abstract::color_conversion<3, inbits, nrgb_traits,
- 3, outbits, yiq_traits, f_nrgb_to_yiq<inbits, outbits> >
- {
- color<3, inbits, yiq_traits>
- doit(const color<3, outbits, nrgb_traits>& v) const
- {
- vec<3, float> in = v.to_float();
- vec<3, float> out;
- out[yiq_Y] =
- 0.299 * in[nrgb_R] + 0.587 * in[nrgb_G] + 0.114 * in[nrgb_B];
- out[yiq_I] =
- 0.596 * in[nrgb_R] - 0.274 * in[nrgb_G] - 0.322 * in[nrgb_B];
- out[yiq_Q] =
- 0.211 * in[nrgb_R] - 0.523 * in[nrgb_G] + 0.312 * in[nrgb_B];
- return out;
- }
-
- static std::string
- name()
- {
- std::ostringstream s;
- s << "f_nrgb_to_yiq<" << inbits << ", "
<< outbits << '>';
- s.str();
- }
- };
-
- template <unsigned inbits, unsigned outbits>
- color<3, outbits, yiq_traits>
- nrgb_to_yiq(const color<3, inbits, nrgb_traits>& v)
- {
- f_nrgb_to_yiq<inbits, outbits> f;
-
- return f(v);
- }
-
- template<unsigned inbits, unsigned outbits>
- struct f_yiq_to_nrgb
- : public abstract::color_conversion<3, inbits, yiq_traits,
- 3, outbits, nrgb_traits, f_yiq_to_nrgb<inbits, outbits> >
- {
- color<3, inbits, nrgb_traits>
- doit(const color<3, outbits, yiq_traits>& v) const
- {
- vec<3, float> in = v.to_float();
- vec<3, float> out;
- out[nrgb_R] = in[yiq_Y] + 0.95617 * in[yiq_I] + 0.62143 * in[yiq_Q];
- out[nrgb_G] = in[yiq_Y] - 0.27269 * in[yiq_I] - 0.64681 * in[yiq_Q];
- out[nrgb_B] = in[yiq_Y] - 1.10374 * in[yiq_I] + 1.70062 * in[yiq_Q];
- return out;
- }
-
- static std::string
- name()
- {
- std::ostringstream s;
- s << "f_yiq_to_nrgb<" << inbits << ", "
<< outbits << '>';
- s.str();
- }
- };
-
- template <unsigned inbits, unsigned outbits>
- color<3, outbits, nrgb_traits>
- yiq_to_nrgb(const color<3, inbits, yiq_traits>& v)
- {
- f_yiq_to_nrgb<inbits, outbits> f;
-
- return f(v);
- }
-
- } // convert
-} // oln
-
-#endif // OLENA_CONVERT_NRGBYIQ_HH
Index: olena/oln/convert/nrgbyuv.hh
--- olena/oln/convert/nrgbyuv.hh Thu, 07 Aug 2003 02:08:21 +0200 david (oln/13_nrgbyuv.hh
1.12 640)
+++ olena/oln/convert/nrgbyuv.hh Thu, 22 Jan 2004 21:43:43 +0100 palma_g ()
@@ -1,126 +0,0 @@
-// Copyright (C) 2001, 2002, 2003 EPITA Research and Development Laboratory
-//
-// This file is part of the Olena Library. This library is free
-// software; you can redistribute it and/or modify it under the terms
-// of the GNU General Public License version 2 as published by the
-// Free Software Foundation.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this library; see the file COPYING. If not, write to
-// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
-// MA 02111-1307, USA.
-//
-// As a special exception, you may use this file as part of a free
-// software library without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to
-// produce an executable, this file does not by itself cause the
-// resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-
-
-#ifndef OLENA_CONVERT_NRGBYUV_HH
-# define OLENA_CONVERT_NRGBYUV_HH
-
-# include <oln/convert/abstract/colorconv.hh>
-
-# include <ntg/color/nrgb.hh>
-# include <ntg/color/yuv.hh>
-# include <ntg/basics.hh>
-
-# include <sstream>
-
-/*---------------------------------------------------------------.
-| The formulas used here come from ``Colour Space Conversions'', |
-| IAdrian Ford and Alan Roberts; August 11,1998. |
-`---------------------------------------------------------------*/
-
-namespace oln {
-
- using namespace ntg;
-
- namespace convert {
-
- template <unsigned inbits, unsigned outbits>
- struct f_nrgb_to_yuv
- : public abstract::color_conversion<3, inbits, nrgb_traits,
- 3, outbits, yuv_traits, f_nrgb_to_yuv<inbits, outbits> >
- {
- color<3, outbits, yuv_traits>
- doit(const color<3, inbits, nrgb_traits>& v) const
- {
- vec<3, float> in = v.to_float();
- vec<3, float> out;
- out[yuv_Y] =
- + 0.299 * in[nrgb_R] + 0.587 * in[nrgb_G] + 0.114 * in[nrgb_B];
- out[yuv_U] =
- - 0.147 * in[nrgb_R] - 0.289 * in[nrgb_G] + 0.436 * in[nrgb_B];
- out[yuv_V] =
- + 0.615 * in[nrgb_R] - 0.515 * in[nrgb_G] - 0.100 * in[nrgb_B];
- return out;
- }
-
- static std::string
- name()
- {
- std::ostringstream s;
- s << "f_nrgb_to_yuv<" << inbits << ", "
<< outbits << '>';
- s.str();
- }
- };
-
- template <unsigned inbits, unsigned outbits>
- color<3, outbits, yuv_traits>
- nrgb_to_yuv(const color<3, inbits, nrgb_traits>& v)
- {
- f_nrgb_to_yuv<inbits, outbits> f;
-
- return f(v);
- }
-
- template<unsigned inbits, unsigned outbits>
- struct f_yuv_to_nrgb
- : public abstract::color_conversion<3, inbits, yuv_traits,
- 3, outbits, nrgb_traits, f_yuv_to_nrgb<inbits, outbits> >
- {
- color<3, outbits, nrgb_traits>
- doit(const color<3, inbits, yuv_traits>& v) const
- {
- vec<3, float> in = v.to_float();
- vec<3, float> out;
- out[nrgb_R] = in[yuv_Y] + 1.140 * in[yuv_V];
- out[nrgb_G] = in[yuv_Y] - 0.394 * in[yuv_U] - 0.581 * in[yuv_V];
- out[nrgb_B] = in[yuv_Y] + 2.028 * in[yuv_U];
-
- return out;
- }
-
- static std::string
- name()
- {
- std::ostringstream s;
- s << "f_yuv_to_nrgb<" << inbits << ", "
<< outbits << '>';
- s.str();
- }
- };
-
- template <unsigned inbits, unsigned outbits>
- color<3, outbits, nrgb_traits>
- yuv_to_nrgb(const color<3, inbits, yuv_traits>& v)
- {
- f_yuv_to_nrgb<inbits, outbits> f;
-
- return f(v);
- }
-
- } // convert
-} // oln
-
-#endif // OLENA_CONVERT_NRGBYUV_HH
--
Giovanni Palma
EPITA - promo 2005 - membre d'EpX - LRDE
Mob. : +33 (0)6 60 97 31 74