[gegl] slic: initialize best cluster to 0 instead of using labels buffer values
- From: Thomas Manni <tmanni src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] slic: initialize best cluster to 0 instead of using labels buffer values
- Date: Tue, 3 Sep 2019 16:37:04 +0000 (UTC)
commit 8aa147086fef9f04cd15c9e9a8deea7dfbf90d0f
Author: Thomas Manni <thomas manni free fr>
Date: Tue Sep 3 17:42:49 2019 +0200
slic: initialize best cluster to 0 instead of using labels buffer values
also use unsigned int to handle GArray indexes.
Fixes issue #196
operations/common/slic.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
---
diff --git a/operations/common/slic.c b/operations/common/slic.c
index 2a7839364..bb3674037 100644
--- a/operations/common/slic.c
+++ b/operations/common/slic.c
@@ -167,7 +167,7 @@ assign_labels (GeglBuffer *labels,
GeglBufferIterator *iter;
GArray *clusters_index;
- clusters_index = g_array_sized_new (FALSE, FALSE, sizeof (gint), 9);
+ clusters_index = g_array_sized_new (FALSE, FALSE, sizeof (guint), 9);
iter = gegl_buffer_iterator_new (input, NULL, 0, format,
GEGL_ACCESS_READ, GEGL_ABYSS_NONE, 2);
@@ -182,7 +182,8 @@ assign_labels (GeglBuffer *labels,
gfloat *pixel = iter->items[0].data;
guint32 *label = iter->items[1].data;
glong n_pixels = iter->length;
- gint x, y, i;
+ gint x, y;
+ guint i;
x = roi->x;
y = roi->y;
@@ -214,12 +215,12 @@ assign_labels (GeglBuffer *labels,
/* find the nearest cluster */
gfloat min_distance = G_MAXFLOAT;
- gint best_cluster = *label;
+ guint best_cluster = 0;
for (i = 0; i < clusters_index->len ; i++)
{
gfloat distance;
- gint index = g_array_index (clusters_index, gint, i);
+ guint index = g_array_index (clusters_index, guint, i);
Cluster *tmp = &g_array_index (clusters, Cluster, index);
if (x < tmp->search_window.x ||
@@ -245,8 +246,6 @@ assign_labels (GeglBuffer *labels,
c->sum[4] += (gfloat) y;
c->n_pixels++;
- g_assert (best_cluster != -1);
-
*label = best_cluster;
pixel += 3;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]