---
milena/ChangeLog | 5 +
.../green => milena}/mln/clustering/kmean_rgb.hh | 106 ++++++++++----------
2 files changed, 57 insertions(+), 54 deletions(-)
copy {scribo/sandbox/green => milena}/mln/clustering/kmean_rgb.hh (93%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index fee653d..66d79f3 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,8 @@
+2010-11-15 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ * mln/clustering/kmean_rgb.hh: Import Kmean RGB from Yann's
+ sandbox.
+
2010-06-21 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
Fix the way to convert unsigned to float.
diff --git a/scribo/sandbox/green/mln/clustering/kmean_rgb.hh
b/milena/mln/clustering/kmean_rgb.hh
similarity index 93%
copy from scribo/sandbox/green/mln/clustering/kmean_rgb.hh
copy to milena/mln/clustering/kmean_rgb.hh
index 544066b..daf6499 100644
--- a/scribo/sandbox/green/mln/clustering/kmean_rgb.hh
+++ b/milena/mln/clustering/kmean_rgb.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007,2008,2009,2010 EPITA LRDE
+// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -167,7 +167,7 @@ namespace mln
/// \return an image which represents the pixel classification.
template <typename T, unsigned n, typename I>
inline
- image2d<value::label_8>
+ mln_ch_value(I,value::label_8)
kmean_rgb(const Image<I>& point,
const unsigned k_center,
const unsigned watch_dog,
@@ -544,16 +544,22 @@ namespace mln
}
};
- template <typename T, unsigned n>
+ template <typename T, unsigned n, typename I>
inline
- image2d<value::label_8>
- kmean_image2d_rgb(const image2d< value::rgb<n> >& point,
- const unsigned k_center,
- const unsigned watch_dog = 10,
- const unsigned n_times = 10)
+ mln_ch_value(I,value::label_8)
+ kmean_image2d_rgb(const Image<I>& point__,
+ const unsigned k_center,
+ const unsigned watch_dog = 10,
+ const unsigned n_times = 10)
{
trace::entering("mln::clustering::impl::kmean_image2d_rgb");
- trace::quiet = true;
+
+ const I& point = exact(point__);
+ typedef mln_value(I) V;
+ mlc_is(V, value::rgb<n>)::check();
+ mlc_bool(mln_site_(I)::dim == 2u)::check();
+ mln_precondition(point.is_valid());
+
// BEGIN TYPEDEF
typedef value::rgb<8> t_rgb;
typedef value::label<8> t_label;
@@ -564,7 +570,7 @@ namespace mln
typedef T t_result1d;
typedef algebra::vec<3,T> t_result3d;
- typedef image2d<t_value> t_point_img;
+ typedef I t_point_img;
typedef image3d<unsigned> t_histo_img;
typedef util::array<t_result1d> t_number_img;
typedef util::array<t_result3d> t_mean_img;
@@ -574,7 +580,7 @@ namespace mln
typedef image3d<t_result1d> t_distance_val;
typedef util::array<t_distance_val> t_distance_img;
- typedef image2d<t_label> t_label_dbg;
+ typedef mln_ch_value(I,t_label) t_label_dbg;
typedef image2d<t_rgb> t_color_dbg;
typedef image2d<t_value> t_mean_dbg;
@@ -702,18 +708,14 @@ namespace mln
while (_current_launching < _n_times)
{
// BEGIN LAUNCH ONE TIME
- trace::quiet = false;
trace::entering("Launch one time");
- trace::quiet = true;
{
t_result1d old_variance = mln_max(t_result1d);
_within_variance = mln_max(t_result1d);
_current_step = 0;
// BEGIN INIT_MEAN
- trace::quiet = false;
trace::entering("init mean");
- trace::quiet = true;
{
t_value_comp0 min_comp0 = mln_min(t_value_comp0);
t_value_comp0 max_comp0 = mln_max(t_value_comp0);
@@ -730,16 +732,12 @@ namespace mln
_mean[l.index_()][2]=(rand()%(max_comp2-min_comp2))+min_comp2;
}
}
- trace::quiet = false;
trace::exiting("init mean");
- trace::quiet = true;
// END INIT MEAN
// UPDATE DISTANCE
- trace::quiet = false;
trace::entering("update distance");
- trace::quiet = true;
for (unsigned i = 0; i < _k_center; ++i)
{
@@ -760,9 +758,7 @@ namespace mln
}
}
- trace::quiet = false;
trace::exiting("update distance");
- trace::quiet = true;
// END UPDATE DISTANCE
do
@@ -770,9 +766,7 @@ namespace mln
old_variance = _within_variance;
// BEGIN UPDATE GROUP
- trace::quiet = false;
trace::entering("update group");
- trace::quiet = true;
{
mln_piter(t_group_img) rgb(_group.domain());
@@ -795,15 +789,11 @@ namespace mln
}
}
- trace::quiet = false;
trace::exiting("update group");
- trace::quiet = true;
// END UPDATE GROUP
// BEGIN UPDATE MEAN
- trace::quiet = false;
trace::entering("update mean");
- trace::quiet = true;
{
mln_eiter(t_number_img) en(_number);
mln_eiter(t_mean_img) em(_mean);
@@ -836,9 +826,7 @@ namespace mln
_mean[l.index_()] /= _number[l.index_()];
}
}
- trace::quiet = false;
trace::exiting("update mean");
- trace::quiet = true;
// END UPDATE MEAN
@@ -847,9 +835,7 @@ namespace mln
break;
// UPDATE DISTANCE
- trace::quiet = false;
trace::entering("update distance");
- trace::quiet = true;
for (unsigned i = 0; i < _k_center; ++i)
{
@@ -865,15 +851,11 @@ namespace mln
(diff2_row + diff2_col + diff2_sli);
}
}
- trace::quiet = false;
trace::exiting("update distance");
- trace::quiet = true;
// END UPDATE DISTANCE
// BEGIN UPDATE VARIANCE
- trace::quiet = false;
trace::entering("update variance");
- trace::quiet = true;
{
_within_variance = literal::zero;
mln_eiter(t_variance_img) l(_variance);
@@ -894,9 +876,7 @@ namespace mln
}
}
- trace::quiet = false;
trace::exiting("update variance");
- trace::quiet = true;
// END UPDATE VARIANCE
//update_cnv();
@@ -909,9 +889,7 @@ namespace mln
//finalize_cnv();
//build_all_dbg();
}
- trace::quiet = false;
trace::exiting("Launch one time");
- trace::quiet = true;
// END LAUNCH ONE TIME
if ((_is_number_valid && (_current_step < _watch_dog))||
@@ -962,7 +940,6 @@ namespace mln
// }
// END BUILD LABEL IMAGE
- trace::quiet = false;
trace::exiting("mln::clustering::impl::kmean_image2d_rgb");
return _label_dbg;
@@ -982,27 +959,49 @@ namespace mln
namespace internal
{
- template <typename T, unsigned n>
+ template <typename T, unsigned n, typename I>
inline
- image2d<value::label_8>
- kmean_rgb_dispatch(const image2d< value::rgb<n> >& img,
- const unsigned k_center,
- const unsigned watch_dog,
- const unsigned n_times)
+ mln_ch_value(I,value::label_8)
+ kmean_rgb_dispatch(const Image<I>& img,
+ const unsigned k_center,
+ const unsigned watch_dog,
+ const unsigned n_times,
+ const value::rgb<n>&,
+ const point2d&)
{
return impl::kmean_image2d_rgb<T,n>(img, k_center, watch_dog, n_times);
}
+ template <typename T, unsigned n, typename I, typename V, typename P>
+ inline
+ mln_ch_value(I,value::label_8)
+ kmean_rgb_dispatch(const Image<I>& img,
+ const unsigned k_center,
+ const unsigned watch_dog,
+ const unsigned n_times,
+ const V&,
+ const P&)
+ {
+ // No kmean implementation found.
+ mlc_abort(I)::check();
+
+ typedef mln_ch_value(I, value::label_8) output_t;
+ return output_t();
+ }
+
template <typename T, unsigned n, typename I>
inline
- image2d< value::label_8>
+ mln_ch_value(I,value::label_8)
kmean_rgb_dispatch(const Image<I>& img,
const unsigned k_center,
const unsigned watch_dog,
const unsigned n_times)
{
- return kmean_rgb_dispatch<T,n>(exact(img),k_center,watch_dog,n_times);
+ typedef mln_value(I) V;
+ typedef mln_site(I) P;
+ return kmean_rgb_dispatch<T,n>(img, k_center, watch_dog,
+ n_times, V(), P());
}
@@ -1015,7 +1014,7 @@ namespace mln
template <typename T, unsigned n, typename I>
inline
- image2d<value::label_8>
+ mln_ch_value(I,value::label_8)
kmean_rgb(const Image<I>& point,
const unsigned k_center,
const unsigned watch_dog,
@@ -1023,13 +1022,12 @@ namespace mln
{
trace::entering("mln::clustering::kmean_rgb");
- image2d<value::label_8> tmp = internal::kmean_rgb_dispatch<T,n>(point,
- k_center,
- watch_dog,
- n_times);
+ mln_ch_value(I, value::label_8)
+ output = internal::kmean_rgb_dispatch<T,n>(point, k_center,
+ watch_dog, n_times);
trace::exiting("mln::clustering::kmean_rgb");
- return tmp;
+ return output;
}
--
1.5.6.5