Browse Source

Use key-value file to store configuration

Matthias Vogelgesang 9 years ago
parent
commit
db09ba380a
2 changed files with 192 additions and 11 deletions
  1. 129 11
      piv.c
  2. 63 0
      piv.cfg

+ 129 - 11
piv.c

@@ -1,25 +1,60 @@
 #include <ufo/ufo.h>
-#include <stdio.h>
+#include <stdlib.h>
 #include "piv-scheduler.h"
 #include "piv-nodes.h"
 #include "piv-ufo-base.h"
 
-int main (void)
+static void
+check_error (GError *error)
+{
+    if (error != NULL) {
+        g_print ("Error reading configuration: %s\n", error->message);
+        exit (1);
+    }
+}
+
+int
+main (int argc, char *argv[])
 {
     struct piv_nodes piv;
     struct piv_ufo_base piv_base;
+    GOptionContext *context;
+    GKeyFile *key_file;
+    GError *error = NULL;
+    static gchar *key_file_name = NULL;
+
+    static GOptionEntry entries[] = {
+        { "config", 'c', 0, G_OPTION_ARG_STRING, &key_file_name, "Configuration file name (default piv.cfg)", "FILE" },
+        { NULL }
+    };
 
 #if !(GLIB_CHECK_VERSION (2, 36, 0))
     g_type_init ();
 #endif
 
+    context = g_option_context_new (NULL);
+    g_option_context_add_main_entries (context, entries, NULL);
+
+    if (!g_option_context_parse (context, &argc, &argv, &error)) {
+        g_print ("Failed parsing arguments: %s\n", error->message);
+        return 1;
+    }
+
+    if (!key_file_name)
+        key_file_name = "piv.cfg";
+
     piv_ufo_base_init(&piv_base);
     piv_nodes_init(&piv, &piv_base);
+
     if (piv_base.error)
-        printf("Error %s\n", piv_base.error->message);
+        g_print ("Error %s\n", piv_base.error->message);
 
-    /* This file include all the configurations that can be passed to the
-     * plugins */
+    key_file = g_key_file_new ();
+
+    if (!g_key_file_load_from_file (key_file, key_file_name, G_KEY_FILE_NONE, &error)) {
+        g_print ("Error loading `%s': %s", key_file_name, error->message);
+        return 1;
+    }
 
     /*********************/
     /* CONFIGURATION *****/
@@ -27,7 +62,49 @@ int main (void)
     UfoTaskNode *global_reader;
     global_reader = ufo_plugin_manager_get_task (piv_base.manager, "read", &piv_base.error);
 
-#include "config.h"
+    gchar *input_path = g_key_file_get_string (key_file, "input", "path", &error);
+    check_error (error);
+
+    guint scale = (guint) g_key_file_get_integer (key_file, "input", "scale", &error);
+    check_error (error);
+
+    g_object_set (G_OBJECT (global_reader), "path", input_path, NULL);
+    g_object_set (G_OBJECT (piv.writer), "filename", "res%i.tif", NULL);
+    g_object_set (G_OBJECT (piv.ringwriter), "filename", "results", NULL);
+
+    g_object_set (G_OBJECT (piv.denoise), "matrix_size",
+                  g_key_file_get_integer (key_file, "input", "matrix_size", &error) / scale, NULL);
+    check_error (error);
+
+    g_object_set (G_OBJECT (piv.contrast), "remove_high",
+                  g_key_file_get_boolean (key_file, "input", "remove_high_intensity_pixels", &error), NULL);
+    check_error (error);
+
+    guint ring_start = ((guint)  g_key_file_get_integer (key_file, "ring", "start", &error)) / scale;
+    check_error (error);
+
+    guint ring_end = ((guint)  g_key_file_get_integer (key_file, "ring", "end", &error)) / scale;
+    check_error (error);
+
+    guint ring_step = ((guint)  g_key_file_get_integer (key_file, "ring", "step", &error)) / scale;
+    check_error (error);
+
+    g_object_set (G_OBJECT (piv.ring_pattern),
+                  "ring_start", ring_start,
+                  "ring_end", ring_end,
+                  "ring_step", ring_step, NULL);
+
+    g_object_set (G_OBJECT (piv.ring_pattern), "ring_thickness",
+                  g_key_file_get_integer (key_file, "ring", "thickness", &error) / scale, NULL);
+    check_error (error);
+
+    g_object_set (G_OBJECT (piv.ring_pattern), "width",
+                  g_key_file_get_integer (key_file, "ring", "width", &error) / scale, NULL);
+    check_error (error);
+
+    g_object_set (G_OBJECT (piv.ring_pattern), "height",
+                  g_key_file_get_integer (key_file, "ring", "height", &error) / scale, NULL);
+    check_error (error);
 
     g_object_set (G_OBJECT (piv.ringwriter), "scale", scale, NULL);
 
@@ -40,12 +117,46 @@ int main (void)
     g_object_set (G_OBJECT (piv.dump_ring), "scale", scale, NULL);
 
     /* Does not need user configuration */
-    unsigned number_of_rings = (ring_end - ring_start) / ring_step + 1;
-    g_object_set (G_OBJECT (piv.duplicater), "dup_count", number_of_rings,
-                  NULL);
+    guint number_of_rings = (ring_end - ring_start) / ring_step + 1;
+    g_object_set (G_OBJECT (piv.duplicater), "dup_count", number_of_rings, NULL);
     g_object_set (G_OBJECT (piv.concatenate_result), "ring_count", number_of_rings, NULL);
     g_object_set (G_OBJECT (piv.loop_ringfft), "loop", 1, NULL);
-    g_object_set (G_OBJECT (piv.loop_ringfft), "dup_count", number_of_images, NULL);
+
+    g_object_set (G_OBJECT (piv.loop_ringfft), "dup_count",
+                  g_key_file_get_integer (key_file, "input", "num_images", &error), NULL);
+    check_error (error);
+
+    g_object_set (G_OBJECT (piv.concatenate_result), "max_count",
+                  g_key_file_get_integer (key_file, "ring", "max_count", &error), NULL);
+    check_error (error);
+
+    g_object_set (G_OBJECT (piv.filter_particle), "min",
+                  g_key_file_get_double (key_file, "filter", "min", &error), NULL);
+    check_error (error);
+
+    g_object_set (G_OBJECT (piv.filter_particle), "threshold",
+                  g_key_file_get_double (key_file, "filter", "threshold", &error), NULL);
+    check_error (error);
+
+    g_object_set (G_OBJECT (piv.get_dup_circ), "threshold",
+                  g_key_file_get_double (key_file, "dup", "threshold", &error) / scale, NULL);
+    check_error (error);
+
+    g_object_set (G_OBJECT (piv.remove_circle), "threshold",
+                  g_key_file_get_double (key_file, "remove", "threshold", &error) / scale, NULL);
+    check_error (error);
+
+    g_object_set (G_OBJECT (piv.multi_search), "radii_range",
+                  g_key_file_get_integer (key_file, "radii", "range", &error) / scale, NULL);
+    check_error (error);
+
+    g_object_set (G_OBJECT (piv.multi_search), "threshold",
+                  g_key_file_get_double (key_file, "radii", "threshold", &error), NULL);
+    check_error (error);
+
+    g_object_set (G_OBJECT (piv.multi_search), "displacement",
+                  g_key_file_get_integer (key_file, "radii", "displacement", &error) / scale, NULL);
+    check_error (error);
 
     /*********************/
     /* GRAPH SETUP *******/
@@ -57,10 +168,13 @@ int main (void)
         g_print("Main : No GPUs found\n");
         return 1;
     }
+
     g_print("Main : Connecting nodes %p\n", it->data);
     piv_nodes_set_gpu(&piv, it->data);
     piv_nodes = g_list_append(piv_nodes, &piv);
-    piv_ufo_base_connect(&piv_base, &piv, scale, dump_ring_to_image, global_reader);
+    piv_ufo_base_connect (&piv_base, &piv, scale,
+                          g_key_file_get_boolean (key_file, "output", "dump_ring_to_image", &error), global_reader);
+    check_error (error);
 
     // Graph expansion for usage of multiple GPUs.  Uncomment lines when UFO
     // supports calling plug-ins on demand
@@ -81,9 +195,13 @@ int main (void)
     /*********************/
 
     piv_ufo_base_unref(&piv_base);
+
     for (it = piv_nodes; it; it = it->next)
         piv_nodes_unref(it->data);
+
     g_object_unref (global_reader);
+    g_option_context_free (context);
+    g_key_file_free (key_file);
 
     return 0;
 }

+ 63 - 0
piv.cfg

@@ -0,0 +1,63 @@
+[input]
+path=data/Image0.tif
+scale=2
+num_images=1
+
+# Define matrix_size to determines the number of surrounding pixels to # be
+# compared with, ideally make this number uneven # Being twice the size of the
+# actual ring thickness tends to be good 
+matrix_size=26
+
+# Whether or not to remove high intensity pixels
+remove_high_intensity_pixels=false
+
+[output]
+dump_ring_to_image=false
+
+[ring]
+start=10
+end=130
+step=2
+
+# Giving thickness of rpiv.ing NOTE if rings raddi apiv.nd thickness are too
+# big, you will get errors from the gpu saying CL_piv.INVALID_WORK_GROUP_SIZE
+thickness=6
+
+# Set the maximum number of rings that should detected per ring pattern, if the
+# number of found rings is greater than max_count, then the output is ignored
+max_count=100
+
+# Should be the same dimension as input image
+width=1080
+height=1280
+
+[filter]
+# When images maximum is less than min ignore output. Min is the likelyness
+# value for a pixel to be the center of a ring and ranges from 0 to 1
+min=0.125
+
+# Consider only pixels that are above 0.8 * max when searching for clusters of
+# pixels. Where max, is the highest intensity in the image
+threshold=0.8
+
+[dup]
+# Set minumum distance between rings, and how close two different radius are
+# considerend to be same ring
+threshold=8.0
+
+[remove]
+# Up to what radii difference is a ring considered an inner or outer ring of two
+# intersecting rings
+threshold=4.0
+
+[radii]
+# Vary up from -radii_range to randii_range the radius to find the polynomial
+# that corresponds to the rings contrast
+range=6
+
+# Set the minimum contrast a ring should have to be considered a ring
+threshold=0.01
+
+# By how much may the ring center be displaced to find it's actual center and
+# it's actual radius
+displacement=1