# Technical Documentation: guofei9987/blind_watermark

> ℹ️ **Provenance:** Multi-Tier Ingestion · [CodeWiki Reference](https://codewiki.google/github.com/guofei9987/blind_watermark)

### Overview (`README.md`)

# blind-watermark

Blind watermark based on DWT-DCT-SVD.


[](https://pypi.org/project/blind_watermark/)
[](https://travis-ci.com/guofei9987/blind_watermark)
[](https://codecov.io/gh/guofei9987/blind_watermark)
[](https://github.com/guofei9987/blind_watermark/blob/master/LICENSE)


[](https://github.com/guofei9987/blind_watermark/)
[](https://github.com/guofei9987/blind_watermark/fork)
[](https://pepy.tech/project/blind-watermark)
[](https://github.com/guofei9987/blind_watermark/discussions)
<a href="https://hellogithub.com/repository/guofei9987/blind_watermark" target="_blank"><img src="https://abroad.hellogithub.com/v1/widgets/recommend.svg?rid=3834302ff46a40f188a651ef8bd26ff5&claim_uid=se0WHo8cbiLv2w1&theme=small" alt="Featured｜HelloGitHub" /></a>

- **Documentation:** [https://BlindWatermark.github.io/blind_watermark/#/en/](https://BlindWatermark.github.io/blind_watermark/#/en/)
- **文档：** [https://BlindWatermark.github.io/blind_watermark/#/zh/](https://BlindWatermark.github.io/blind_watermark/#/zh/)  
- **中文 readme** [README_cn.md](README_cn.md)
- **Source code:** [https://github.com/guofei9987/blind_watermark](https://github.com/guofei9987/blind_watermark)



# install
```bash
pip install blind-watermark
```

For the current developer version:
```bach
git clone git@github.com:guofei9987/blind_watermark.git
cd blind_watermark
pip install .
```

# How to use


## Use in bash


```bash
# embed watermark into image:
blind_watermark --embed --pwd 1234 examples/pic/ori_img.jpeg "watermark text" examples/output/embedded.png
# extract watermark from image:
blind_watermark --extract --pwd 1234 --wm_shape 111 examples/output/embedded.png
```



## Use in Python

Original Image + Watermark = Watermarked Image

 + '@guofei9987 开源万岁！' = 


See the [codes](/examples/example_str.py)

Embed watermark:
```python
from blind_watermark import WaterMark

bwm1 = WaterMark(password_img=1, password_wm=1)
bwm1.read_img('pic/ori_img.jpg')
wm = '@guofei9987 开源万岁！'
bwm1.read_wm(wm, mode='str')
bwm1.embed('output/embedded.png')
len_wm = len(bwm1.wm_bit)
print('Put down the length of wm_bit {len_wm}'.format(len_wm=len_wm))
```

Extract watermark:
```python
bwm1 = WaterMark(password_img=1, password_wm=1)
wm_extract = bwm1.extract('output/embedded.png', wm_shape=len_wm, mode='str')
print(wm_extract)
```
Output:
>@guofei9987 开源万岁！

### attacks on Watermarked Image


|attack method|image after attack|extracted watermark|
|--|--|--|
|Rotate 45 Degrees||'@guofei9987 开源万岁！'|
|Random crop||'@guofei9987 开源万岁！'|
|Masks|  |'@guofei9987 开源万岁！'|
|Vertical cut||'@guofei9987 开源万岁！'|
|Horizontal cut||'@guofei9987 开源万岁！'|
|Resize||'@guofei9987 开源万岁！'|
|Pepper Noise||'@guofei9987 开源万岁！'|
|Brightness 10% Down||'@guofei9987 开源万岁！'|






### embed images

embed watermark:
```python
from blind_watermark import WaterMark

bwm1 = WaterMark(password_wm=1, password_img=1)
# read original image
bwm1.read_img('pic/ori_img.jpg')
# read watermark
bwm1.read_wm('pic/watermark.png')
# embed
bwm1.embed('output/embedded.png')
```


Extract watermark:
```python
bwm1 = WaterMark(password_wm=1, password_img=1)
# notice that wm_shape is necessary
bwm1.extract(filename='output/embedded.png', wm_shape=(128, 128), out_wm_name='output/extracted.png', )
```


|attack method|image after attack|extracted watermark|
|--|--|--|
|Rotate 45 Degrees|||
|Random crop|||
|Mask|  ||


### embed array of bits

See it [here](/examples/example_bit.py)


As demo, we embed 6 bytes data:
```python
wm = [True, False, True, True, True, False]
```

Embed:
```python
from blind_watermark import WaterMark

bwm1 = WaterMark(password_img=1, password_wm=1)
bwm1.read_ori_img('pic/ori_img.jpg')
bwm1.read_wm([True, False, True, True, True, False], mode='bit')
bwm1.embed('output/embedded.png')
```

Extract:
```python
bwm1 = WaterMark(password_img=1, password_wm=1, wm_shape=6)
wm_extract = bwm1.extract('output/打上水印的图.png', mode='bit')
print(wm_extract)
```
Notice that `wm_shape` (shape of watermark) is necessary

The output `wm_extract` is an array of float. set a threshold such as 0.5.


# Concurrency

```python
WaterMark(..., processes=None)
```
- `processes` number of processes, can be integer. Default `None`, which means using all processes.  

## Related Project

- text_blind_watermark (Embed message into text): [https://github.com/guofei9987/text_blind_watermark](https://github.com/guofei9987/text_blind_watermark)  
- HideInfo（hide as image, hide as sounds, hide as text）：[https://github.com/guofei9987/HideInfo](https://github.com/guofei9987/HideInfo)

---

### Overview (`docs/README.md`)

# [blind_watermark](https://github.com/guofei9987/blind_watermark)

[](https://pypi.org/project/blind_watermark/)
[](https://github.com/guofei9987/blind_watermark)
[](https://travis-ci.com/guofei9987/blind_watermark)
[](https://codecov.io/gh/guofei9987/blind_watermark)
[](https://pypi.org/project/blind_watermark/)
[](https://github.com/guofei9987/blind_watermark/stargazers)
[](https://github.com/guofei9987/blind_watermark/network/members)
[](https://gitter.im/guofei9987/blind_watermark?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)



Heuristic Algorithms in Python  
(Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing, Ant Colony Algorithm, Immune Algorithm,Artificial Fish Swarm Algorithm in Python)  


- **Documentation:** [https://blind_watermark.github.io/blind_watermark/#/en/](https://blind_watermark.github.io/blind_watermark/#/en/)
- **文档：** [https://blind_watermark.github.io/blind_watermark/#/zh/](https://blind_watermark.github.io/blind_watermark/#/zh/)  
- **Source code:** [https://github.com/guofei9987/blind_watermark](https://github.com/guofei9987/blind_watermark)

---

### Overview (`docs/en/README.md`)

# blind-watermark

Blind watermark based on dct and svd.


[](https://pypi.org/project/blind_watermark/)
[](https://travis-ci.com/guofei9987/blind_watermark)
[](https://codecov.io/gh/guofei9987/blind_watermark)
[](https://github.com/guofei9987/blind_watermark/blob/master/LICENSE)


[](https://github.com/guofei9987/blind_watermark/)
[](https://github.com/guofei9987/blind_watermark/fork)
[](https://pepy.tech/project/blind-watermark)
[](https://github.com/guofei9987/blind_watermark/discussions)


- **Documentation:** [https://BlindWatermark.github.io/blind_watermark/#/en/](https://BlindWatermark.github.io/blind_watermark/#/en/)
- **文档：** [https://BlindWatermark.github.io/blind_watermark/#/zh/](https://BlindWatermark.github.io/blind_watermark/#/zh/)  
- **中文 readme** [README_cn.md](README_cn.md)
- **Source code:** [https://github.com/guofei9987/blind_watermark](https://github.com/guofei9987/blind_watermark)



# install
```bash
pip install blind-watermark
```

For the current developer version:
```bach
git clone git@github.com:guofei9987/blind_watermark.git
cd blind_watermark
pip install .
```

# How to use


### Use in bash


```bash
# embed watermark into image:
blind_watermark --embed --pwd 1234 examples/pic/ori_img.jpeg "watermark text" examples/output/embedded.png
# extract watermark from image:
blind_watermark --extract --pwd 1234 --wm_shape 111 examples/output/embedded.png
```



## Use in Python

Original Image + Watermark = Watermarked Image

 + '@guofei9987 开源万岁！' = 


See the [codes](/examples/example_str.py)

Embed watermark:
```python
from blind_watermark import WaterMark

bwm1 = WaterMark(password_img=1, password_wm=1)
bwm1.read_img('pic/ori_img.jpg')
wm = '@guofei9987 开源万岁！'
bwm1.read_wm(wm, mode='str')
bwm1.embed('output/embedded.png')
len_wm = len(bwm1.wm_bit)
print('Put down the length of wm_bit {len_wm}'.format(len_wm=len_wm))
```

Extract watermark:
```python
bwm1 = WaterMark(password_img=1, password_wm=1)
wm_extract = bwm1.extract('output/embedded.png', wm_shape=len_wm, mode='str')
print(wm_extract)
```
Output:
>@guofei9987 开源万岁！

### attacks on Watermarked Image


|attack method|image after attack|extracted watermark|
|--|--|--|
|Rotate 45 Degrees||'@guofei9987 开源万岁！'|
|Random crop||'@guofei9987 开源万岁！'|
|Masks|  |'@guofei9987 开源万岁！'|
|50% Horizontal cut||'@guofei9987 开源万岁！'|
|50% Vertical cut||'@guofei9987 开源万岁！'|
|Resize 0.5||'@guofei9987 开源万岁！'|
|Pepper Noise||'@guofei9987 开源万岁！'|
|Brightness 10% Down||'@guofei9987 开源万岁！'|






### embed images

embed watermark:
```python
from blind_watermark import WaterMark

bwm1 = WaterMark(password_wm=1, password_img=1)
# read original image
bwm1.read_img('pic/ori_img.jpg')
# read watermark
bwm1.read_wm('pic/watermark.png')
# embed
bwm1.embed('output/embedded.png')
```


Extract watermark:
```python
bwm1 = WaterMark(password_wm=1, password_img=1)
# notice that wm_shape is necessary
bwm1.extract(filename='output/embedded.png', wm_shape=(128, 128), out_wm_name='output/extracted.png', )
```


|attack method|image after attack|extracted watermark|
|--|--|--|
|Rotate 45 Degrees|||
|Random crop|||
|Mask|  ||


### embed array of bits

See it [here](/examples/example_bit.py)


As demo, we embed 6 bytes data:
```python
wm = [True, False, True, True, True, False]
```

Embed:
```python
from blind_watermark import WaterMark

bwm1 = WaterMark(password_img=1, password_wm=1)
bwm1.read_ori_img('pic/ori_img.jpg')
bwm1.read_wm([True, False, True, True, True, False], mode='bit')
bwm1.embed('output/embedded.png')
```

Extract:
```python
bwm1 = WaterMark(password_img=1, password_wm=1, wm_shape=6)
wm_extract = bwm1.extract('output/打上水印的图.png', mode='bit')
print(wm_extract)
```
Notice that `wm_shape` (shape of watermark) is necessary

The output `wm_extract` is an array of float. set a threshold such as 0.5.


# Concurrency

```python
WaterMark(..., processes=None)
```
- `processes`: number of processes, can be integer. Default `None`, meaning use all processes.  

## Related Project

text_blind_watermark: [https://github.com/guofei9987/text_blind_watermark](https://github.com/guofei9987/text_blind_watermark)  
Embed message into text.

---

### Overview (`docs/zh/README.md`)

# blind-watermark

基于频域的数字盲水印  


[](https://pypi.org/project/blind_watermark/)
[](https://travis-ci.com/guofei9987/blind_watermark)
[](https://codecov.io/gh/guofei9987/blind_watermark)
[](https://github.com/guofei9987/blind_watermark/blob/master/LICENSE)


[](https://github.com/guofei9987/blind_watermark/)
[](https://github.com/guofei9987/blind_watermark/fork)
[](https://pepy.tech/project/blind-watermark)
[](https://github.com/guofei9987/blind_watermark/discussions)


- **Documentation:** [https://BlindWatermark.github.io/blind_watermark/#/en/](https://BlindWatermark.github.io/blind_watermark/#/en/)
- **文档：** [https://BlindWatermark.github.io/blind_watermark/#/zh/](https://BlindWatermark.github.io/blind_watermark/#/zh/)  
- **English readme** [README.md](README.md)
- **Source code:** [https://github.com/guofei9987/blind_watermark](https://github.com/guofei9987/blind_watermark)

# 安装
```bash
pip install blind-watermark
```

或者安装最新开发版本
```bach
git clone git@github.com:guofei9987/blind_watermark.git
cd blind_watermark
pip install .
```

# 如何使用

### 命令行中使用

```bash
# 嵌入水印：
blind_watermark --embed --pwd 1234 examples/pic/ori_img.jpeg "watermark text" examples/output/embedded.png
# 提取水印：
blind_watermark --extract --pwd 1234 --wm_shape 111 examples/output/embedded.png
```



## Python 中使用

原图 + 水印 = 打上水印的图

 + '@guofei9987 开源万岁！' = 



参考 [代码](/examples/example_str.py)


嵌入水印
```python
from blind_watermark import WaterMark

bwm1 = WaterMark(password_img=1, password_wm=1)
bwm1.read_img('pic/ori_img.jpg')
wm = '@guofei9987 开源万岁！'
bwm1.read_wm(wm, mode='str')
bwm1.embed('output/embedded.png')
len_wm = len(bwm1.wm_bit)
print('Put down the length of wm_bit {len_wm}'.format(len_wm=len_wm))
```


提取水印
```python
bwm1 = WaterMark(password_img=1, password_wm=1)
wm_extract = bwm1.extract('output/embedded.png', wm_shape=len_wm, mode='str')
print(wm_extract)
```
Output:
>@guofei9987 开源万岁！


### 各种攻击后的效果

|攻击方式|攻击后的图片|提取的水印|
|--|--|--|
|旋转攻击45度||'@guofei9987 开源万岁！'|
|随机截图||'@guofei9987 开源万岁！'|
|多遮挡|  |'@guofei9987 开源万岁！'|
|横向裁剪50%||'@guofei9987 开源万岁！'|
|纵向裁剪50%||'@guofei9987 开源万岁！'|
|缩放攻击||'@guofei9987 开源万岁！'|
|椒盐攻击||'@guofei9987 开源万岁！'|
|亮度攻击||'@guofei9987 开源万岁！'|



### 嵌入图片

参考 [代码](/examples/example_str.py)


嵌入：
```python
from blind_watermark import WaterMark

bwm1 = WaterMark(password_wm=1, password_img=1)
# read original image
bwm1.read_img('pic/ori_img.jpg')
# read watermark
bwm1.read_wm('pic/watermark.png')
# embed
bwm1.embed('output/embedded.png')
```

提取：
```python
bwm1 = WaterMark(password_wm=1, password_img=1)
# notice that wm_shape is necessary
bwm1.extract(filename='output/embedded.png', wm_shape=(128, 128), out_wm_name='output/extracted.png', )
```

|攻击方式|攻击后的图片|提取的水印|
|--|--|--|
|旋转攻击45度|||
|随机截图|||
|多遮挡|  ||



### 隐水印还可以是二进制数据

参考 [代码](/examples/example_bit.py)


作为 demo， 如果要嵌入是如下长度为6的二进制数据
```python
wm = [True, False, True, True, True, False]
```

嵌入水印

```python
# 除了嵌入图片，也可以嵌入比特类数据
from blind_watermark import WaterMark

bwm1 = WaterMark(password_img=1, password_wm=1)
bwm1.read_ori_img('pic/ori_img.jpg')
bwm1.read_wm([True, False, True, True, True, False], mode='bit')
bwm1.embed('output/打上水印的图.png')
```

解水印：（注意设定水印形状 `wm_shape`）
```python
bwm1 = WaterMark(password_img=1, password_wm=1, wm_shape=6)
wm_extract = bwm1.extract('output/打上水印的图.png', mode='bit')
print(wm_extract)
```

解出的水印是一个0～1之间的实数，方便用户自行卡阈值。如果水印信息量远小于图片可容纳量，偏差极小。

# 并行计算

```python
WaterMark(..., processes=None)
```
- `processes`: 整数，指定线程数。默认为 `None`, 表示使用全部线程。


## 相关项目

text_blind_watermark: [https://github.com/guofei9987/text_blind_watermark](https://github.com/guofei9987/text_blind_watermark)  
文本盲水印，把信息隐秘地打入文本.

---

###  Coverpage (`docs/_coverpage.md`)

# blind_watermark

> 数字盲水印

* 图片水印
* 比特水印

[GitHub](https://github.com/guofei9987/blind_watermark/)
[Get Started](/en/README)

---

###  Navbar (`docs/_navbar.md`)

- Translations
  - [:uk: English](/en/)
  - [:cn: 中文](/zh/)

---

###  Sidebar (`docs/_sidebar.md`)

* [English Document](docs/en.md)
* [中文文档](docs/zh.md)

---

### En  Coverpage (`docs/en/_coverpage.md`)

# blind_watermark

> Blind Watermark

* [](https://pypi.org/project/blind_watermark/)
[](https://travis-ci.com/guofei9987/blind_watermark)
[](https://codecov.io/gh/guofei9987/blind_watermark)
[](https://github.com/guofei9987/blind_watermark/blob/master/LICENSE)


[](https://github.com/guofei9987/blind_watermark/)
[](https://github.com/guofei9987/blind_watermark/fork)
[](https://pepy.tech/project/blind-watermark)
[](https://github.com/guofei9987/blind_watermark/discussions)
* embed a picture
* embed a string
* embed byte-file

[GitHub](https://github.com/guofei9987/blind_watermark/)
[Get Started](/en/README)

---

### Zh  Coverpage (`docs/zh/_coverpage.md`)

# blind_watermark

> 数字盲水印

* [](https://pypi.org/project/blind_watermark/)
[](https://travis-ci.com/guofei9987/blind_watermark)
[](https://codecov.io/gh/guofei9987/blind_watermark)
[](https://github.com/guofei9987/blind_watermark/blob/master/LICENSE)


[](https://github.com/guofei9987/blind_watermark/)
[](https://github.com/guofei9987/blind_watermark/fork)
[](https://pepy.tech/project/blind-watermark)
[](https://github.com/guofei9987/blind_watermark/discussions)
* 嵌入图片
* 嵌入文本
* 嵌入二进制

[GitHub](https://github.com/guofei9987/blind_watermark/)
[开始](/zh/README)

---

--- METRICS ---
- Files Extracted: 9
- Estimated Token Budget: ~3820 tokens
- Canonical Reference: https://codewiki.google/github.com/guofei9987/blind_watermark
