Coefficient-Aware Global Assignment for Robust Latent-DCT Watermarking in Stable Diffusion
Chakkratorn Kwakhong*, Department of Computer Science, Kasetsart University
Bangkok, Thailand, chakkratorn.k@ku.th
Chien-Chang Chen*, Department of Computer Science and Information Engineering, Tamkang University
New Taipei CIty, Taiwan, ccchen34@mail.tku.edu.tw
Cheng-Hsiu Li*, Department of Computer Science and Information Engineering, Tamkang University
New Taipei CIty, Taiwan, bensonjobjob@gmail.com
Somchoke Ruengittinun*, Department of Computer Science, Kaetsart University
Bangkok, Thailand, somchoke.r@gmail.com
Worasait Suwannik*, Department of Computer Science, Kasetsart Universiy
Bangkok, Thailand, worasait.suwannik@gmail.com
* Corresponding author
Abstract — Images produced by latent diffusion models may circulate without ownership metadata, which can be removed during re-encoding or redistribution. Invisible watermarking provides a persistent mechanism to address this loss of provenance. However, while existing latent-DCT watermarking offers a training-free solution, it relies on a fixed embedding template and a static optimization budget. This rigidity weakens robustness against compound distortions and creates a computational bottleneck. This study evaluates whether adapting watermark placement and optimization length to the latent content of each image can overcome these limitations. Coordinate selection is formulated as a linear assignment problem over 53 candidate frequencies, paired with a matching step that assigns each payload value to its nearest resident coefficient, and a convergence-based early-stopping criterion monitors the optimization process. On 100 WikiArt images under a nine-operation compound attack, the fixed template and an assignment-only variant detect 69% and 70% of marks, respectively. Adding coefficient-aware matching raises detection to 98%. Because the exact solvers select identical positions on the evaluated dataset, this improvement is associated with the matching mechanism rather than the position assignment. The early-stopping rule reduces end-to-end runtime by 10.6–11.6% while detection under the same compound attack changes from 98% to 97% and mixed-image SSIM remains at 0.92. Together, these findings show that post-generation watermarking can reduce processing time while retaining the robustness gained through coefficient-aware matching. By replacing fixed placement and refinement beyond convergence, the resulting pipeline offers a more efficient route to ownership verification for images that already exist.
Keywords — Digital Watermarking, Stable Diffusion, Discrete Cosine Transform, Linear Assignment, Copyright Protection
I. Introduction
The rapid adoption of latent diffusion models [1] has re-duced the time and technical effort needed to create visual con-tent. Independent creators and small studios can now produce and distribute large image collections without maintaining a conventional production pipeline. Once an image leaves its original platform, however, prompts, account records, and metadata may be removed during conversion, redistribution, or editing. The creator may then have little evidence connecting the distributed file to its source. Invisible digital watermarking addresses this problem by embedding ownership information into the image itself [2], where it can remain recoverable after distribution and common image processing.
Current diffusion watermarking methods do not fully ad-dress this setting. Methods that train or fine-tune water-marking components require data, computing resources, and deployment effort that may be impractical for smaller orga-nizations. Training-free methods remove this requirement but can introduce another restriction. Tree-Rings [3] modifies the initial diffusion noise in the Fourier domain, while Gaussian Shading [4] encodes the payload into a Gaussian latent before sampling. Both methods leave the model weights unchanged, but they require access to the generation process. They can protect images produced through a controlled generator but cannot directly watermark images that already exist. This leaves a practical need for a method that can protect existing image collections without retraining or modifying the diffusion model.
Frozen-model latent watermarking provides a post-generation approach to this problem. DDIM inversion [5] maps an existing image into the latent space of Stable Diffusion. A block-based discrete cosine transform exposes latent-frequency coefficients in which a copyright-dependent payload can be embedded. Adam optimization [6] then refines the modified latent to recover visual fidelity, and statistical testing determines whether the corresponding watermark is present [7]–[9]. The model weights remain frozen through-out the process. However, the conventional implementation assigns every payload to the same mid-frequency coefficient template and applies a fixed 60-step optimization budget to every image. Latent coefficients vary with image content and inversion trajectories, so a fixed position may require a small modification in one image and a much larger modification in another. Optimization loss also stabilizes at different rates, yet the fixed budget continues processing even when further refinement produces little improvement. These choices can weaken watermark recovery after cumulative processing and increase the cost of protecting large image collections.
This study examines whether both stages can be adapted to the latent content of each image. Embedding positions are selected from the available coefficients rather than imposed by a fixed template, and payload values are matched to coefficients that require smaller modifications. The resulting correspondence is retained with the per-image ownership record and reused during verification. A convergence-based early-stopping criterion monitors the optimization process and
terminates refinement after the loss has stabilized. The evalu-ation compares the adaptive approach with conventional fixed embedding and measures image quality, watermark detection after individual and compound processing, and computation time. This design separates the effect of content-aware em-bedding from the effect of reducing the optimization budget without introducing model retraining.
choose the set minimizing total embedding displacement for the image at hand. Let C̄(pᵢ) be the mean coefficient at candidate position pᵢ across the 64 blocks. With embedding strength δ, the assignment cost is
(4)
and the resulting objective is
The experiments show that coefficient-payload assignment improves watermark recovery.
(5)
Under compound non-geometric processing, the fixed template is less reliable. The convergence-based criterion completes refinement in fewer iterations while preserving the robustness obtained through adaptive embedding. The results therefore indicate that processing time can be reduced without losing the watermark’s resistance to cumulative image operations. This extends the original frozen-model pipeline into a more efficient post-generation system for protecting existing images.
II. Methodology
DCT Transform
Figure 1 shows the overall framework. Section III summa-rizes the embedding and detection procedure of [8], [9], which is the baseline for the position-selection method proposed in this work. The payload occupies the fourth latent channel alone, which is partitioned into 64 disjoint tiles of 8 × 8 samples, each carried into the frequency domain by the two-
dimensional DCT [10]:
(1)
where π is injective so no coordinate receives two entries.
Selecting five of the 53 coordinates with minimum total cost forms a rectangular linear assignment problem with an exact polynomial-time solution. The Hungarian method [12] finds it at O(n3); Jonker–Volgenant [13] reaches the same optimum along shortest augmenting paths and scales better. Both are exact, so they return the same coordinates apart from ties; on the benchmark used here, the two solvers selected identical coordinates for every image. Choosing where to write leaves open what to write there.
Direct embedding takes values in generated order, so a slot may receive one far from the resident coefficient, which forces the optimizer to induce substantial pixel-space displacement. Coefficient-aware matching instead scans the unused values and picks the closest,
(6)
for slot j, exchanging entries j and rj before writing.
with for w > 0.
All subsequent operations act on the 64 transformed tiles, never on pixels.
The embedded payload derives from the owner’s copyright image. SHAKE256 [11] turns it into a byte stream that is deterministic in the image, so whoever later claims ownership can reproduce it. Each byte is rescaled onto a 256-level lattice,
(2)
and pushed through the inverse standard normal CDF,
(3)
Matching changes payload ordering but alters neither the selected coordinates nor the total capacity. Hungarian-Direct and JV-Coefficient-Matched solve the same assignment problem with exact solvers, and only JV-Coefficient-Matched applies payload matching. Any detection difference between them therefore cannot be attributed to the solver alone.
Figure 1. Fig. 1. Overview of the latent-DCT watermarking and verification framework, adapted from [8], [9], with global position assignment and coefficient-aware payload matching as the evaluated extensions. Preprocessing encodes the input image and applies DDIM inversion. Embedding applies a block DCT to the fourth latent channel, selects coordinates by global position assignment, adds the SHAKE256-derived payload, and restores fidelity with Adam under MSE, SSIM, and VGG losses. Verification re-encodes and re-inverts the image under test, reads the stored coordinates, and returns a p-value.
III. WATERMARK EMBEDDING AND DETECTION
A. Watermark Embedding and Optimization
Each block is written at the five selected coordinates by C′ᵦ(pₖ) = δw_idx(b,k), after which an inverse DCT returns the modified latent. Overwriting coefficients alone leaves visible traces, so this study uses Adam with three losses over 60 iterations. Mean squared error controls pixel difference.
the structural similarity loss [14] maintains visual similarity and prevents color shift and blurring,
(8)
and the VGG loss keeps semantics aligned, focusing on high-level content including texture.
where ϕl is the activation of layer l of a pretrained VGG network [15] and ClHlWl its size. These are combined.
with sequentially adapted weights as Lₜ = λₘ(t)L_MSE + λₛ(t)L_SSIM + λᵥ(t)L_VGG, and the selected coefficients are projected back to their targets after every iteration.
The stopping rule smooths this objective with an exponential moving average,
(10)
and monitors its relative decrease,
(11)
We refer to this convergence criterion as Relative-EMA. Optimization halts at the first t ≥ tmin for which ρτ < ϵrel across the window τ ∈ {t − W + 1, . . . , t}. We use W = 5, ϵrel = 5 × 10−3 and tmin = 15, and report the last iteration of the qualifying window. Smoothing distinguishes this rule from a threshold on the raw loss, which fires on single noisy iterations.
The decoded result is then mixed with the original in pixel space by binary search on a mixing weight until the final SSIM reaches 0.92, fixing one quality budget across configurations so robustness cannot be traded against fidelity.
B. Detection
Verification is non-blind, as the right panel of Figure 1 shows: the test image is encoded, inverted, and transformed by block DCT, and the stored coordinates give observed coefficients cˆi. With s2 the estimated coefficient variance, the statistic is the squared distance to the targets,
(12)
A marked image has been pushed toward those targets, so T
is small; an unmarked one holds coefficients unrelated to the
key, so T is large. Formally T is approximately central χ2 with
k = 320 degrees of freedom when the mark is present and noncentral χ² with λ = s⁻²Σᵢ(δwᵢ)² when it is absent, so the
test is one-sided on the lower tail and a watermark is declared
when p = Fχ′2 (T ; k, λ) ≤ 0.1. Since λ sums the realised payload rather than assuming unit variance, the quantization above shifts λ to its correct value instead of invalidating the reference. Under direct embedding the reference vector is
reconstructible from the secret key alone. Under coefficient-aware matching it is the reordered payload, so the permutation must be stored and supplied at verification, an overhead of at most log2(320!) ≈ 2207 bits, about 276 bytes per image.
A. Experimental Setup
Experiments use Stable Diffusion 2.1-base on an NVIDIA RTX 4090 (24 GB) under Ubuntu 24.04 and CUDA 13.0, over
100 WikiArt images at 512 × 512. Every configuration shares the payload length, embedding channel, 60-iteration baseline budget, threshold p ≤ 0.1, and final mixed SSIM of 0.92, and each runs at the full budget and again under the convergence-
based early stopping (Relative-EMA) rule.
Twelve attack conditions are applied: diffusion purification [16], two learned compressors [17], [18], JPEG at quality 50, brightness and contrast reduction, Gaussian noise (σn = 0.05), Gaussian blur, BM3D denoising [19], a 90◦ rotation, and two compound attacks, all norot applying the nine non-geometric operations in sequence and all adding rotation. Every result was re-scored from its raw chi-squared output at p ≤ 0.1,
n = 100, and reported time is the full pipeline wall clock per
image.
B. Detection Rate and Robustness
Table I reports the results. Any single non-geometric attack leaves every configuration detecting 98–100% of images, so single attacks separate nothing and the comparison rests on what happens when distortions accumulate.
Under all norot the fixed template detects 69% of images and global assignment alone reaches 70%: solving (5) relo-cates the coordinates but leaves the displacement at each write unchanged, since its cost is a mean over 64 blocks and so optimizes a summary statistic rather than the coefficient each write meets. Adding coefficient-aware ordering on the same coordinates raises detection to 98%, 28 points above global assignment alone and 29 above the fixed baseline. Equation (6) explains why: the displacement is minimized at every write rather than fixed by sequence position, so the residual signal falls inside the frequency statistics the image already had, which cumulative processing perturbs less than a signal forced into an unfavorable block.
The improvement belongs to the complete matching-based configuration, not to the JV solver. Across both budgets JV stays at 97–98% against 69–73% for the direct configurations, while average detection rises only from 82.0% to 83.9% because single attacks are already saturated, and pre-mixing PSNR is 23.38 dB against 23.10 dB. Origin false positives read 11% for Fixed-Direct and 6% for the assignment-based configurations, though negative-image calibration under the stored-permutation protocol would be needed before treating that as a deployment property. Rotation defeats all three, at 5–10% detection, because a quarter turn moves the block grid so the stored coordinates no longer index the coefficients carrying the payload.
C. Effect of Early Stopping
The lower block of Table I addresses the computational bottleneck. Figure 2 shows that the mean objective de-creases rapidly during the first ten iterations, begins to flatten near iteration 25, and improves only slightly thereafter. The convergence-based rule stops at an average of 49.4 iterations for Fixed, 50.1 for Hungarian, and 50.3 for JV-Coefficient-Matched.
As shown in Figure 3, the overall runtime reduction is limited because early stopping affects only the Adam opti-mization stage, while the remaining pipeline components are
Fig. 2. Mean total loss over 100 images. Dashed lines mark the mean stopping iteration chosen by (10)–(11): 49.4 Fixed, 50.1 Hungarian, 50.3 JV.
Fig. 3. Execution time breakdown per image. The convergence-based early stopping (Relative-EMA) reduces the Adam optimization phase across all con-figurations, while components outside the optimization loop remain constant. End-to-end runtime falls by 10.6–11.6%.
unchanged. Runtime decreases from 60.0 to 53.2 s for Fixed, from 59.4 to 53.1 s for Hungarian, and from 61.3 to 54.2 s for JV-Coefficient-Matched. These changes correspond to end-to-end reductions of 11.3%, 10.6%, and 11.6%, respectively.
Robustness is maintained under early stopping. Compound non-geometric detection changes from 69% to 73% for Fixed, from 70% to 69% for Hungarian, and from 98% to 97% for JV-Coefficient-Matched. Average detection changes by no more than 0.8 percentage points across all configurations. Pre-mixing PSNR decreases by 0.57-0.71 dB, but the subsequent mixing search holds the final SSIM at 0.92 for every config-uration.
Figure 4 shows representative final outputs after the mixing stage. Because the mixing search uses the same SSIM target regardless of the stopping iteration, the outputs under the two optimization budgets remain visually similar. Under the tested attacks and fixed-SSIM condition, the optimization can therefore stop earlier without reducing the robustness obtained from coefficient-aware payload matching.
Figure 2. Fig. 2. Mean total loss over 100 images. Dashed lines mark the mean stopping iteration chosen by (10)–(11): 49.4 Fixed, 50.1 Hungarian, 50.3 JV.Figure 3. Execution time breakdown per image. The convergence-based early stopping (Relative-EMA) reduces the Adam optimization phase across all con-figurations, while components outside the optimization loop remain constant. End-to-end runtime falls by 10.6–11.6%.Figure 4. Final watermarked output for one representative image, under both budgets. PSNR is measured after mixing, against the original at the left, and is therefore higher than the pre-mixing values in Table I.
Table 1. Table 1. DETECTION RATE, IMAGE QUALITY, AND RUNTIME ON 100 WIKIART IMAGES, RE-SCORED AT p ≤ 0.1
Configuration
Position rule
Avg. 12 (%)
all norot (%)
all (%)
rotate 90 (%)
FP (%)
PSNR (dB)
Time (s)
Baseline, full 60-iteration budget
Fixed-Direct [8], [9]
predetermined
82.0
69
9
7
11
23.10
60.0
Hungarian-Direct
global assignment
82.2
70
7
9
6
23.05
59.4
JV-Coefficient-Matched global assignment
global assignment
83.9
98
4
5
6
23.38
61.3
convergence-based
early stopping (Relative-EMA)
Fixed-Direct [8], [9]
predetermined
82.3
73
6
9
11
22.39
53.2
Hungarian-Direct
global assignment
82.1
69
6
10
6
22.44
53.1
JV-Coefficient-Matched
global assignment
84.7
97
10
9
6
22.81
54.2
V. Conclusion
This work addressed two limitations of an existing frozen-model latent-DCT watermarking pipeline: fixed embedding positions and a static optimization budget. The evaluation found that selecting positions based only on latent content offered little improvement over the fixed template under com-pound non-geometric processing. Detection increased from 69% to 70%. When payload values were matched to coef-ficients of similar magnitude, detection rose to 98%. Because the two exact assignment solvers selected identical positions across all 100 images, this result is associated with payload matching and the stored payload order rather than the position solver. Verification requires storing the reordered watermark sequence, with an upper-bound storage requirement of approx-imately 276 bytes per image.
A convergence-based early-stopping criterion reduced aver-age end-to-end runtime by approximately 11%, while detection under compound non-geometric processing changed from 98% to 97%. The final mixing stage held SSIM at 0.92 for both optimization settings. Under the evaluated conditions, the optimization process can therefore terminate earlier while retaining the robustness obtained from coefficient-aware em-bedding.
The method remains sensitive to geometric transformations, with detection falling to 5–10% under rotation. At the decision threshold of p ≤ 0.1, the recorded false-positive rates ranged from 6% to 11%, and the stored-payload procedure requires
further calibration on unwatermarked images. Future work should investigate alignment methods for geometric attacks, repeat stochastic experiments across multiple runs, and evaluate the stored payload order on larger sets of unwatermarked images.
References
[1] R. Rombach, A. Blattmann, D. Lorenz, P. Esser, and B. Ommer, “High-resolution image synthesis with latent diffusion models,” in Proc. CVPR, 2022, pp. 10684–10695.
[2] M. Barni, F. Bartolini, V. Cappellini, and A. Piva, “A DCT-domain system for robust image watermarking,” Signal Processing, vol. 66, no. 3, pp. 357–372, 1998.
[3] Y. Wen, J. Kirchenbauer, J. Geiping, and T. Goldstein, “Tree-Rings watermarks: Invisible fingerprints for diffusion images,” in Adv. Neural Inf. Process. Syst., vol. 36, 2023.
[4] Z. Yang, K. Zeng, K. Chen, H. Fang, W. Zhang, and N. Yu, “Gaussian Shading: Provable performance-lossless image watermarking for diffu-sion models,” in Proc. CVPR, 2024.
[5] J. Song, C. Meng, and S. Ermon, “Denoising diffusion implicit models,” in Proc. ICLR, 2021.
[6] D. P. Kingma and J. Ba, “Adam: A method for stochastic optimization,” in Proc. ICLR, 2015.
[7] L. Zhang, X. Liu, A. V. Martin, C. X. Bearfield, Y. Brun, and H. Guan, “Attack-resilient image watermarking using Stable Diffusion,” in Adv. Neural Inf. Process. Syst., vol. 37, 2024.
[8] C.-H. Li, “A study of Stable Diffusion model and discrete cosine transform based image watermark method,” M.S. thesis, Tamkang Univ., Taiwan, 2026.
[9] C.-C. Chen, N. Suetrong, P. Poungnil, and T. Deepentham, “Research on watermark embedding algorithm,” unpublished manuscript, 2026.
[10] N. Ahmed, T. Natarajan, and K. R. Rao, “Discrete cosine transform,” IEEE Trans. Comput., vol. C-23, no. 1, pp. 90–93, 1974.
[11] Nat. Inst. Stand. Technol., “SHA-3 standard: Permutation-based hash and extendable-output functions,” FIPS PUB 202, 2015.
[12] H. W. Kuhn, “The Hungarian method for the assignment problem,” Nav. Res. Logist. Quart., vol. 2, nos. 1–2, pp. 83–97, 1955.
[13] R. Jonker and A. Volgenant, “A shortest augmenting path algorithm for dense and sparse linear assignment problems,” Computing, vol. 38, no. 4, pp. 325–340, 1987.
[14] Z. Wang, A. C. Bovik, H. R. Sheikh, and E. P. Simoncelli, “Image quality assessment: From error visibility to structural similarity,” IEEE Trans. Image Process., vol. 13, no. 4, pp. 600–612, 2004.
[15] K. Simonyan and A. Zisserman, “Very deep convolutional networks for large-scale image recognition,” in Proc. ICLR, 2015.
[16] X. Zhao, K. Zhang, Z. Su, S. Vasan, I. Grishchenko, C. Kruegel, G. Vigna, Y.-X. Wang, and L. Li, “Invisible image watermarks are provably removable using generative AI,” in Adv. Neural Inf. Process. Syst., vol. 37, 2024.
[17] J. Balle´, D. Minnen, S. Singh, S. J. Hwang, and N. Johnston, “Variational image compression with a scale hyperprior,” in Proc. ICLR, 2018.
[18] Z. Cheng, H. Sun, M. Takeuchi, and J. Katto, “Learned image com-pression with discretized Gaussian mixture likelihoods and attention modules,” in Proc. CVPR, 2020.
[19] K. Dabov, A. Foi, V. Katkovnik, and K. Egiazarian, “Image denoising by sparse 3-D transform-domain collaborative filtering,” IEEE Trans. Image Process., vol. 16, no. 8, pp. 2080–2095, 2007.