From 8a879518c5939f7a998cb4c5298064ee5532c4fd Mon Sep 17 00:00:00 2001 From: Christian C Date: Thu, 6 Mar 2025 18:06:56 -0800 Subject: Fix closeup logic --- src/lib/seg/util.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/lib/seg/util.c') 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; } } -- cgit v1.2.1