spread spectrum watermarking - error in the code
Show older comments
i have written a code for spread spectrum watermarking. But it shows the error that input must be a string. can any one help me to correct the program.
clc;
clear all;
close all;
k=.0002; % set the gain factor for embeding
% read in the cover object
cover_object=dicomread('189.dcm');
cover_object = uint8(255*mat2gray(cover_object));
figure, imshow(cover_object,[])
title('input Image')
% determine size of watermarked image
[Mc Nc]=size(cover_object);
%reading the watermark image
fid=fileread('try.txt');
data=uint8(fid);
data_b=dec2bin(data);
data_f=reshape(data_b',1,[])
message_vector=data_f;
x=length(message_vector);
els = {'p',[-0.125 0.125],0};
lshaarInt = liftwave('haar','int2int');
lsnewInt = addlift(lshaarInt,els);
[LL,LH,HL,HH] = lwt2(double(cover_object),lsnewInt);
[LL1,LH1,HL1,HH1] = lwt2(double(LL),lsnewInt);
figure,imshow(LL,[]);
title('LL band');
figure,imshow(LL1,[]);
title(' LL1 band');
w=0;
[m n]=size(LL1);
pn=zeros(x,m*n);
% add pn sequences to HH
for kk=1:x
pn_sequence_h=round(rand(1,m*n));
pn(kk,:)=pn_sequence_h;
if (message_vector(kk) == 1)
w=w+pn_sequence_h;
end
end
host_vector=LL1(:);
Iw=host_vector+k*w';
wm=buffer(Iw,n);
figure, imshow(wm,[])
title(' band after watermarking')
% perform IDWT
LL = uint8(ilwt2(wm,LH1,HL1,HH1,lsnewInt));
watermarked_image=uint8(ilwt2(double(LL),LH,HL,HH,lsnewInt));
% convert back to uint8
watermarked_image_uint8=uint8(watermarked_image);
% display watermarked image
figure,imshow(watermarked_image_uint8,[])
% extraction part
title('Watermarked Image')
els = {'p',[-0.125 0.125],0};
%
lshaarInt = liftwave('haar','int2int');
lsnewInt = addlift(lshaarInt,els);
[LL,LH,HL,HH] = lwt2(double(watermarked_image_uint8),lsnewInt);
[LL1,LH1,HL1,HH1] = lwt2(double(LL),lsnewInt);
messagevector=[];
iw=LL1(:);
for kk=1:x
if (sign(cov(iw',pn(kk,:))) < 0)
messagevector(kk)=0;
else
messagevector(kk)=1;
end
end
e=reshape(messagevector,7,[]);
r=bin2dec(e');
ans=char(r)'
fido=fopen('out1.txt','w');
fwrite(fido,ans);
fclose(fido);
processed=double(watermarked_image);
original=double(cover_object);
[m n]=size(original);
%mserror
error=original-processed;
se=error.*error;
sumse=sum(sum(se));
mse=sumse/(m*n);
%mserror
ma=max(max(original));
t=10*log10(ma*ma/mse);
display 'The PSNR is :',t
[ssimval,b] = SSIM(watermarked_image,cover_object);
display 'The ssim is :',ssimval
[ssim,b] = SSIM(message,watermark);
display 'The ssim of watermark is :',ssimval
2 Comments
Walter Roberson
on 4 Jul 2016
As you did not provide the .dcm file or the .txt file for us to test with, do we at least get a hint as to which line the error was reported for? Maybe even a complete copy of the error message?
uthara ravi
on 4 Jul 2016
Edited: uthara ravi
on 4 Jul 2016
Answers (1)
Walter Roberson
on 4 Jul 2016
dec2bin() does not return an array that has 0 and 1 in each element. dec2bin() returns an array that has '0' and '1' in it, the characters for printing 0 and 1 rather than the values 0 and 1.
You are manipulating the '0' and '1' values believing that they are numeric 0 and 1. You are getting a numeric vector e as your result. You are then trying to convert that numeric vector to decimal as if it were suitable input for bin2dec, but bin2dec needs '0' and '1'.
Solution:
data_b = dec2bin(data) - '0';
Now the result will be numeric 0 and numeric 1.
Then later,
r = bin2dec( char(e' + '0'));
This converts the numeric 0 and numeric 1 to '0' and '1'
1 Comment
uthara ravi
on 4 Jul 2016
Categories
Find more on Watermarking in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!