📄 embedding.m
字号:
clear all;
close all;
clc;
X=imread('lena.jpg');
% X=imread('onion.png');
X = imresize(X,[512 512]);
imwrite(X,'original.jpg');
figure;
imshow(X),title('Host Image');
I=X;
IW = X;
X = X(:,:,2); % Taking green plane alone for watermark embedding
X=double(X);
[LL1,HL1,LH1,HH1]=dwt2(X,'haar'); % First level decomposition
[LL2,HL2,LH2,HH2]=dwt2(HL1,'haar'); % Second level decomposition
figure;
imshow(LL1),title('Approximation 1 coeff');
figure;
imshow(HL1),title('H1 coeff');
figure;
imshow(LH1),title('V1 coeff');
figure;
imshow(HH1),title('D1 coeff');
figure;
imshow(LL2),title('Approximation 2 coeff');
figure;
imshow(HL2),title('H2 coeff');
figure;
imshow(LH2),title('V2 coeff');
figure;
imshow(HH2),title('D2 coeff');
w=imread('cam.jpg');
w2=im2bw(w); % Converting it in to logical image format
w1=imresize(w2,[128 128]);
W = w1;
figure;
imshow(w1),title('Original Logo');
alpha = 0.05; % assign alpha value for embedding
%dividing
for m=0:31 %dividing into 32 blocks in horizontal direction
for n=0:31 %dividing into 32 blocks in vertical direction
for i=1+4*m:4+4*m
for j=1+n*4:4+4*n
z(i-m*4,j-n*4)=HL2(i,j);%we get 1 block of HL2
w3(i-m*4,j-n*4)=w1(i,j);% we get 1 block of watermark
end
end
for i=1+4*m:4+4*m
for j=1+n*4:4+4*n
W3(i,j) = (1-alpha) * z(i-m*4,j-n*4) + (alpha * w3(i-m*4,j-n*4)); % Formula for embedding
end
end
for i=1+4*m:4+4*m
for j=1+n*4:4+4*n
HL2(i,j) = W3(i,j); %combining all blocks into 128*128 matrixHL2(i,j)
end
end
end % vertical block end
end % Horizontal end
%take inverse dwt
HL1=(idwt2(LL2,HL2,LH2,HH2,'haar')); % Reconstruction of HL1
Y=(idwt2(LL1,HL1,LH1,HH1,'haar')); % Reconstructed watermarked image
IW(:,:,2) = Y; %Integrating watermarked green plane with original R and B plane
figure;
imshow(IW),title('Watermarked image');%watermarked image
imwrite(uint8(IW),'watermarked.jpg');
figure;
subplot(1,3,1),imshow(I);title('Original Image');
subplot(1,3,2),imshow(W);title('Original Logo');
subplot(1,3,3),imshow(IW);title('Watermarked Image');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -