SVD watermarking color image
Show older comments
Hi, Im trying to change algorith from grayscale to color images but I stuck
clear all;
clc;
close all;
%img= rgb2gray(imread('photo1.jpg'));%host image
img= imread('photo1.jpg');%host image
%img=imresize(img,[256 256]);
imwrite(uint8(img),'photo1 org.jpg');
%[M,N]=size(img);
img=double(img);
imgr=img(:,:,1);
imgg=img(:,:,2);
imgb=img(:,:,3);
[Uimgr,Simgr,Vimgr]=svd(imgr);
[Uimgg,Simgg,Vimgg]=svd(imgg);
[Uimgb,Simgb,Vimgb]=svd(imgb);
Simgr_temp=Simgr;
Simgg_temp=Simgg;
Simgb_temp=Simgb;
%global U_SHL_w
%global V_SHL_w
% read watermark
%img_wat=imresize(rgb2gray(imread('photo2.jpg')),[256 256]);
img_wat=imread('photo2.jpg');
%img_wat=imresize(img_wat,[256 256]);
imwrite(uint8(img_wat),'watermark.jpg','jpg');
alfa =0.1;
%alfa= input('The alfa Value = ');
[x y]=size(img_wat);
img_wat=double(img_wat);
img_watr=img_wat(:,:,1);
img_watg=img_wat(:,:,2);
img_watb=img_wat(:,:,3);
%[U_SHL_wr,S_SHL_wr,V_SHL_wr]=svd(img_watr);
%[U_SHL_wg,S_SHL_wg,V_SHL_wg]=svd(img_watg);
%[U_SHL_wb,S_SHL_wb,V_SHL_wb]=svd(img_watb);
for i=1:x
for j=1:y
Simgr(i,j) =Simgr(i,j) + alfa * img_watr(i,j);
Simgg(i,j) =Simgg(i,j) + alfa * img_watg(i,j);
Simgb(i,j) =Simgb(i,j) + alfa * img_watb(i,j);
end
end
SVD for Simg (SM)
%Simgr =Simgr + alfa * img_watr;
%Simgg =Simgg + alfa * img_watg;
%Simgb =Simgb + alfa * img_watb;
[U_SHL_wr,S_SHL_wr,V_SHL_wr]=svd(img_watr);
[U_SHL_wg,S_SHL_wg,V_SHL_wg]=svd(img_watg);
[U_SHL_wb,S_SHL_wb,V_SHL_wb]=svd(img_watb);
Wimgr =Uimgr* S_SHL_wr * Vimgr';
Wimgg =Uimgg* S_SHL_wg * Vimgg';
Wimgb =Uimgb* S_SHL_wb * Vimgb';
Wimg=cat(3,Wimgr,Wimgg,Wimgb);
figure
imshow(uint8(img));
title('The Original Image')
figure
imshow(uint8(img_wat));
title('The Watermark')
imwrite(uint8(Wimg),'watermarked.jpg','jpg');
imshow(uint8(Wimg));
title('The Watermarked')
K=imabsdiff(img,Wimg);
figure
imshow(K,[])
I see error:
Index in position 2 exceeds array bounds (must not exceed 400).
Error in embedcolor (line 48)
Simgr(i,j) =Simgr(i,j) + alfa * img_watr(i,j);
How to reapir it?
1 Comment
KALYAN ACHARJYA
on 31 Aug 2019
Edited: KALYAN ACHARJYA
on 31 Aug 2019
Please do attach all required pics, for that use paper clip (Attachments)
Accepted Answer
More Answers (0)
Categories
Find more on Watermarking in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!