多媒体安全重采样

批量把图片进行重采样

import matplotlib
import numpy
import cv2 as cv
import os
i = 1
dir = r"E:/Multimedia Security/num1" #原图路径
outdir = r"E:/Multimedia Security/chongcaiyang2"#保存重采样图路径
imlist = os.listdir(dir)
for img in imlist:
    img1 = cv.imread(dir + '/' + img)#读取图片
    img2=cv.resize(img1,(0,0),fx=0.5,fy=0.5,interpolation=cv.INTER_LINEAR)#进行重采样 模式为双线性插值
    outdir1=outdir+'/'+str(i)+'.tif'#输出路径
    cv.imwrite(outdir1, img2)#保存图片
    i = i + 1

进行图像残差计算得到p-map图

import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import cv2
import os
import matplotlib.image as 
mping
import shutil
from PIL import Image
from scipy import  ndimage


a = np.array([[-0.25, 0.5, -0.25], [0.5, 0, 0.5]
                 , [-0.25, 0.5, -0.25]])
r = 1
t = 2
K = 1
o = 1
dst = mping.imread(r"C:\Users\chengyuxiao\Desktop\1111.tif")  # 读取重采样图片
dst = dst[:, :,0]
h, w = np.shape(dst)
h2 = int(np.ceil(h / 2))
padimg = np.pad(dst, ((1, 1), (1, 1)), 'constant', constant_values=(0, 0)).astype(np.float32)
e = padimg - cv2.filter2D(padimg, -1, a)
e1 = padimg - cv2.filter2D(padimg, -1, a, borderType=cv2.BORDER_CONSTANT)  # 对残差图像做对比度增强
e = e[1:-1, 1:-1]
e = np.exp(-e ** 2)
p = r * np.exp(-(abs(e) ** 2) / o)
cv2.imwrite("4444.tif", p)#保存P-map图

重采样图的p-map图

下一步对p-map图做傅里叶变换,进行滤波和对比度增强。

V = np.fft.fft2(p)
V = np.fft.fftshift(V)
mask = np.ones(dst.shape, np.uint8)
win2 = 40 / 256 * h2
mask[int(h / 2 - win2):int(h / 2 + win2), int(w / 2 - win2):int(w / 2 + win2)] = 0
P0 = abs(V) * mask
P2 = ((P0 / np.max(np.abs(P0))) ** 4) * (np.max(np.abs(P0)))
print(np.where(P2 == P2.max()))
plt.imshow(P2)
plt.show()

在这里插入图片描述

在这里插入图片描述

​ 得到重采样图的FTT图

计算重采样的特征值

计算特征值的函数:
def getcha(P, h):
    P0 = P[:int(np.ceil(h / 2)), int(np.ceil(h / 2)):]
    l, m = np.where(P0 == np.max(P0))
    m = m[0] + 1
    if m < h / 2:
        P1 = P0[:int(np.ceil(h / 2)), :]
    else:
        P1 = P0[:, int(np.ceil(h / 2)):]

    C = np.array([0] * int(np.ceil(h / 2))).astype(np.float32)
    x = (np.sum(abs(P1) ** 2)) ** (-1)
    for j in range(0, int(np.ceil(h / 2))):
        C[j] = np.sum(abs(P1[int(np.ceil(h / 2)) - 1 - j:-1, 0:1 + j]) ** 2) * x
    # 分类
    C = abs(C)
    C = C / np.max(C)
    cha = C[:-1] - C[1:]
    return cha
主函数
a = np.array([[-0.25, 0.5, -0.25], [0.5, 0, 0.5]
                 , [-0.25, 0.5, -0.25]])
r = 1
t = 2
K = 1
o = 1
dst = mping.imread(r"C:\Users\chengyuxiao\Desktop\1111.tif")  # 图片读取函数
dst = dst[:, :,0]
h, w = np.shape(dst)
h2 = int(np.ceil(h / 2))
padimg = np.pad(dst, ((1, 1), (1, 1)), 'constant', constant_values=(0, 0)).astype(np.float32)
e = padimg - cv2.filter2D(padimg, -1, a)
e1 = padimg - cv2.filter2D(padimg, -1, a, borderType=cv2.BORDER_CONSTANT)  # 对残差图像做对比度增强
e = e[1:-1, 1:-1]
e = np.exp(-e ** 2)
p = r * np.exp(-(abs(e) ** 2) / o)
V = np.fft.fft2(p)
V = np.fft.fftshift(V)
mask = np.ones(dst.shape, np.uint8)
win2 = 40 / 256 * h2
mask[int(h / 2 - win2):int(h / 2 + win2), int(w / 2 - win2):int(w / 2 + win2)] = 0
P0 = abs(V) * mask
P2 = ((P0 / np.max(np.abs(P0))) ** 4) * (np.max(np.abs(P0)))
cha1=getcha(P2,h)
cha1=abs(cha1)
dele=max(cha1)
print(dele)
mask
P2 = ((P0 / np.max(np.abs(P0))) ** 4) * (np.max(np.abs(P0)))
cha1=getcha(P2,h)
cha1=abs(cha1)
dele=max(cha1)
print(dele)
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值