An Open Source, MIT licensed implementation of TrustMark watemarking for the Content Authenticity Initiative (CAI) as described in:
TrustMark - Universal Watermarking for Arbitrary Resolution Images
https://arxiv.org/abs/2311.18297
Tu Bui 1, Shruti Agarwal 2 , John Collomosse 1,2
1 DECaDE Centre for the Decentralized Digital Economy, University of Surrey, UK.
2 Adobe Research, San Jose CA.
This repo contains a Python (v3.8.5 or greater) implementation (python/
) and a browser deployable Javascript (js/
) implementation of TrustMark for encoding, decoding and removing image watermarks. In addition, a C2PA (c2pa/
) example is provided to demonstrate signing of a watermarked image using the CAI supplied python library for C2PA / Content Credentials.
Within the python folder run pip install .
The TrustMark package is also available via PyPi - run pip install trustmark
to install it indepedent of this repo.
The python/test.py
script provides examples of watermarking images (a JPEG and a transparent PNG image are provided as examples). To test the installation the following code snippet in Python shows typical usage:
from trustmark import TrustMark
from PIL import Image
# init
tm=TrustMark(verbose=True, model_type='Q')
# encoding example
cover = Image.open('ufo_240.jpg').convert('RGB')
tm.encode(cover, 'mysecret').save('ufo_240_Q.png')
# decoding example
cover = Image.open('ufo_240_Q.png').convert('RGB')
wm_secret, wm_present, wm_schema = tm.decode(cover)
if wm_present:
print(f'Extracted secret: {wm_secret}')
else:
print('No watermark detected')
# removal example
stego = Image.open('ufo_240_Q.png').convert('RGB')
im_recover = tm.remove_watermark(stego)
im_recover.save('recovered.png')
Models are now fetched on first use, due to the size and number of model variants
If you find this work useful we request you please cite the repo and/or TrustMark paper as follows.
@article{trustmark,
title={Trustmark: Universal Watermarking for Arbitrary Resolution Images},
author={Bui, Tu and Agarwal, Shruti and Collomosse, John},
journal = {ArXiv e-prints},
archivePrefix = "arXiv",
eprint = {2311.18297},
year = 2013,
month = nov
}