MATLAB Answers

Taha rassem
1

Image watermarking using SVD

Asked by Taha rassem
on 18 Feb 2011
Latest activity Commented on by Huanhuan Wang
on 29 Jun 2016

I tired to write code to insert 256*256 image as watermark in a host image 256*256. I am using SVD in my algorithm. I just convert the original image to SVD and adding the watermark image(W) to the singular value as SM=S+aW. a is scaling factor. Then I do SVD for SM and select to singular value of SM to construct the watermarked image.

Please, kindly tell me if my the following code is correct.

The PSNR between original watermark and extracted watermark is very high (> 265 db). Is this value is acceptable?

The code:

%-------------------------
%Embedding 
%-------------------------
clear;
clc
img= imread('lena2.tif');
img=imresize(img,[256 256]);
[M,N]=size(img);
img=double(img);
[Uimg,Simg,Vimg]=svd(img);
Simg_temp=Simg;
% read watermark
 img_wat= imread('cameraman.tif');
 img_wat=imresize(img_wat,[256 256]);
   alfa= input('The alfa Value = ');
   [x y]=size(img_wat);
   img_wat=double(img_wat);
   for i=1:x
       for j=1:y
          Simg(i,j) =Simg(i,j) + alfa * img_wat(i,j);
       end 
   end 
   % SVD for Simg (SM)
  [U_SHL_w,S_SHL_w,V_SHL_w]=svd(Simg);
Wimg =Uimg* S_SHL_w * Vimg';
figure(1)
imshow(uint8(img));
title('The Original Image')
figure(2)
imshow(uint8(img_wat));
title('The Watermark ')
figure(3)
imshow(uint8(Wimg));
title('The Watermarked Image')
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%calculate image quality degradation after inserting watermark
%%%%%%%%%%%%%%%%%%%%%%%%%%%
mse=mean(squeeze(sum(sum((double(img)-double(Wimg)).^2))/(M*N)));
PSNR=10*log10(255^2./mse);
msg=sprintf('\n\n-------------------------\nWatermark by SVD  PSNR=%fdB\n-----------------------------\n\n', PSNR);
    disp(msg);
%--------------------------------------------------------------------------
% %% Extraction Part
% -------------------------------------------------------------------------
[UWimg,SWimg,VWimg]=svd(Wimg);
D_1=U_SHL_w * SWimg * V_SHL_w';
for i=1:x 
  for j=1:y
     Watermark(i,j)= (D_1(i,j) - Simg_temp(i,j) )/alfa ;
  end 
end
figure(8)
imshow(uint8(Watermark));
mse=mean(squeeze(sum(sum((double(img_wat)-(Watermark)).^2))/(M*N)));
PSNR=10*log10(255^2./mse);
msg=sprintf('\n\n-------------------------\nWatermark by SVD  PSNR=%fdB\n-----------------------------\n\n', PSNR);
disp(msg);

  3 Comments

If u have any query thn regarding ur project either mail at matlabprojects35@gmail.com or, https://www.facebook.com/MatlabProjects-909644652486619. Kindly Spread it to Help Others.

You should use correlation value not psnr to compare your embedded and extracted watermark

[U_SHL_w,S_SHL_w,V_SHL_w]=svd(Simg);
this line is wrong. Simg is the sigular value, not a image.
U can try this way:
Wimg =Uimg* Simg * Vimg'; 
where, 'Simg' is the new sigular U got before.Then, U can abondon the code:Wimg =Uimg* S_SHL_w * Vimg';

Products

No products are associated with this question.

1 Answer

Answer by meenakshi
on 30 Aug 2011

no, normally the psnr must be between 20 to 45.in calculation of mse instead of squeeze use, mean.

  1 Comment

If u have any query thn regarding ur project either mail at matlabprojects35@gmail.com or, https://www.facebook.com/MatlabProjects-909644652486619. Kindly Spread it to Help Others.


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!