diff options
| author | Christian C <cc@localhost> | 2025-03-06 18:06:56 -0800 | 
|---|---|---|
| committer | Christian C <cc@localhost> | 2025-03-06 18:06:56 -0800 | 
| commit | 8a879518c5939f7a998cb4c5298064ee5532c4fd (patch) | |
| tree | 0b5db4261c7de1f0eafaee36f6e47bc2d553189c | |
| parent | 636f829a0e5062151eb9af6b6ad0bd4155e2749e (diff) | |
Fix closeup logic
| -rwxr-xr-x | run.sh | 2 | ||||
| -rw-r--r-- | src/lib/seg/util.c | 13 | ||||
| -rw-r--r-- | src/main.c | 14 | 
3 files changed, 16 insertions, 13 deletions
@@ -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;  	}        } @@ -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));  | 
