PVD Steganography with base decomposition
Show older comments
Hi. I have just write the code myself. Below is the code for PVD with base decomposition method. However, when I to compile and run it gives no respond with no output image. Can anyone tells me whatis wrong with my code? Thanks.
function BPVD(inputEmbed,inputText,outputEmbed)
fid = fopen(inputText,'r'); %read input text file
em = fread(fid);
len = length(em); %calculate total length of character
in = [];
in=[in dec2bin(len,20)];
for i=1:len %character convert to binary
in=[in dec2bin(em(i),7)];
end
a = imread(inputEmbed); %get cover image
[r,c]=size(a);
final=double(a);
next=0;
capacity=0; %bit space that can be embedded
MSE=[];
Pnew2=[];
for x=0:1:r-1 %traverse through all the pixel value on
for y=0:2:c-1 %the image by 2 consecutive pair non overlaping pixel
g=a(1+x,1+y:2+y);
g=double(g);
d=g(1,2)-g(1,1); %d=difference between 2 pixel
%d=a(1+x,2+y)-a(1+x,1+y); %calculate the difference d=(gi+1)-gi
lb=[0 16 32 64 128]; %lowerbound
ub=[15 31 63 127 255]; %upperbound
Base2=[3 4 5 8 11];
Base1=[3 4 7 8 12];
R=[1 2 3 4 5];
dap=abs(d); %absolute value to make 0<=d<=255
for i=1:1:5 %test the R boundary
if(dap >= lb(i)&& dap <= ub(i))
t=i+2;
J=R(i);
capacity=capacity+t;
if(next>length(in)) %if last iteration
k1=zeros(1,t);
k=k1;
%k=int2str(k);
k=bin2dec(char(k));%output rest will be remain as the same
Tquo=mod(fix(k/Base1(i)),Base2(i));
Trem=mod(k,Base1(i));
P1=fix(g(1,1)/Base2(i))*Base2(i)+Tquo;
P2=fix(g(1,2)/Base1(i))*Base1(i)+Trem;
elseif(next+t>length(in))
if(1+next>=length(in))
k=zeros(1,t);
else
k=in(1+next:length(in));
end
diff =next+t-length(in);
k1=zeros(1,t);
if(diff>0)
for j=1:next+t-length(in)
k1(j)=k(j);
end
end
k=k1;
next=next+t;
%k=int2str(k);
k=bin2dec(char(k));
if(1+next>length(in))
Tquo=mod(fix(k/Base1(i)),Base2(i));
Trem=mod(k,Base1(i));
P1=fix(g(1,1)/Base2(i))*Base2(i)+Tquo;
P2=fix(g(1,2)/Base1(i))*Base1(i)+Trem;
else
Tquo=mod(fix(k/Base1(i)),Base2(i));
Trem=mod(k,Base1(i));
P1=fix(g(1,1)/Base2(i))*Base2(i)+Tquo;
P2=fix(g(1,2)/Base1(i))*Base1(i)+Trem;
end
else
k=in(1+next:t+next); %for all front part iteration
next=next+t;
%k=int2str(k);
k=bin2dec(char(k)); %convert binary to decimal
Tquo=mod(fix(k/Base1(i)),Base2(i));
Trem=mod(k,Base1(i));
P1=fix(g(1,1)/Base2(i))*Base2(i)+Tquo;
P2=fix(g(1,2)/Base1(i))*Base1(i)+Trem;
end
end
end
if(P1>255)
P1=P1-Base2(J);
end
if(P2>255)
P2=P2-Base1(J);
end
P1N=P1-Base2(J);
P1P=P1+Base2(J);
P2N=P2-Base1(J);
P2P=P2+Base1(J);
POOL1=[P1N P1 P1P];
POOL2=[P2N P2 P2P];
for PI=1:3
for PJ=1:3
Pnew1=[POOL1(PI) POOL2(PJ)];
nd=abs(POOL1(PI)-POOL2(PJ));
for w=1:1:5
if(nd >= lb(w)&& nd <= ub(w))
if(w==J)
MSE=[MSE (Pnew1(1,1)-g(1,1))^2+(Pnew1(1,2)-g(1,2))^2];
Pnew2=[Pnew2 Pnew1];
end
end
end
end
end
Q=min(MSE);
[r1 c1]=size(MSE);
for j=1:1:c1
if(MSE(j)==Q)
Pnew3=[Pnew2(j*2-1) Pnew2(j*2)];
end
end
final(1+x,1+y)=Pnew3(1,1); %replace new pixel value into final
final(1+x,2+y)=Pnew3(1,2);
end
end
if(next>length(in))
disp('Embedded Successfully...Writing to output image');
try
imwrite(uint8(final),outputEmbed); %construct new image using final pixel values
catch
disp('Unable to write into output image file');
disp('Execution Unsuccessful...Exiting');
fclose('all');
exit;
end
end
psnr(inputEmbed,outputEmbed)
capacity
Answers (0)
Categories
Find more on Image Arithmetic 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!