本文地址:https://blog.youkuaiyun.com/Maxwave13/article/details/105555019
其他地址都是转载
参考博客 :Matlab STDM 数字水印算法
原理可以参考 这篇论文 : STDM 图像水印改进算法.
这种水印算法比较久远,没有python代码,所以我就实现了一下。
块处理的算法比较有价值,是参考 :块处理 block process
以下为具体步骤:
先编写块处理函数,将图像分成8*8后进行DCT变换。
def block_dct(M, blk_size=(8,8), flag = "dctn"):
from scipy.fftpack import dctn, idctn
if flag == "dctn":
fun = dctn
elif flag == "idctn":
fun = idctn
M = M[:M.shape[0]-M.shape[0]%blk_size[0],
:M.shape[1]-M.shape[1]%blk_size[1]]
rows = []
for i in range(0, M.shape[0], blk_size[0]):
cols = []
for j in range(0, M.shape[1], blk_size[1]):
max_ndx = (min(i+blk_size[0], M.shape[0]),
min(j+blk_size[1], M.shape[1]))
cols.append(fun(M[i:max_ndx[0], j:max_ndx[1]], nor