ImageWatermarkerBase<T>

Base Classes · AiDotNet.Safety.Watermarking

Abstract base class for keyed image watermarkers: each adds a pseudo-random pattern derived from a secret key to a transform of the image, and detects it by correlating the same transform against the same pattern.

Inheritance: ModelBase<T, Vector<T>, Vector<T>> → SafetyModuleBase<T> → ImageSafetyModuleBase<T> → ImageWatermarkerBase<T>

Implements: IImageWatermarker<T>, IKeyedWatermarker

Known derived types: FrequencyImageWatermarker<T>, InvisibleImageWatermarker<T>

For Beginners

the key works like a password. Only someone with the same key can tell the watermark is there. The watermark is spread thinly over many coefficients, so it is invisible in any one place but adds up to a strong signal when you know exactly what pattern to look for.

How It Works

The watermark is computed on the image’s luminance (the mean over channels) and the same spatial change is added to every channel. The image is split into tiles of at most MaxTileSize pixels per side, and each tile carries its own pattern, so the cost grows linearly with the pixel count and averaging tiles reveals nothing. Embedding rejects images above MaxPixels pixels; detection reports no evidence for them, so a safety pipeline that checks a huge image still completes.

Detection is a correlation test over every tile: with the selected transform coefficients c and the key’s pattern x, z = sum(c_k * x_k) / sqrt(sum(c_k^2)). Without the watermark, or with a different key, z is approximately standard normal; with it, z grows with the strength and with the number of coefficients. DetectWatermark maps z to a confidence: 0 up to z = 3 (a one-sided false-positive rate near 0.1%), rising linearly to 1 at z = 6. EvaluateImage reports a finding from ReportThreshold (by default confidence 0.3, z = 3.9).

The pattern is derived with HMAC-SHA256 from the key, so the key is the whole secret. The default, PublicKey, is published here: anyone can reproduce, and therefore forge, a mark made with it. Use a long random key of your own (for example 32 random bytes in base64) to mark content as yours.

The embedded amplitude per coefficient is the strength times the larger of the coefficients’ robust spread and 2% of the image’s value range, so smooth images still receive a watermark that survives mild noise.

Properties

Property Summary
bool UsesPublicKey { get; } Whether the watermarker uses the published PublicKey.

Methods

Method Summary
IReadOnlyList<SafetyFinding> EvaluateImage(Tensor<T> image)
Tensor<T> EmbedWatermark(Tensor<T> image)
double DetectWatermark(Tensor<T> image)

Fields

Field Summary
int MaxTileSize The largest tile side, in pixels; larger images are watermarked tile by tile.
string PublicKey The key used when none is given.