GeminiWM

How Reverse Alpha Blending Works: The Math Behind Gemini Watermark Removal

A technical deep dive into reverse alpha blending — the lossless mathematical technique used to remove Gemini's visible watermark by reversing the compositing formula.

When Google applies the visible sparkle watermark to a Gemini-generated image, it uses a standard compositing technique called alpha blending. Because this operation is mathematically simple and fully deterministic, it can be run in reverse to recover the original pixel values. This article explains exactly how that works — the formulas, a worked example, the code, and the limitations.

Alpha Compositing: The Forward Operation

Alpha compositing is how nearly all transparency in computer graphics works. When you place a semi-transparent layer on top of an image, each pixel in the result is calculated as:

C_result = C_source * alpha + C_destination * (1 - alpha)

Where:

  • C_result is the final pixel color you see
  • C_source is the watermark pixel color
  • C_destination is the original image pixel color (what was there before the watermark)
  • alpha is the watermark’s opacity at that pixel (0 = fully transparent, 1 = fully opaque)

This formula runs independently for each color channel (red, green, blue) at each pixel position in the watermark region. Pixels outside the watermark region are untouched.

For the Gemini sparkle watermark, C_source and alpha are constants — the same sparkle image with the same transparency values is applied to every generated image. The only variable is C_destination, which is whatever your original image had in the bottom-right corner.

The Reverse: Solving for the Original

Since we know C_result (the watermarked image we received), C_source (the sparkle graphic), and alpha (the sparkle’s transparency at each pixel), we can solve for C_destination — the original pixel value before the watermark was applied.

Rearranging the alpha compositing formula:

C_result = C_source * alpha + C_destination * (1 - alpha)
C_result - C_source * alpha = C_destination * (1 - alpha)
C_destination = (C_result - C_source * alpha) / (1 - alpha)

That is the complete reverse alpha blending formula:

original = (watermarked - watermark_color * alpha) / (1 - alpha)

There is no machine learning here. No neural network. No approximation. It is algebra — the same kind you learned in school, applied to each pixel independently.

A Worked Example

Let us trace through a single pixel to see the numbers. Suppose the original image had a pixel with red value 180 in the bottom-right corner, and the watermark pixel at that position has a red value of 255 (white) with an alpha of 0.3.

Forward (applying the watermark):

C_result = 255 * 0.3 + 180 * (1 - 0.3)
C_result = 76.5 + 126.0
C_result = 202.5

Since pixel values are integers (0-255), this gets rounded to 203. This is the value stored in the watermarked image you receive from Gemini.

Reverse (removing the watermark):

C_destination = (203 - 255 * 0.3) / (1 - 0.3)
C_destination = (203 - 76.5) / 0.7
C_destination = 126.5 / 0.7
C_destination = 180.71

Rounded to the nearest integer: 181. The original was 180. That is the +-1 rounding error in action — one round of integer truncation during the forward pass means we sometimes land one value off when reversing. Over an entire image, this produces zero visible difference.

Where Alpha Is Zero

One important edge case: where the watermark’s alpha is 0 (fully transparent pixels), the formula would require division by 1, which works fine — but more importantly, those pixels were never modified in the first place. When alpha is 0:

C_result = C_source * 0 + C_destination * 1 = C_destination

The original pixel passes through unchanged. No reversal is needed. In the watermark region, most pixels are fully transparent — the sparkle graphic is mostly empty space. Only the pixels that form the actual sparkle shape have non-zero alpha values and need to be reversed.

The Code in Practice

Here is what the pixel manipulation loop looks like conceptually. GeminiWM runs this in the browser using HTML Canvas:

// For each pixel in the watermark region
for (let i = 0; i < watermarkRegion.length; i += 4) {
  const alpha = watermarkPixels[i + 3] / 255; // Normalize alpha to 0-1

  if (alpha === 0) continue; // Pixel was not modified, skip it

  // Reverse alpha blend for each color channel (R, G, B)
  for (let c = 0; c < 3; c++) {
    const result = imagePixels[i + c];       // The watermarked value
    const source = watermarkPixels[i + c];   // The watermark color
    const original = (result - source * alpha) / (1 - alpha);

    imagePixels[i + c] = Math.round(
      Math.min(255, Math.max(0, original))
    );
  }
}

The Math.min(255, Math.max(0, ...)) clamping ensures the output stays within the valid 0-255 range for pixel values. In rare cases, rounding errors could push a value to -1 or 256, and the clamp catches those.

This entire operation runs in microseconds. There is no iteration, no optimization loop, no convergence — just one pass through the affected pixels, one arithmetic operation per channel, done.

Why the Watermark Mask Must Be Known

Reverse alpha blending requires three known values to solve for the fourth. If you do not have the exact watermark image — the precise color values and alpha at every pixel — you cannot solve the equation. You would have two unknowns (the watermark and the original) with only one equation, which is unsolvable.

This technique works for Gemini’s visible watermark specifically because:

  1. The watermark image is identical on every Gemini output
  2. It is always positioned in the same corner
  3. Its size is predictable (48x48 or 96x96 based on image dimensions)
  4. The alpha values are consistent

If Google randomized the watermark position, varied the transparency, or used a different sparkle graphic each time, reverse alpha blending would still work in theory — but you would need to determine the watermark parameters for each individual image, which is a much harder problem.

Reverse Alpha Blending vs. AI Inpainting

The alternative approach to watermark removal is AI inpainting — using a neural network to “paint over” the watermark region by guessing what the original pixels looked like based on surrounding context.

The two approaches differ fundamentally:

Reverse Alpha BlendingAI Inpainting
AccuracyMathematically exact (+-1)Approximate — the AI guesses
SpeedMicrosecondsSeconds to minutes
Quality lossNoneSome — the AI invents pixels
RequirementsKnown watermark maskJust the watermarked image
Works onKnown, fixed watermarksAny watermark or obstruction

AI inpainting is the right tool when you do not know what the watermark looks like — for example, removing a stock photo watermark that varies per provider. It is the wrong tool when you have exact knowledge of the overlay, because you are replacing a perfect mathematical solution with an approximate one.

For Gemini’s visible sparkle, reverse alpha blending is strictly superior. The watermark is known, fixed, and applied with a standard compositing formula. There is no reason to involve a neural network when arithmetic gives you a perfect answer.

The Precision Question

Is reverse alpha blending truly lossless? Almost. The +-1 rounding error per channel per pixel is real, and in the strictest sense, the output is not bit-identical to the pre-watermark image. But consider the scale: a potential 1/255 (0.4%) deviation in some color channels of some pixels in a small region of the image. No human eye can detect this. No image quality metric will flag it. For all practical purposes, it is lossless.

The important contrast is with SynthID, Google’s invisible watermark. SynthID cannot be reversed with this technique because it is not applied via alpha compositing — it is woven into the image at generation time across every pixel. The visible sparkle and SynthID are two completely different watermarks requiring completely different approaches, and only the visible one has a clean mathematical solution.

Frequently Asked Questions

Is reverse alpha blending lossless?
Nearly. There can be a +-1 pixel rounding error due to integer precision, but the result is visually identical to the original. No information is destroyed — the math precisely reverses the compositing.
Why doesn't this work for all watermarks?
Reverse alpha blending requires knowing the exact watermark pattern and alpha values. This works for Gemini because the watermark is identical on every image. For unknown or dynamic watermarks, AI inpainting is needed instead.

Ready to remove your Gemini watermarks?

Free, lossless, and 100% private. Your images never leave your browser.

Try GeminiWM Free