[gegl] alpha-inpaint: opt out of threading, replace exhaustive search with stochastic



commit 158b9aeac30c9ada1111c827a37468cb8e442f54
Author: Øyvind Kolås <pippin gimp org>
Date:   Wed Jul 3 17:09:37 2019 +0200

    alpha-inpaint: opt out of threading, replace exhaustive search with stochastic
    
    When searching to improve a probe - do a stochastic search instead of a brute
    force linear search.

 operations/workshop/inpaint.c      | 16 ++++++++--------
 operations/workshop/pixel-duster.h | 21 ++++++++++++---------
 2 files changed, 20 insertions(+), 17 deletions(-)
---
diff --git a/operations/workshop/inpaint.c b/operations/workshop/inpaint.c
index 2492dc060..715636637 100644
--- a/operations/workshop/inpaint.c
+++ b/operations/workshop/inpaint.c
@@ -27,7 +27,7 @@
 #ifdef GEGL_PROPERTIES
 
 
-property_int (seek_distance, "seek radius", 5)
+property_int (seek_distance, "seek radius", 11)
   value_range (1, 512)
 
 property_int (min_iter, "min iter", 100)
@@ -36,12 +36,12 @@ property_int (min_iter, "min iter", 100)
 property_int (max_iter, "max iter", 2000)
   value_range (1, 40000)
 
-property_int (improvement_iters, "improvement iters", 3)
+property_int (improvement_iters, "improvement iters", 4)
 
 property_double (chance_try, "try chance", 0.33)
   value_range (0.0, 1.0)
   ui_steps    (0.01, 0.1)
-property_double (chance_retry, "retry chance", 1.0)
+property_double (chance_retry, "retry chance", 0.8)
   value_range (0.0, 1.0)
   ui_steps    (0.01, 0.1)
 
@@ -65,19 +65,19 @@ property_double (ring_gap4,    "ring gap4", 5.5)
   value_range (0.0, 16.0)
   ui_steps    (0.25, 0.25)
 
-property_double (metric_dist_powk, "metric dist powk", 1.5)
+property_double (metric_dist_powk, "metric dist powk", 2.0)
   value_range (0.0, 10.0)
   ui_steps    (0.1, 1.0)
 
-property_double (metric_empty_hay_score, "metric empty hay score", 0.5)
+property_double (metric_empty_hay_score, "metric empty hay score", 0.11)
   value_range (0.01, 100.0)
   ui_steps    (0.05, 0.1)
 
-property_double (metric_empty_needle_score, "metric empty needle score", 0.033)
+property_double (metric_empty_needle_score, "metric empty needle score", 0.2)
   value_range (0.01, 100.0)
   ui_steps    (0.05, 0.1)
 
-property_double (metric_cohesion, "metric cohesion", 0.004)
+property_double (metric_cohesion, "metric cohesion", 0.01)
   value_range (0.0, 10.0)
   ui_steps    (0.2, 0.2)
 
@@ -202,7 +202,7 @@ gegl_op_class_init (GeglOpClass *klass)
   operation_class->get_required_for_output = get_required_for_output;
   operation_class->get_cached_region       = get_cached_region;
   operation_class->opencl_support          = FALSE;
-  operation_class->threaded                = TRUE;
+  operation_class->threaded                = FALSE;
 
   gegl_operation_class_set_keys (operation_class,
       "name",        "gegl:alpha-inpaint",
diff --git a/operations/workshop/pixel-duster.h b/operations/workshop/pixel-duster.h
index 060c87117..bc0772aff 100644
--- a/operations/workshop/pixel-duster.h
+++ b/operations/workshop/pixel-duster.h
@@ -80,7 +80,7 @@ typedef struct
 
 
 #define RINGS                   4   // increments works up to 7-8 with no adver
-#define RAYS                    12 // good values for testing 6 8 10 12 16
+#define RAYS                    6  // good values for testing 6 8 10 12 16
 #define NEIGHBORHOOD            (RINGS*RAYS+1)
 
 #define N_SCALE_NEEDLES         3
@@ -617,14 +617,18 @@ static int probe_improve (PixelDuster *duster,
   probe_prep (duster, probe, needles);
 
   {
-    float iter_start_x = probe->source_x;
-    float iter_start_y = probe->source_y;
-  for (int dx = -duster->seek_radius; dx < duster->seek_radius; dx++)
-    for (int dy = -duster->seek_radius; dy < duster->seek_radius; dy++)
+    float mag = duster->seek_radius;
+    for (int i = 0; i < 32; i++)
+    {
+      int dx = g_random_int_range (-mag, mag);
+      int dy = g_random_int_range (-mag, mag);
+      mag *= 0.8; // reduce seek radius for each iteration
+      if (mag < 3)
+        mag = 3;
       if (!(dx == 0 && dy == 0))
       {
-        int test_x = iter_start_x + dx;
-        int test_y = iter_start_y + dy;
+        int test_x = probe->source_x + dx;
+        int test_y = probe->source_y + dy;
         float *hay = ensure_hay (duster, test_x, test_y);
         float score = probe_score (duster, probe, needles, test_x, test_y, hay, probe->score);
         if (score < probe->score)
@@ -634,12 +638,11 @@ static int probe_improve (PixelDuster *duster,
           probe->source_x = test_x;
           probe->source_y = test_y;
           probe->score = score;
-          //probe_update_target (duster, probe);
         }
       }
+    }
   }
 
-
   probe_post_search (duster, probe);
 
   return 0;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]