aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index fa09a86..5746cd8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;