https://svn/svn/oln/prototypes/proto-1.0/olena
Index: ChangeLog
from Nicolas Widynski <nicolas.widynski(a)lrde.epita.fr>
Update Watersnakes.
* oln/morpho/watersnakes.hh: Little modifications.
watersnakes.hh | 59 ++++++++++++++++++++++++++-------------------------------
1 file changed, 27 insertions(+), 32 deletions(-)
Index: oln/morpho/watersnakes.hh
--- oln/morpho/watersnakes.hh (revision 453)
+++ oln/morpho/watersnakes.hh (working copy)
@@ -46,7 +46,7 @@
const float INFTY = 1000000000000.f;
-# define WSHED 255
+# define WSHED -2
# define MASK_VALUE -1
typedef enum version_t { TARJAN = 0, NORMAL = 1 } version;
@@ -76,6 +76,7 @@
LS[p] = LS[p] > (float)(input[p] - input[n]) ? LS[p] : (float)(input[p] -
input[n]);
}
}
+
return LS;
}
@@ -189,7 +190,6 @@
template <typename T>
bool is_a_boundary_point(const image2d<int>& label,
- const window2d& ng,
const T& p,
unsigned& label_b)
{
@@ -207,20 +207,18 @@
template <typename T>
bool
snake_iteration(image2d<T>& label,
- const window2d& ng,
const image2d<float *>& dist,
- unsigned nb_compo,
int b)
{
float dist_min = INFTY;
point2d p_replace;
- unsigned label_replace;
+ unsigned label_replace = 0;
oln_iter_type(image2d<T>) p(label);
for_all(p)
{
unsigned label_b;
- if (is_a_boundary_point(label, ng, p, label_b))
+ if (is_a_boundary_point(label, p, label_b))
{
float tmp = - dist[p][label[p] - 1] + compute_perimeter(label, p, label[p], b) +
dist[p][label_b - 1] - compute_perimeter(label, p, label_b, b);
@@ -261,18 +259,15 @@
if (marqueur[p] == false)
{
dist[p][label[p] - 1] = input[p];
- for (int i = 0; i < nb_compo; i++)
- if (i != label[p] - 1)
+ for (unsigned i = 0; i < nb_compo; i++)
+ if ((int)i != label[p] - 1)
dist[p][i] = INFTY;
}
else
- {
- for (int i = 0; i < nb_compo; i++)
+ for (unsigned i = 0; i < nb_compo; i++)
dist[p][i] = INFTY;
}
- }
-
int i = 0;
bool stop = false;
@@ -290,7 +285,7 @@
float grad = local_grad(input, LS, p, n);
float tmp = chamfer_distance(p, n) * grad;
- for (int k = 0; k < nb_compo; k++)
+ for (unsigned k = 0; k < nb_compo; k++)
if (dist[p][k] + tmp < dist[n][k])
{
dist[n][k] = dist[p][k] + tmp;
@@ -311,7 +306,7 @@
float grad = local_grad(input, LS, p2, n);
float tmp = chamfer_distance(p2, n) * grad;
- for (int k = 0; k < nb_compo; k++)
+ for (unsigned k = 0; k < nb_compo; k++)
if (dist[p2][k] + tmp < dist[n][k])
{
dist[n][k] = dist[p2][k] + tmp;
@@ -404,7 +399,6 @@
image2d<int> output(input.size());
level::fill(output, MASK_VALUE);
- unsigned tmp;
oln_iter_type(image2d<T>) p(input);
for_all (p)
@@ -415,7 +409,7 @@
}
template<typename T, typename T2>
- image2d<T>
+ std::vector<point2d>
watershed_line(const image2d<T>& input,
const image2d<T>& orig,
const image2d<T2>& marqueur,
@@ -423,17 +417,14 @@
int b,
version v)
{
- image2d<T> res(input.size());
+ image2d<int> final(input.size());
image2d<int> label;
image2d<T2> mark(input.size());
oln_iter_type(image2d<T>) p(input);
image2d<bool> is_wshed_line(input.size());
- float dist;
- float tmp;
+ std::vector<point2d> res;
unsigned nb_compo = 0;
- int i = 0;
-
for_all(p)
mark[p] = marqueur[p];
@@ -450,8 +441,8 @@
op_type op(marqueur, input, ng);
recon = op.output;
}
-
image2d<float> LS = lower_slope(recon, ng);
+
label = init_watershed_(recon, mark, ng, nb_compo);
image2d<float*> topo = topographic_distance(recon, LS, mark, label, ng,
nb_compo);
@@ -460,8 +451,7 @@
{
unsigned mini_label = 1;
float mini_topo = topo[p][0];
- int h = 1;
- for (; h < nb_compo; h++)
+ for (unsigned h = 1; h < nb_compo; h++)
if (mini_topo > topo[p][h])
{
mini_topo = topo[p][h];
@@ -469,28 +459,33 @@
}
label[p] = mini_label;
}
- while (snake_iteration(label, ng, topo, nb_compo, b))
+
+ while (snake_iteration(label, topo, b))
;
- level::fill(res, 0);
+ level::fill(final, 0);
for_all(p)
{
oln_neighb_type(window2d) q(win_c4p(), p);
for_all (q)
if (input.hold(q))
- if (label[p] != label[q] and res[q] != WSHED)
- res[p] = WSHED;
- if (res[p] == 0)
- res[p] = orig[p];
+ if (label[p] != label[q] and final[q] != WSHED)
+ final[p] = WSHED;
+ if (final[p] == 0)
+ final[p] = orig[p];
}
+ for_all(p)
+ if (final[p] == WSHED)
+ res.push_back(p);
+
return res;
}
template<typename T, typename T2>
- image2d<T>
+ std::vector<point2d>
watersnakes_(const image2d<T>& input,
const image2d<T2>& marqueur,
const window2d& ng,
@@ -508,7 +503,7 @@
template<typename T, typename T2>
- image2d<T>
+ std::vector<point2d>
watersnakes(const image2d<T>& input,
const image2d<T2>& marqueur,
const window2d& ng,