How Threshold Affects Gradient in GIMP Distance Map

In GIMP, the Distance Map filter generates a grayscale gradient where pixel brightness represents the physical distance to the nearest boundary. The Threshold parameter directly controls the binarization cutoff point that defines these boundaries from semi-transparent or anti-aliased inputs. By shifting the exact pixel coordinates where an edge begins, the threshold expands or contracts the source geometry, directly dictating where the distance calculation starts and how wide the resulting gradient radius extends across the canvas.

The Role of Threshold in Edge Detection

The Distance Map filter relies on clear binary boundaries (inside vs. outside) to calculate spatial distances. When working with anti-aliased text, feathered selections, or images with smooth alpha transitions, pixels contain intermediate opacity or brightness values between 0 and 255 (or 0.0 to 1.0 in GEGL).

The threshold parameter establishes the exact value cutoff:

  • Any pixel with an intensity or alpha value above the threshold is treated as solid obstacle/source geometry.
  • Any pixel below the threshold is treated as empty space across which distance is calculated.

How Threshold Alters Gradient Radius

Because the gradient radius measures the distance outward (or inward) from the detected boundary, moving the boundary directly alters the visible spread of the gradient.

  1. Expanding the Source (Lower Threshold): Lowering the threshold forces faint, semi-transparent pixels on soft edges to be classified as part of the source object. This physically expands the detected perimeter outward. As a result, outward distance gradients begin further away from the object's visual core, expanding the exterior reach of the gradient while shrinking any inward gradients.

  2. Shrinking the Source (Higher Threshold): Increasing the threshold requires pixels to be much denser or brighter to be considered part of the shape. Soft edges are discarded as empty space, effectively eroding the geometry. This contracts the detected perimeter inward, causing outward distance gradients to start closer to the center and inward gradients to terminate sooner.

  3. Steepness and Perceived Radius: The Distance Map calculates distances linearly up to a specified maximum value. While the mathematical slope of the distance calculation remains constant per pixel, the spatial placement of that ramp shifts based on the threshold. On shapes with shallow, gradual opacity fades, a slight adjustment to the threshold produces a large shift in the starting point of the gradient, noticeably stretching or compressing the visible radius of the distance field.

Practical Application

To maintain an accurate, predictable gradient radius:

  • For crisp, hard-edged shapes: The threshold has minimal impact on the gradient radius because the boundary does not contain intermediate values.
  • For blurred, feathered, or soft-edged shapes: Set the threshold to 0.5 (or mid-gray) for a balanced representation of the visual boundary. Lower the threshold if you need the gradient radius to encapsulate subtle glows or transparent fringes, or raise it to isolate only the fully opaque core before generating the distance falloff.