PVD Steganography with modulus function

9 次查看(过去 30 天)
Hi. I am currently implementing a PVD Steganography with modulus function. The embedded and extracted part runs perfectly. However the text file extracted seems is not 100% correct. I suspect that the ceil and floor function at embedded part is causing the problems. I hope anyone can solve my doubt as I have debugging for quite some times but the results are not satisfied.Thanks. Below is my matlab coding:
Embedded part:
function modulus(inputEmbed,inputText,outputEmbed)
fid = fopen(inputText,'r');
em = fread(fid);
len = length(em);
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
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
lb=[0 8 16 32 64 128]; %lowerbound
ub=[7 15 31 63 127 255]; %upperbound
dap=abs(d);
for i=1:1:6 %test the R boundary
if(dap >= lb(i)&& dap <= ub(i))
n=ub(i)-lb(i)+1; %quantization width of range
t=log2(n); %maximum bit can be embedded between 2 pixel
capacity=capacity+t;
nt=2^t;
FREM =mod((g(1,1)+g(1,2)),nt);
if(next>length(in))
m=0;
m1=0;
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))
m=0;
m1=0;
else
m=abs(FREM-k);
m1=2^t-abs(FREM-k);
end
else
k=in(1+next:t+next);
next=next+t;
k=bin2dec(char(k));
m=abs(FREM-k);
m1=2^t-abs(FREM-k);
end
end
end
if(FREM>k && m<=((2^t)/2) && g(1,1)>=g(1,2))
P0=[g(1,1)-ceil(m/2) g(1,2)-floor(m/2)];
elseif (FREM>k && m<=((2^t)/2) && g(1,1)<g(1,2))
P0=[g(1,1)-ceil(m/2) g(1,2)-floor(m/2)];
elseif (FREM>k && m>((2^t)/2) && g(1,1)>=g(1,2))
P0=[g(1,1)+ceil(m1/2) g(1,2)+floor(m1/2)];
elseif (FREM>k && m>((2^t)/2) && g(1,1)<g(1,2))
P0=[g(1,1)+ceil(m1/2) g(1,2)+floor(m1/2)];
elseif (FREM<=k && m<=((2^t)/2) && g(1,1)>=g(1,2))
P0=[g(1,1)+ceil(m/2) g(1,2)+floor(m/2)];
elseif (FREM<=k && m<=((2^t)/2) && g(1,1)<g(1,2))
P0=[g(1,1)+ceil(m/2) g(1,2)+floor(m/2)];
elseif (FREM<=k && m>((2^t)/2) && g(1,1)>=g(1,2))
P0=[g(1,1)-ceil(m1/2) g(1,2)-floor(m1/2)];
elseif (FREM<=k && m>((2^t)/2) && g(1,1)<g(1,2))
P0=[g(1,1)-ceil(m1/2) g(1,2)-floor(m1/2)];
end
if((g(1,1)==0 || g(1,2)==0)&&(P0(1)<0 || P0(2)<0))
P1=[P0(1)+((2^t)/2) P0(2)+((2^t)/2)];
final(1+x,1+y)=P1(1,1); %replace new pixel value into final
final(1+x,2+y)=P1(1,2);
elseif((g(1,1)==255 || g(1,2)==255)&&(P0(1)>255 || P0(2)>255))
P1=[P0(1)-((2^t)/2) P0(2)-((2^t)/2)];
final(1+x,1+y)=P1(1,1); %replace new pixel value into final
final(1+x,2+y)=P1(1,2);
elseif(dap>128)
if(P0(1)<0 && P0(2)>=0)
P1=[0 P0(1)+P0(2)];
final(1+x,1+y)=P1(1,1); %replace new pixel value into final
final(1+x,2+y)=P1(1,2);
elseif(P0(1)>=0 && P0(2)<0)
P1=[P0(1)+P0(2) 0];
final(1+x,1+y)=P1(1,1); %replace new pixel value into final
final(1+x,2+y)=P1(1,2);
elseif(P0(1)>255 && P0(2)>=0)
P1=[255 P0(2)+(P0(1)-255)];
final(1+x,1+y)=P1(1,1); %replace new pixel value into final
final(1+x,2+y)=P1(1,2);
elseif(P0(1)>=0 && P0(2)>255)
P1=[P0(1)+(P0(2)-255) 255];
final(1+x,1+y)=P1(1,1); %replace new pixel value into final
final(1+x,2+y)=P1(1,2);
end
else
final(1+x,1+y)=P0(1,1); %replace new pixel value into final
final(1+x,2+y)=P0(1,2);
end
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
capacity
Extraction Part:
function extractmodulus(embeddedtif,outputtxt)
msg = [];
flag = 0;
a=imread(embeddedtif);
[r,c]=size(a);
j=0;
length=0;
for x=0:1:r-1
for y=0:2:c-1
gp=a(1+x,1+y:2+y);
gp=double(gp);
nd=abs(gp(1,2)-gp(1,1));
lb=[0 8 16 32 64 128];
ub=[7 15 31 63 127 255];
for i=1:1:6
if(nd>=lb(i)&&nd<=ub(i))
w=ub(i)-lb(i)+1;
t=log2(w);
FREM=mod(gp(1,1)+gp(1,2),2^t);
k=dec2bin(FREM,t);
msg = [msg k];
j=j+t;
if(flag==0 && j>=20)
length=bin2dec(msg(1:20))+3; %possible 3 char error
length=length*7;
flag=1;
end
if(flag==1 && j>=length)
j=1;
for i=20:7:length-7
finaltxt(j)=bin2dec(msg(1+i:7+i));
j=j+1;
end
fid=fopen(outputtxt,'w');
fwrite(fid,finaltxt);
fclose('all');
end
end
end
end
end
  1 个评论
Walter Roberson
Walter Roberson 2012-1-1
If there embedding is running "perfectly" (your indication) then by definition there is no error in the embedding, and so it would be a contradiction for there to be an error in the floor and ceiling part of the embedding. Thus either the embedding is *not* running "perfectly" or else the error is in the extraction.

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by