-
Notifications
You must be signed in to change notification settings - Fork 0
/
dwt_decode.m
30 lines (30 loc) · 1.01 KB
/
dwt_decode.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function [tamperedLocations, res] = dwt_decode(watered)
% im=imread(tampered);
im = imread(strcat(extractBefore(watered,"_"),'_dwt.bmp'));
% im = imread('lenna_dwt.bmp');
im1=imread(watered);
if(ndims(im)==3)
im = im(:, :, 1);
end
if(ndims(im1)==3)
im1 = im1(:, :, 1);
end
grayTamperedImage=im;
grayWateredImage=im1;
% 对篡改图像进行DWT变换
level=1;
[tCA, ~, ~, ~] = dwt2(grayTamperedImage, 'db1', level);
[wCA, ~, ~, ~] = dwt2(grayWateredImage, 'db1', level);
% 计算DWT系数之间的差异
diffCA = abs(wCA - tCA);
if(sum(sum(diffCA))<100)
res=0;
tamperedLocations = zeros(size(diffCA));
else
res=1;
% 设置差异阈值,超过阈值则认为是篡改区域
threshold = 20;
% 标记出篡改位置
tamperedLocations = diffCA > threshold;
end
end