trustmark


Nametrustmark JSON
Version 0.7.0 PyPI version JSON
download
home_pagehttps://github.com/adobe/trustmark
SummaryTrustMark: Universal Watermarking for Arbitrary Resolution Images
upload_time2024-08-19 21:50:21
maintainerNone
docs_urlNone
authorJohn Collomosse
requires_python>=3.8.5
licenseCopyright 2023 Adobe All Rights Reserved. NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms of the license agreement accompanying it. MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords watermarking cai watermark content authenticity initiative provenance
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # TrustMark - Universal Watermarking for Arbitrary Resolution Images

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](https://www.surrey.ac.uk/people/tu-bui) <sup>1</sup>, [Shruti Agarwal](https://research.adobe.com/person/shruti-agarwal/)  <sup>2</sup> , [John Collomosse](https://www.collomosse.com)  <sup>1,2</sup> 

<sup>1</sup> DECaDE Centre for the Decentralized Digital Economy, University of Surrey, UK. \
<sup>2</sup> Adobe Research, San Jose CA.


This repo contains a Python (3.8.5 or higher) implementation of TrustMark for  encoding, decoding and removing image watermarks.  


### Quick start 

Within the python folder run `pip install .` \

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:

```python
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')
```


### TrustMark Models

Models are now fetched on first use, due to the number of variants and size of models they are not packaged as binary any more.

We recommend use of the Q (quality) model variant.  Other variants are packaged for historial / academic paper reproduction purposes but exhibit a lower PSNR.

### CUDA troubleshoot

The following clean install should work for getting up and running on GPU using the python implementation in this repo.

```
conda create --name trustmark python=3.10
conda activate trustmark
conda install pytorch cudatoolkit=12.8 -c pytorch -c conda-forge
pip install torch==2.1.2 torchvision==0.16.2 -f https://download.pytorch.org/whl/torch_stable.html
pip install .
```

### TrustMark Data Schema

Packaged TrustMark models/code are trained to encode a payload of 100 bits.  

To promote interoperability we recommend following the data schema implemented in `python/datalayer`.  This affords for a user selectable level of error correction over the raw 100 bits of payload.

#### Supported modes

* `Encoding.BCH_5` - Protected payload of 61 bits (+ 35 ECC bits) - allows for 5 bit flips.
* `Encoding.BCH_4` - Protected payload of 68 bits (+ 28 ECC bits) - allows for 4 bit flips.
* `Encoding.BCH_3` - Protected payload of 75 bits (+ 21 ECC bits) - allows for 3 bit flips.
* `Encoding.BCH_SUPER` - Protected payload of 40 bits (+ 56 ECC bits) - allows for 8 bit flips.

For example instantiate the encoder as:
```
tm=TrustMark(verbose=True, model_type='Q', encoding_type=TrustMark.Encoding.BCH_5)
```

The decoder will automatically detect the data schema in a given TrustMark, allowing for user selectable level of robustness.

#### Payload encoding

The raw 100 bits break down into D+E+V=100 bits, where D is the protect payload (e.g. 61) and E are the error correction parity bits (e.g. 35) and V are the version bits (always 4). The version bits comprise 2 reserved (unused) bits, and 2 bits encoding an integer in range 0-3 which indicate the trustmark data schema in use (see `python/datalayer.py` for the numeric codes).

### Usage with C2PA

TrustMark may be used to directly encode a 'soft binding' identifier, which may be used to look up provenace metadata (manifest). This identifier should be encoded via one of the Encoding types BCH_n described above.

TrustMark may alternatively be used to indicate the presence of another watermarking technology that carries an identifier.  In this mode the encoding should be Encoding.BCH_SUPER and the payload contain an integer identifer that describes the co-present watermarking technology.  This value should be taken from the C2PA Soft Binding Algorithm List.

An example of direct encoding for C2PA is included in `c2pa/c2pa_watermark_example.py` including the C2PA manifest that should be used to describe the watermark insertion.

## Citation

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 = 2023,
  month = nov
}
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/adobe/trustmark",
    "name": "trustmark",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8.5",
    "maintainer_email": "John Collomosse <collomos@adobe.com>",
    "keywords": "watermarking, CAI, watermark, Content Authenticity Initiative, provenance",
    "author": "John Collomosse",
    "author_email": "Shruti Agarwal <shragarw@adobe.com>, John Collomosse <collomos@adobe.com>",
    "download_url": "https://files.pythonhosted.org/packages/16/4d/d3d1ce6480d840aa3b991c66d3c923ee3cb4539ce47e9cb30b879c7dbc6b/trustmark-0.7.0.tar.gz",
    "platform": null,
    "description": "# TrustMark - Universal Watermarking for Arbitrary Resolution Images\n\nAn Open Source, MIT licensed implementation of TrustMark watemarking for the Content Authenticity Initiative (CAI) as described in: \n\n**TrustMark - Universal Watermarking for Arbitrary Resolution Images**\n\nhttps://arxiv.org/abs/2311.18297 \n\n[Tu Bui](https://www.surrey.ac.uk/people/tu-bui) <sup>1</sup>, [Shruti Agarwal](https://research.adobe.com/person/shruti-agarwal/)  <sup>2</sup> , [John Collomosse](https://www.collomosse.com)  <sup>1,2</sup> \n\n<sup>1</sup> DECaDE Centre for the Decentralized Digital Economy, University of Surrey, UK. \\\n<sup>2</sup> Adobe Research, San Jose CA.\n\n\nThis repo contains a Python (3.8.5 or higher) implementation of TrustMark for  encoding, decoding and removing image watermarks.  \n\n\n### Quick start \n\nWithin the python folder run `pip install .` \\\n\nThe `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:\n\n```python\nfrom trustmark import TrustMark\nfrom PIL import Image\n\n# init\ntm=TrustMark(verbose=True, model_type='Q')\n\n# encoding example\ncover = Image.open('ufo_240.jpg').convert('RGB')\ntm.encode(cover, 'mysecret').save('ufo_240_Q.png')\n\n# decoding example\ncover = Image.open('ufo_240_Q.png').convert('RGB')\nwm_secret, wm_present, wm_schema = tm.decode(cover)\nif wm_present:\n  print(f'Extracted secret: {wm_secret}')\nelse:\n  print('No watermark detected')\n\n# removal example\nstego = Image.open('ufo_240_Q.png').convert('RGB')\nim_recover = tm.remove_watermark(stego)\nim_recover.save('recovered.png')\n```\n\n\n### TrustMark Models\n\nModels are now fetched on first use, due to the number of variants and size of models they are not packaged as binary any more.\n\nWe recommend use of the Q (quality) model variant.  Other variants are packaged for historial / academic paper reproduction purposes but exhibit a lower PSNR.\n\n### CUDA troubleshoot\n\nThe following clean install should work for getting up and running on GPU using the python implementation in this repo.\n\n```\nconda create --name trustmark python=3.10\nconda activate trustmark\nconda install pytorch cudatoolkit=12.8 -c pytorch -c conda-forge\npip install torch==2.1.2 torchvision==0.16.2 -f https://download.pytorch.org/whl/torch_stable.html\npip install .\n```\n\n### TrustMark Data Schema\n\nPackaged TrustMark models/code are trained to encode a payload of 100 bits.  \n\nTo promote interoperability we recommend following the data schema implemented in `python/datalayer`.  This affords for a user selectable level of error correction over the raw 100 bits of payload.\n\n#### Supported modes\n\n* `Encoding.BCH_5` - Protected payload of 61 bits (+ 35 ECC bits) - allows for 5 bit flips.\n* `Encoding.BCH_4` - Protected payload of 68 bits (+ 28 ECC bits) - allows for 4 bit flips.\n* `Encoding.BCH_3` - Protected payload of 75 bits (+ 21 ECC bits) - allows for 3 bit flips.\n* `Encoding.BCH_SUPER` - Protected payload of 40 bits (+ 56 ECC bits) - allows for 8 bit flips.\n\nFor example instantiate the encoder as:\n```\ntm=TrustMark(verbose=True, model_type='Q', encoding_type=TrustMark.Encoding.BCH_5)\n```\n\nThe decoder will automatically detect the data schema in a given TrustMark, allowing for user selectable level of robustness.\n\n#### Payload encoding\n\nThe raw 100 bits break down into D+E+V=100 bits, where D is the protect payload (e.g. 61) and E are the error correction parity bits (e.g. 35) and V are the version bits (always 4). The version bits comprise 2 reserved (unused) bits, and 2 bits encoding an integer in range 0-3 which indicate the trustmark data schema in use (see `python/datalayer.py` for the numeric codes).\n\n### Usage with C2PA\n\nTrustMark may be used to directly encode a 'soft binding' identifier, which may be used to look up provenace metadata (manifest). This identifier should be encoded via one of the Encoding types BCH_n described above.\n\nTrustMark may alternatively be used to indicate the presence of another watermarking technology that carries an identifier.  In this mode the encoding should be Encoding.BCH_SUPER and the payload contain an integer identifer that describes the co-present watermarking technology.  This value should be taken from the C2PA Soft Binding Algorithm List.\n\nAn example of direct encoding for C2PA is included in `c2pa/c2pa_watermark_example.py` including the C2PA manifest that should be used to describe the watermark insertion.\n\n## Citation\n\nIf you find this work useful we request you please cite the repo and/or TrustMark paper as follows.\n\n```\n@article{trustmark,\n  title={Trustmark: Universal Watermarking for Arbitrary Resolution Images},\n  author={Bui, Tu and Agarwal, Shruti and Collomosse, John},\n  journal = {ArXiv e-prints},\n  archivePrefix = \"arXiv\",\n  eprint = {2311.18297},\n  year = 2023,\n  month = nov\n}\n```\n\n\n",
    "bugtrack_url": null,
    "license": "Copyright 2023 Adobe All Rights Reserved.  NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms of the license agreement accompanying it.  MIT License  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "TrustMark: Universal Watermarking for Arbitrary Resolution Images",
    "version": "0.7.0",
    "project_urls": {
        "Homepage": "https://github.com/adobe/trustmark",
        "Repository": "https://github.com/adobe/trustmark.git"
    },
    "split_keywords": [
        "watermarking",
        " cai",
        " watermark",
        " content authenticity initiative",
        " provenance"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "164dd3d1ce6480d840aa3b991c66d3c923ee3cb4539ce47e9cb30b879c7dbc6b",
                "md5": "15b576bfb0ca9380cefbd0f16db4f6b1",
                "sha256": "5373bb94ea7bee203a7acc94edf8770bed0592ea8324ae5aa134b544ff26fac7"
            },
            "downloads": -1,
            "filename": "trustmark-0.7.0.tar.gz",
            "has_sig": false,
            "md5_digest": "15b576bfb0ca9380cefbd0f16db4f6b1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.5",
            "size": 33497,
            "upload_time": "2024-08-19T21:50:21",
            "upload_time_iso_8601": "2024-08-19T21:50:21.632853Z",
            "url": "https://files.pythonhosted.org/packages/16/4d/d3d1ce6480d840aa3b991c66d3c923ee3cb4539ce47e9cb30b879c7dbc6b/trustmark-0.7.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-19 21:50:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "adobe",
    "github_project": "trustmark",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "trustmark"
}
        
Elapsed time: 0.33384s