diff options
author | Christian C <cc@localhost> | 2025-03-05 20:30:01 -0800 |
---|---|---|
committer | Christian C <cc@localhost> | 2025-03-05 20:30:01 -0800 |
commit | ffeadedd0510cb7194058c8c66c21b57f6fa02f2 (patch) | |
tree | 37c592b1f2e9c7420a1694f218761822c5c68e5d /src | |
parent | 7f5a8fa0f7f3e1aacb4ff770b4a68f19ae8eebef (diff) |
Cleanup
TODO: Create erosion function for filling gaps
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 25 |
1 files changed, 20 insertions, 5 deletions
@@ -17,7 +17,7 @@ #define OFFSET 16 -#define N_DILATIONS 3 +#define N_DILATIONS 0 #define MIN_AREA 200 #define MIN_PERIMETER 50 @@ -33,11 +33,15 @@ int main(int argc, char** argv) uint32_t width, height; uint16_t starting_label = 1; uint16_t *masks = NULL; + // Expect a directory to be passed as the first argument if (argc > 1) { + // Ensure the directory exists if (is_directory(argv[1])) { + // List files in the ddirectory file_list = list_directory(argv[1]); if (file_list) { size_t index = 0; + // For each file while (1) { char* fname = file_list[index]; if (fname == NULL) { @@ -47,9 +51,23 @@ int main(int argc, char** argv) free(file_list[index++]); continue; } + // If we have a tiff file + // 1. Convert to labels + // 2. Find contiguous regions + // 3. Combine with current total mask + // 4. Free up allocations made in this process char* fpath = full_path(argv[1], fname); + if (fpath == NULL) { + free(file_list[index++]); + continue; + } printf("Loading %s...\n", fpath); uint16_t *file_labels = tif_to_labels(fpath, &width, &height, &starting_label); + if (file_labels == NULL) { + free(fpath); + free(file_list[index++]); + continue; + } masks = combine_masks(masks, file_labels, width, height); free(file_labels); free(fpath); @@ -119,9 +137,6 @@ int main(int argc, char** argv) struct AVLNode* small_label_tree = NULL; small_label_tree = get_small_labels(NULL, root, MIN_AREA, MIN_PERIMETER); - print_in_order_uint16_t(small_label_tree); - printf("\n"); - // Remove the small labels for (size_t y = 0; y < height; y++) { for (size_t x = 0; x < width; x++) { @@ -155,7 +170,7 @@ int main(int argc, char** argv) labels = masks; masks = temp; free(labels); - printf("%u labels found\n", starting_label-1); + printf("%u remaining labels found\n", starting_label-1); printf("Mask dimensions: %u %u\n", width, height); // Regenerate information after relabeling root = NULL; |