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 --- run.sh | 2 +- src/lib/seg/util.c | 13 +++++-------- src/main.c | 14 ++++++++++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/run.sh b/run.sh index b87a185..8b9c597 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,4 @@ #!/bin/sh SOURCE="$1" mkdir -p output/${SOURCE} -./build/prog -s -d data/${SOURCE} -b output/${SOURCE}/${SOURCE}.bin -p output/${SOURCE}/${SOURCE}.png +./build/prog -s -n 8 -d data/${SOURCE} -b output/${SOURCE}/${SOURCE}.bin -p output/${SOURCE}/${SOURCE}.png 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; } } diff --git a/src/main.c b/src/main.c index 204f77f..d51765c 100644 --- a/src/main.c +++ b/src/main.c @@ -21,8 +21,6 @@ #define OFFSET 16 -#define N_DILATIONS 10 - #define MIN_AREA 500 #define MIN_PERIMETER 0 @@ -32,11 +30,12 @@ int main(int argc, char** argv) char* directory = NULL; char* png_file = "../out.png"; char* bin_file = "../out.bin"; + size_t closeup_pixel_count = 10; bool_t silent = FALSE; //----------------------------------------------- //-GET-COMMAND-LINE-ARGUMENTS-------------------- //----------------------------------------------- - while ((opt = getopt(argc, argv, "d:b:p:s")) != -1) { + while ((opt = getopt(argc, argv, "d:b:p:n:s")) != -1) { switch (opt) { case 's': silent = TRUE; @@ -59,6 +58,13 @@ int main(int argc, char** argv) } png_file = optarg; break; + case 'n': + if (!silent) { + printf("Closeup Size: %d\n", atoi(optarg)); + closeup_pixel_count = atoi(optarg); + } + png_file = optarg; + break; case ':': if (!silent) { printf("Option requires value\n"); @@ -181,7 +187,7 @@ int main(int argc, char** argv) //-CLOSE-UP-SMALL-GAPS-BETWEEN-REGIONS----------- //----------------------------------------------- TIME(ts_start); - closeup(&masks, width, height, N_DILATIONS); + closeup(&masks, width, height, closeup_pixel_count); TIME(ts_end); if (!silent) { printf("Closing up took %f ms\n", 1000*diff_time(&ts_end, &ts_start)); -- cgit v1.2.1