[gegl] alpha-inpaint: disable bail in score building



commit 65ed686286c900b24fbfbd54a0b027affcdfe70f
Author: Øyvind Kolås <pippin gimp org>
Date:   Tue Jul 2 23:26:28 2019 +0200

    alpha-inpaint: disable bail in score building

 operations/workshop/inpaint.c      | 76 ++++++++++++++++++++++++++++++++------
 operations/workshop/pixel-duster.h |  7 +---
 2 files changed, 66 insertions(+), 17 deletions(-)
---
diff --git a/operations/workshop/inpaint.c b/operations/workshop/inpaint.c
index 20a7af0ae..0b65af19c 100644
--- a/operations/workshop/inpaint.c
+++ b/operations/workshop/inpaint.c
@@ -26,10 +26,11 @@
 
 #ifdef GEGL_PROPERTIES
 
+
 property_int (seek_distance, "seek radius", 30)
   value_range (4, 512)
 
-property_int (min_neigh, "min neigh", 3)
+property_int (min_neigh, "min neigh", 2)
   value_range (0, 4)
 
 property_int (min_iter, "min iter", 100)
@@ -38,10 +39,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)
-  value_range (0, 30)
+property_int (improvement_iters, "improvement iters", 2)
+
+property_int (k, "k", 1)
+  value_range (1, 5)
 
-property_double (chance_try, "try chance", 0.66)
+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)
@@ -55,11 +58,11 @@ property_double (ring_gap,    "ring gap", 1.3)
 property_double (ring_gamma, "ring gamma", 1.4)
   value_range (0.0, 4.0)
   ui_steps    (0.1, 0.2)
-property_double (ring_twist, "ring twist", 0.033)
+property_double (ring_twist, "ring twist", 0.0)
   value_range (0.0, 1.0)
   ui_steps    (0.01, 0.2)
 
-property_double (ring_gap1,    "ring gap1", 1.5)
+property_double (ring_gap1,    "ring gap1", 1.2)
   value_range (0.0, 8.0)
   ui_steps    (0.25, 0.25)
 
@@ -79,7 +82,7 @@ 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.100)
+property_double (metric_empty_hay_score, "metric empty hay score", 0.5)
   value_range (0.01, 100.0)
   ui_steps    (0.05, 0.1)
 
@@ -87,10 +90,13 @@ property_double (metric_empty_needle_score, "metric empty needle score", 0.033)
   value_range (0.01, 100.0)
   ui_steps    (0.05, 0.1)
 
-property_double (metric_cohesion, "metric cohesion", 0.005)
+property_double (metric_cohesion, "metric cohesion", 0.004)
   value_range (0.0, 10.0)
   ui_steps    (0.2, 0.2)
 
+property_double (scale, "enlarge as well as inpaint 1.0 does nothing", 1.0)
+  value_range (0.0, 10.0)
+  ui_steps    (0.5, 0.5)
 
 
 #else
@@ -123,6 +129,29 @@ prepare (GeglOperation *operation)
   gegl_operation_set_format (operation, "output", format);
 }
 
+static void scaled_copy (PixelDuster *duster,
+                         GeglBuffer *in,
+                         GeglBuffer *out,
+                         gfloat      scale)
+{
+  GeglRectangle rect;
+  const Babl *format = babl_format ("RGBA float");
+  gint x, y;
+
+  rect = *gegl_buffer_get_extent (in);
+  for (y = 0; y < rect.height; y++)
+    for (x = 0; x < rect.width; x++)
+      {
+        float rgba[4];
+        gegl_sampler_get (duster->in_sampler_f, x, y, NULL,
+                          &rgba[0], 0);
+        {
+          GeglRectangle r = {x * scale, y * scale, 1, 1};
+          gegl_buffer_set (out, &r, 0, format, &rgba[0], 0);
+        }
+      }
+}
+
 
 static gboolean
 process (GeglOperation       *operation,
@@ -136,14 +165,14 @@ process (GeglOperation       *operation,
   GeglRectangle out_rect = *gegl_buffer_get_extent (output);
   PixelDuster    *duster = pixel_duster_new (input, input, output, &in_rect, &out_rect,
                                              o->seek_distance,
-                                             1, // max_k
+                                             o->k, // max_k
                                              o->min_neigh,
                                              o->min_iter,
                                              o->max_iter,
                                              o->chance_try,
                                              o->chance_retry,
-                                             1.0, // scale_x
-                                             1.0, // scale_y
+                                             o->scale, // scale_x
+                                             o->scale, // scale_y
                                              o->improvement_iters,
                                              o->ring_gap,
                                              o->ring_gap1,
@@ -157,7 +186,12 @@ process (GeglOperation       *operation,
                                              o->metric_empty_needle_score,
                                              o->metric_cohesion/1000.0,
                                              operation);
-  gegl_buffer_copy (input, NULL, GEGL_ABYSS_NONE, output, NULL);
+
+  if (o->scale > 0.9999 && o->scale < 1.0001)
+    gegl_buffer_copy (input, NULL, GEGL_ABYSS_NONE, output, NULL);
+  else
+    scaled_copy (duster, input, output, o->scale);
+
   pixel_duster_add_probes_for_transparent (duster);
 
   seed_db (duster);
@@ -205,6 +239,23 @@ operation_process (GeglOperation        *operation,
                                    gegl_operation_context_get_level (context));
 }
 
+static GeglRectangle
+get_bounding_box (GeglOperation *operation)
+{
+  GeglProperties *o      = GEGL_PROPERTIES (operation);
+  GeglRectangle *res = gegl_operation_source_get_bounding_box (operation, "input");
+  GeglRectangle result = {0,0,100,100};
+  if (res)
+    result = *res;
+  result.x = 0;
+  result.y = 0;
+  result.width  *= o->scale;
+  result.height *= o->scale;
+
+  return result;
+}
+
+
 static void
 gegl_op_class_init (GeglOpClass *klass)
 {
@@ -217,6 +268,7 @@ gegl_op_class_init (GeglOpClass *klass)
   filter_class->process                    = process;
   operation_class->prepare                 = prepare;
   operation_class->process                 = operation_process;
+  operation_class->get_bounding_box        = get_bounding_box;
   operation_class->get_required_for_output = get_required_for_output;
   operation_class->get_cached_region       = get_cached_region;
   operation_class->opencl_support          = FALSE;
diff --git a/operations/workshop/pixel-duster.h b/operations/workshop/pixel-duster.h
index dd009d0b1..bdfb7bdc6 100644
--- a/operations/workshop/pixel-duster.h
+++ b/operations/workshop/pixel-duster.h
@@ -92,7 +92,7 @@ typedef struct
 #define RAYS                    12 // good values for testing 6 8 10 12 16
 #define NEIGHBORHOOD            (RINGS*RAYS+1)
 
-#define N_SCALE_NEEDLES         3
+#define N_SCALE_NEEDLES         1
 
 
 typedef struct _Probe Probe;
@@ -377,7 +377,7 @@ score_site (PixelDuster *duster,
     return INITIAL_SCORE;
   }
 
-  for (i = 1; i < NEIGHBORHOOD && score < bail; i++)
+  for (i = 1; i < NEIGHBORHOOD /* && score < bail */; i++)
   {
     if (needle[i*4 + 3]>0.001f)
     {
@@ -395,8 +395,6 @@ score_site (PixelDuster *duster,
       score += duster->metric_empty_needle_score * duster->order[i][2];
     }
 
-
-
     {
       /* both empty in needle and empty in hay get a similar badness score */
     }
@@ -416,7 +414,6 @@ score_site (PixelDuster *duster,
     sum_x /= count;
     sum_y /= count;
 
-
     score += (POW2(sum_x - probe->source_x[0]) +
              POW2(sum_y - probe->source_y[0])) * duster->metric_cohesion;
 


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