aboutsummaryrefslogtreecommitdiff
path: root/src/lib/seg/util.c
diff options
context:
space:
mode:
authorChristian C <cc@localhost>2025-03-06 18:06:56 -0800
committerChristian C <cc@localhost>2025-03-06 18:06:56 -0800
commit8a879518c5939f7a998cb4c5298064ee5532c4fd (patch)
tree0b5db4261c7de1f0eafaee36f6e47bc2d553189c /src/lib/seg/util.c
parent636f829a0e5062151eb9af6b6ad0bd4155e2749e (diff)
Fix closeup logic
Diffstat (limited to 'src/lib/seg/util.c')
-rw-r--r--src/lib/seg/util.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/lib/seg/util.c b/src/lib/seg/util.c
index 8a5f5e5..677e8f5 100644
--- a/src/lib/seg/util.c
+++ b/src/lib/seg/util.c
@@ -115,39 +115,36 @@ void dilate(uint16_t** mask, uint32_t width, uint32_t height)
uint16_t* _erode(uint16_t* mask, uint32_t width, uint32_t height)
{
uint16_t *new_mask = (uint16_t*)calloc(width*height,sizeof(uint16_t));
+ memcpy(new_mask, mask, width*height*sizeof(uint16_t));
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
size_t current_position = xy_to_coord(x, y, width, height);
- if (mask[current_position] != 0) {
- new_mask[current_position] = mask[current_position];
- continue;
- }
size_t proposed_position;
if (x != 0) {
proposed_position = xy_to_coord(x-1, y, width, height);
if (mask[proposed_position] == 0) {
- new_mask[current_position] = mask[proposed_position];
+ new_mask[current_position] = 0;
continue;
}
}
if ((x+1) != width) {
proposed_position = xy_to_coord(x+1, y, width, height);
if (mask[proposed_position] == 0) {
- new_mask[current_position] = mask[proposed_position];
+ new_mask[current_position] = 0;
continue;
}
}
if (y != 0) {
proposed_position = xy_to_coord(x, y-1, width, height);
if (mask[proposed_position] == 0) {
- new_mask[current_position] = mask[proposed_position];
+ new_mask[current_position] = 0;
continue;
}
}
if ((y+1) != height) {
proposed_position = xy_to_coord(x, y+1, width, height);
if (mask[proposed_position] == 0) {
- new_mask[current_position] = mask[proposed_position];
+ new_mask[current_position] = 0;
continue;
}
}