Why GIMP Grain Extract and Merge Are Reversible

In GIMP, the Grain Extract and Grain Merge blend modes form a mathematically complementary pair that allows for non-destructive frequency separation and high-pass detail editing. By treating neutral 50% gray as a zero baseline, Grain Extract subtracts a blurred version of an image from the original to isolate high-frequency textures, while Grain Merge precisely adds those textures back to the blurred base. Because their underlying linear formulas cancel each other out, the original image can be reconstructed with bit-for-bit fidelity, provided the workflow uses high-precision floating-point color.

The Mathematics of the Blend Modes

Blend modes in digital image processing calculate resulting pixel values on a normalized scale from \(0.0\) (black) to \(1.0\) (white), where \(0.5\) represents neutral 50% gray.

1. Grain Extract Formula

When you duplicate an image layer, apply a low-pass filter (such as Gaussian Blur) to the duplicate, and set the top layer's blend mode to Grain Extract, GIMP calculates each pixel via:

\[\text{Result} = \text{Original} - \text{Blurred} + 0.5\]

  • If a pixel in the original matches the blurred base, the calculation is \(X - X + 0.5 = 0.5\) (neutral gray).
  • If a pixel is brighter than the local average, the value exceeds \(0.5\).
  • If a pixel is darker than the local average, the value drops below \(0.5\).

This produces a standard high-pass texture map centered around neutral gray.

2. Grain Merge Formula

Grain Merge reverses the offset and combines two layers using the following formula:

\[\text{Result} = \text{Layer A} + \text{Layer B} - 0.5\]

When reconstructing an image, Layer A is the extracted high-pass texture layer, and Layer B is the low-pass blurred layer.

The Algebraic Cancellation

Substituting the Grain Extract output directly into the Grain Merge equation demonstrates why the pair is lossless:

  1. Let \(I\) be the Original Image and \(B\) be the Blurred Image.
  2. The extracted high-frequency detail layer \(D\) is defined as: \[D = I - B + 0.5\]
  3. Merging \(D\) back onto \(B\) using Grain Merge yields: \[\text{Final} = D + B - 0.5\]
  4. Replace \(D\) with its extraction formula: \[\text{Final} = (I - B + 0.5) + B - 0.5\]
  5. Simplify the expression: \[\text{Final} = I - B + B + 0.5 - 0.5\] \[\text{Final} = I\]

The blurred components (\(-B + B\)) and the neutral gray offsets (\(+0.5 - 0.5\)) completely negate one another, leaving solely the original image data (\(I\)).

Why This Matters for High-Pass Detail Editing

Traditional high-pass workflows that rely on the Overlay or Soft Light blend modes do not follow perfectly linear inverses. Overlay utilizes conditional math depending on whether the underlying pixels are above or below mid-gray, leading to contrast shifts and clipping at extreme values.

Because Grain Extract and Grain Merge rely purely on linear addition and subtraction:

  • Separation of Tone and Texture: Retouchers can smooth out skin tones, color casts, or blotchiness on the low-frequency blurred layer without damaging the pores, hair, or fabric details held on the extracted layer.
  • Precise Texture Modification: Sharpening, cloning, or mitigating artifacts on the high-pass layer does not alter the underlying color balance or dynamic range of the base image.
  • Preservation with 32-bit Floating Point: In 8-bit integer mode, intermediate pixel values that dip below \(0\) or rise above \(255\) can suffer from clipping. Operating GIMP in 16-bit or 32-bit linear floating-point precision preserves values beyond the standard \([0.0, 1.0]\) boundary, ensuring that the reversibility remains absolute even in high-contrast transitions.