Skip to content

Commit 5dab36d

Browse files
committed
整理LSB代码文件,上传仓库
0 parents  commit 5dab36d

30 files changed

+302
-0
lines changed

.DS_Store

8 KB
Binary file not shown.

falseRate.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import numpy as np
2+
from cv2 import cv2 as cv
3+
import math
4+
5+
def falseRate(img1,img2):
6+
img1_float = np.array(img1,dtype=np.float)
7+
img2_float = np.array(img2,dtype=np.float)
8+
return np.mean(abs(img1_float-img2_float))/256
9+
10+
if __name__ == "__main__":
11+
imgEmbedPath = input('embed img path(orignal watermark):')
12+
imgExtractPath = input('extract img path(extracted watermark):')
13+
imgEmbed = cv.imread(imgEmbedPath,cv.IMREAD_UNCHANGED)
14+
imgExtract = cv.imread(imgExtractPath,cv.IMREAD_UNCHANGED)
15+
print('「提取出来的水印」的错误率:{}'.format(falseRate(imgEmbed,imgExtract)))
16+

genNeedImg.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from cv2 import cv2 as cv
2+
import sys
3+
4+
def genNeedImg(imgPath,size=None,flag='binary'):
5+
'''
6+
用于生成指定大小的灰度图或二值图, imgPath为图像路径
7+
size为tuple类型,用于指定生成图像的尺寸, 如:(512,512),默认为None表示输出原图像尺寸
8+
flag为标志转换类型,默认为binary,可选的值为binary或gray
9+
'''
10+
imgRow = cv.imread(imgPath)
11+
if size != None: # 调整图像尺寸
12+
imgRow= cv.resize(imgRow,size)
13+
imgGray = cv.cvtColor(imgRow,cv.COLOR_RGB2GRAY) # 转换颜色空间为灰度
14+
imgName = imgPath[9:].split('.')[0] # 获取图像原始名称
15+
if flag == 'gray': # 生成灰度图
16+
cv.imwrite('./images/{}_gray.bmp'.format(imgName),imgGray)
17+
print('Gray image generated!')
18+
else: # 生成二值图
19+
ret, imgBinary = cv.threshold(imgGray,127,255,cv.THRESH_BINARY)
20+
prop = int(size[0]*size[1]/(512*512)*100) # 以载体图像为512x512,算生成的水印大小占载体图的百分比
21+
cv.imwrite('./images/{}_binary{}.bmp'.format(imgName,prop),imgBinary)
22+
print('Binary image generated!')
23+
print('threshold:{}'.format(ret)) # 输出转换与之
24+
25+
if __name__ == "__main__":
26+
imgName = sys.argv[1]
27+
size =[int(sys.argv[2]),int(sys.argv[3])]
28+
flag = sys.argv[4]
29+
genNeedImg(imgName,tuple(size),flag=flag)

images/.DS_Store

6 KB
Binary file not shown.

images/hn.png

2.29 MB
Loading

images/hn_gray.bmp

257 KB
Binary file not shown.

images/xn.jpg

78.9 KB
Loading

images/xn_binary100.bmp

257 KB
Binary file not shown.

images/xn_binary25.bmp

65.1 KB
Binary file not shown.

images/xn_binary50.bmp

129 KB
Binary file not shown.

0 commit comments

Comments
 (0)