gemwm

package module
v0.0.0-...-f409abb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 13 Imported by: 0

README

gemwm

Go library for removing visible watermarks from Google Gemini AI-generated images.

Gemini adds a semi-transparent star (✦) watermark to the bottom-right corner of generated images. This library removes it using mathematically precise Reverse Alpha Blending — no AI, no inpainting, just math.

Note: This tool only removes the visible watermark. It does NOT remove SynthID (Google's invisible watermark).

Install

go get github.com/BlakeLiAFK/gemwm

Usage

Library
package main

import (
    "log"
    "github.com/BlakeLiAFK/gemwm"
)

func main() {
    img, _ := gemwm.LoadImage("input.png")

    // One function, that's it
    result, err := gemwm.Clean(img)
    if err != nil {
        log.Fatal(err)
    }

    if result.Detected {
        gemwm.SaveImage("output.png", result.Image)
    }
}
Options
// Force remove (skip detection)
result, _ := gemwm.Clean(img, gemwm.WithForce())

// Custom detection threshold (default: 0.35)
result, _ := gemwm.Clean(img, gemwm.WithThreshold(0.5))

// Force specific mask size (48 or 96)
result, _ := gemwm.Clean(img, gemwm.WithMaskSize(96))

// File shortcut
err := gemwm.CleanFile("input.png", "output.png")
CLI
go install github.com/BlakeLiAFK/gemwm/cmd/gemwm@latest

# Single file
gemwm photo.png -o clean.png

# Force mode
gemwm photo.png -o clean.png --force

# Batch
gemwm ./input/ -o ./output/ --batch

# Verbose
gemwm photo.png -o clean.png -v

How It Works

Gemini applies visible watermarks using alpha compositing:

watermarked = alpha * 255 + (1 - alpha) * original

We reverse the formula to recover original pixels:

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

The alpha map is pre-calibrated from known Gemini watermark templates (48x48 and 96x96).

Watermark Specs
Image Size Watermark Margin
Either dim <= 1024px 48x48 32px
Both dims > 1024px 96x96 64px
Detection

Three-stage weighted detection (NCC-based):

Stage Method Weight
Spatial NCC Pattern correlation 50%
Gradient NCC Sobel edge matching 30%
Variance Analysis Texture dampening 20%

Default threshold: 0.35

Result

type Result struct {
    Image      image.Image // Processed image
    Detected   bool        // Watermark detected
    Confidence float64     // Detection confidence (0.0-1.0)
    MaskSize   int         // Mask size used (48 or 96)
}

License

MIT

Documentation

Overview

Package gemwm 提供 Gemini 生成图片可见水印的检测与去除功能。

Gemini 在生成图片的右下角添加半透明 ✦ 四角星水印, 本库通过反向 Alpha 混合算法实现无损去除。

用法:

// 最简用法
output, err := gemwm.Clean(img)

// 强制去除(跳过检测)
output, err := gemwm.Clean(img, gemwm.WithForce())

// 文件便捷方法
err := gemwm.CleanFile("in.png", "out.png")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanFile

func CleanFile(input, output string, opts ...Option) error

CleanFile 从文件读取图片,去除水印后保存。 输出格式由 output 文件扩展名决定(支持 png/jpg)。

func LoadImage

func LoadImage(path string) (image.Image, error)

LoadImage 从文件加载图片

func SaveImage

func SaveImage(path string, img image.Image) error

SaveImage 保存图片到文件(格式由扩展名决定)

Types

type Option

type Option func(*config)

Option 配置选项

func WithForce

func WithForce() Option

WithForce 跳过水印检测,强制执行去除

func WithMaskSize

func WithMaskSize(size int) Option

WithMaskSize 强制指定 mask 尺寸,48 或 96

func WithThreshold

func WithThreshold(v float64) Option

WithThreshold 设置检测阈值 (0.0-1.0),默认 0.35

type Result

type Result struct {
	Image      image.Image // 处理后的图片
	Detected   bool        // 是否检测到水印
	Confidence float64     // 检测置信度 (0.0-1.0)
	MaskSize   int         // 使用的 mask 尺寸 (48 或 96)
}

Result 包含去除水印的结果信息

func Clean

func Clean(img image.Image, opts ...Option) (*Result, error)

Clean 检测并去除图片中的 Gemini 可见水印。 这是本库唯一的核心接口。

Directories

Path Synopsis
cmd
gemwm command
gemwm 命令行工具,去除 Gemini 生成图片的可见水印
gemwm 命令行工具,去除 Gemini 生成图片的可见水印

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL