aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian C <cc@localhost>2025-04-01 17:36:06 -0700
committerChristian C <cc@localhost>2025-04-01 17:36:06 -0700
commit2bc54ac42b831a7dfcba26c2d12ba002f80a5e40 (patch)
treeb1b55e38f0b73fb36f8c023a3f602d57f19832ff
parent18d3621cb789e443843350e5d9fbbe7bc434339c (diff)
Formatting
-rw-r--r--src/prog.c188
1 files changed, 95 insertions, 93 deletions
diff --git a/src/prog.c b/src/prog.c
index 337a71e..528450e 100644
--- a/src/prog.c
+++ b/src/prog.c
@@ -2,136 +2,134 @@
#include <stdlib.h>
#include <unistd.h>
-#include <lib/lib.h>
-#include <lib/png.h>
+#include <lib/algo/avl_tree.h>
+#include <lib/algo/flood_fill.h>
#include <lib/bool.h>
-#include <lib/monad.h>
+#include <lib/color.h>
#include <lib/dir.h>
#include <lib/file.h>
-#include <lib/time.h>
-#include <lib/color.h>
-#include <lib/algo/flood_fill.h>
-#include <lib/algo/avl_tree.h>
-#include <lib/seg/util.h>
+#include <lib/lib.h>
+#include <lib/monad.h>
+#include <lib/png.h>
#include <lib/seg/mask_data.h>
+#include <lib/seg/util.h>
+#include <lib/time.h>
-int main(int argc, char** argv)
-{
- char opt;
- char* directory = NULL;
- char* png_file = "../out.png";
- char* bin_file = "../out.bin";
+int main(int arg_count, char **arg_value) {
+ char cli_option;
+ char *process_directory = NULL;
+ char *png_output_file_fullpath = "../out.png";
+ char *bin_output_file_fullpath = "../out.bin";
size_t closeup_pixel_count = 10;
- size_t min_area = 500;
- size_t min_perimeter = 0;
- bool_t silent = FALSE;
+ size_t minimum_mask_area_threshold = 500;
+ size_t minimum_mask_perimeter_threshold = 0;
+ bool_t suppress_outputs_b = FALSE;
//-----------------------------------------------
//-GET-COMMAND-LINE-ARGUMENTS--------------------
//-----------------------------------------------
- while ((opt = getopt(argc, argv, "d:b:p:n:sA:P:")) != -1) {
- switch (opt) {
+ while ((cli_option = getopt(arg_count, arg_value, "d:b:p:n:sA:P:")) != -1) {
+ switch (cli_option) {
case 's':
- silent = TRUE;
+ suppress_outputs_b = TRUE;
break;
case 'A':
- min_area = atoi(optarg);
+ minimum_mask_area_threshold = atoi(optarg);
break;
case 'P':
- min_perimeter = atoi(optarg);
+ minimum_mask_perimeter_threshold = atoi(optarg);
break;
case 'd':
- if (!silent) {
+ if (!suppress_outputs_b) {
printf("Parse Directory: %s\n", optarg);
}
- directory = optarg;
+ process_directory = optarg;
break;
case 'b':
- if (!silent) {
- printf("Bin File: %s\n", optarg);
+ if (!suppress_outputs_b) {
+ printf("Bin File: %s\n", optarg);
}
- bin_file = optarg;
+ bin_output_file_fullpath = optarg;
break;
case 'p':
- if (!silent) {
- printf("PNG File: %s\n", optarg);
+ if (!suppress_outputs_b) {
+ printf("PNG File: %s\n", optarg);
}
- png_file = optarg;
+ png_output_file_fullpath = optarg;
break;
case 'n':
- if (!silent) {
- printf("Closeup Size: %d\n", atoi(optarg));
+ if (!suppress_outputs_b) {
+ printf("Closeup Size: %d\n", atoi(optarg));
}
closeup_pixel_count = atoi(optarg);
break;
case ':':
- if (!silent) {
- printf("Option requires value\n");
+ if (!suppress_outputs_b) {
+ printf("Option requires value\n");
}
break;
case '?':
- if (!silent) {
- printf("Unknown option: %c\n", optopt);
+ if (!suppress_outputs_b) {
+ printf("Unknown option: %c\n", optopt);
}
break;
}
}
- for (;optind < argc; optind++) {
- if (!silent) {
- printf("Extra arguments: %s\n", argv[optind]);
+ for (; optind < arg_count; optind++) {
+ if (!suppress_outputs_b) {
+ printf("Extra arguments: %s\n", arg_value[optind]);
}
}
TIME(ts_g_start);
//-----------------------------------------------
//-PROCESS-FILES-IN-DIRECTORY--------------------
//-----------------------------------------------
- char** file_list = NULL;
+ char **file_list = NULL;
MaskData_t starting_label = 1;
Mask *masks_im = NULL;
// Expect a directory to be passed as the first argument
- if (directory != NULL) {
+ if (process_directory != NULL) {
// Ensure the directory exists
- if (is_directory(directory)) {
+ if (is_directory(process_directory)) {
// List files in the ddirectory
- file_list = list_directory(directory);
+ file_list = list_directory(process_directory);
if (file_list != NULL) {
- for (size_t index = 0; file_list[index] != NULL; index++) {
- char* fname = file_list[index];
- if (is_tif_ext(fname) == FALSE) {
- 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(directory, fname);
- if (fpath == NULL) {
- free(file_list[index]);
- continue;
- }
- if (!silent) {
- printf("Loading %s...\n", fpath);
- }
- //-----------------------------------------------
- //-PROCESS-TIFF-TO-LABELS------------------------
- //-----------------------------------------------
- Mask *file_im =
- tif_to_labels(fpath, &starting_label);
+ for (size_t index = 0; file_list[index] != NULL; index++) {
+ char *fname = file_list[index];
+ if (is_tif_ext(fname) == FALSE) {
+ 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(process_directory, fname);
+ if (fpath == NULL) {
+ free(file_list[index]);
+ continue;
+ }
+ if (!suppress_outputs_b) {
+ printf("Loading %s...\n", fpath);
+ }
+ //-----------------------------------------------
+ //-PROCESS-TIFF-TO-LABELS------------------------
+ //-----------------------------------------------
+ Mask *file_im = tif_to_labels(fpath, &starting_label);
if (file_im == NULL) {
free(fpath);
free(file_list[index]);
- continue;
+ continue;
}
- //-----------------------------------------------
- //-COMBINE-LABELS-TO-GLOBAL-MASK-----------------
- //-----------------------------------------------
- masks_im = combine_masks(masks_im, file_im);
- free_image_mask(file_im);
- free(fpath);
- free(file_list[index]);
- }
- free(file_list);
+ //-----------------------------------------------
+ //-COMBINE-LABELS-TO-GLOBAL-MASK-----------------
+ //-----------------------------------------------
+ masks_im = combine_masks(masks_im, file_im);
+ free_image_mask(file_im);
+ free(fpath);
+ free(file_list[index]);
+ }
+ free(file_list);
}
}
}
@@ -147,18 +145,20 @@ int main(int argc, char** argv)
//-FIND-CONTIGUOUS-REGIONS-----------------------
//-----------------------------------------------
reduce_contiguous_regions(masks_im, &starting_label);
- if (!silent) {
- printf("%u labels found\n", starting_label-1);
+ if (!suppress_outputs_b) {
+ printf("%u labels found\n", starting_label - 1);
printf("Mask dimensions: %u %u\n", width, height);
}
//-----------------------------------------------
//-FILTER-SMALL-REGIONS-OUT----------------------
//-----------------------------------------------
TIME(ts_filter_start);
- filter_small_masks(masks_im, min_area, min_perimeter);
+ filter_small_masks(masks_im, minimum_mask_area_threshold,
+ minimum_mask_perimeter_threshold);
TIME(ts_filter_end);
- if (!silent) {
- printf("Removing small labels took %f ms\n", 1000*diff_time(&ts_filter_end, &ts_filter_start));
+ if (!suppress_outputs_b) {
+ printf("Removing small labels took %f ms\n",
+ 1000 * diff_time(&ts_filter_end, &ts_filter_start));
}
//-----------------------------------------------
//-FIND-CONTIGUOUS-REGIONS-----------------------
@@ -166,8 +166,8 @@ int main(int argc, char** argv)
//--to-make-labels-span-1-to-n-------------------
//-----------------------------------------------
reduce_contiguous_regions(masks_im, &starting_label);
- if (!silent) {
- printf("%u remaining labels found\n", starting_label-1);
+ if (!suppress_outputs_b) {
+ printf("%u remaining labels found\n", starting_label - 1);
printf("Mask dimensions: %u %u\n", width, height);
}
#ifdef AVL_INFO
@@ -175,7 +175,7 @@ int main(int argc, char** argv)
//-OPTIONAL:-------------------------------------
//-GET-MASK-META-INFORMATION---------------------
//-----------------------------------------------
- AVLNode* root = NULL;
+ AVLNode *root = NULL;
root = get_mask_data(masks_im);
if (!silent) {
printf("Inorder traversal of AVL tree: ");
@@ -188,10 +188,11 @@ int main(int argc, char** argv)
//-CLOSE-UP-SMALL-GAPS-BETWEEN-REGIONS-----------
//-----------------------------------------------
TIME(ts_start);
- closeup(masks_im,closeup_pixel_count);
+ closeup(masks_im, closeup_pixel_count);
TIME(ts_end);
- if (!silent) {
- printf("Closing (%lu) up took %f ms\n", closeup_pixel_count, 1000*diff_time(&ts_end, &ts_start));
+ if (!suppress_outputs_b) {
+ printf("Closing (%lu) up took %f ms\n", closeup_pixel_count,
+ 1000 * diff_time(&ts_end, &ts_start));
}
//-----------------------------------------------
//-END-OF-PROCESSING-----------------------------
@@ -201,17 +202,18 @@ int main(int argc, char** argv)
//-SAVE-MASK-AS-BINARY-AND-PNG-------------------
//-----------------------------------------------
if (masks_im != NULL) {
- Bitmap* bitmap = image_mask_data_to_bitmap(masks_im);
+ Bitmap *bitmap = image_mask_data_to_bitmap(masks_im);
if (bitmap != NULL) {
- save_png(bitmap, png_file);
+ save_png(bitmap, png_output_file_fullpath);
free(bitmap);
}
- write_array(bin_file, masks_im->image[0], width*height*sizeof(MaskData_t));
+ write_array(bin_output_file_fullpath, masks_im->image[0],
+ width * height * sizeof(MaskData_t));
free_image_mask(masks_im);
}
TIME(ts_g_end);
- if (!silent) {
- printf("Finished in %f ms\n", 1000*diff_time(&ts_g_end, &ts_g_start));
+ if (!suppress_outputs_b) {
+ printf("Finished in %f ms\n", 1000 * diff_time(&ts_g_end, &ts_g_start));
}
return 0;
}