我是Matlab的初学者。如何在编辑框中按类型手动输入文本,并通过Matlab编程将其嵌入到bmp图像(Steganography)中?我使用PVD Steganography方法找到了代码。
这是示例代码,但它从文件中获取文本,而不是从我手动输入的内容中获取文本。请你的建议
% --- Executes on button press in btn_embedd.
function btn_embedd_Callback(hObject, eventdata, handles)
pilihinput=handles.pilihinput %berhubungan dg pilihan pada radiobutton
switch handles.pilihinput
case 1 % IF RADIO BUTTON INPUT TEXT MANUAL CHOOSEN
password1='';
password = get(handles.edt_passwordcover, 'string');
pwd=strcmp(password,'input password');
pwd1=strcmp(password,password1);
if (pwd)||(pwd1)
msgbox('Please input password','ERROR','error');
else
imfile=get(handles.txt_lokasicitracover,'String');
txfile=get(handles.edit_ketikpesan,'String');
w='';
k=strcmp(imfile,'input image');
k1=strcmp(imfile,w);
k2=strcmp(txfile,'input message');
k3=strcmp(txfile,w);
if (k)||(k1)
msgbox('Please input image','ERROR','error');
elseif (k2)||(k3)
msgbox('Please input message','ERROR','error');
else
try
file=imread(imfile);
isfile=1;
catch
isfile=0;
end;
try
istxfile=fopen(txfile,'rt');
catch
istxfile=-1; %If fopen cannot open the file, it returns -1.
end;
if(isfile==0)
msgbox('image not found. please browse image','ERROR','error');
elseif(istxfile<0)
msgbox('message file is empty. please type message','ERROR','error');
else
h=waitbar(0,'Embedding...');
for p=1:400, % computation here %
waitbar(p/100);
end;
[psnr,capa,opfile,full,file]=proses_embedd(imfile,txfile);
close(h);
set(handles.txt_nilaipnsr,'String',num2str(psnr));
set(handles.txt_ukuranpesan,'String',num2str(capa));
set(handles.txt_kapasitaspesan,'String',num2str(file));
figure,imshow(imfile);
figure,imshow(opfile);
if (full==0)
msg=strcat(int2str(capa),'bits only embedded please select a large image');
msgbox(msg,'warning','warn');
end;
if (full==1)
msgbox('SUCCESS!!!','SUCCESS');
end;
end;
end;
end;
case 2 % IF RADIO BUTTON TEXT FROM FILE CHOOSEN
password1='';
password = get(handles.edt_passwordcover, 'string');
pwd=strcmp(password,'input password');
pwd1=strcmp(password,password1);
if (pwd)||(pwd1)
msgbox('Please input password','ERROR','error');
else
imfile=get(handles.txt_lokasicitracover,'String');
txfile=get(handles.txt_filepesan,'String');
w='';
k=strcmp(imfile,'input image');
k1=strcmp(imfile,w);
k2=strcmp(txfile,'input message');
k3=strcmp(txfile,w);
if (k)||(k1)
msgbox('Please input image','ERROR','error');
elseif (k2)||(k3)
msgbox('Please input message','ERROR','error');
else
try
file=imread(imfile);
isfile=1;
catch
isfile=0;
end;
try
istxfile=fopen(txfile,'rt');
catch
istxfile=-1;
end;
if(isfile==0)
msgbox('image not found. please browse image','ERROR','error');
elseif(istxfile<0)
msgbox('message file not found. please browse file','ERROR','error');
else
h=waitbar(0,'Embedding...');
for p=1:400, % computation here %
waitbar(p/100);
end;
[psnr,capa,opfile,full,file]=proses_embedd(imfile,txfile);
close(h);
set(handles.txt_nilaipnsr,'String',num2str(psnr));
set(handles.txt_ukuranpesan,'String',num2str(capa));
set(handles.txt_kapasitaspesan,'String',num2str(file));
figure,imshow(imfile);
figure,imshow(opfile);
if (full==0)
msg=strcat(int2str(capa),'bits only embedded please select a large image');
msgbox(msg,'warning','warn');
end;
if (full==1)
msgbox('SUCCESS!!!','SUCCESS');
end;
end;
end;
end;
end
这是将文本嵌入图像的功能
function[psnr,capa,opfile,full,file]= proses_embedd(P1,Q)
P=imread(P1);
[Pm,Pn]=size(P);
I=P;
fid=fopen(Q,'rt');
[X1,co]=fread(fid,'*char');
r=1;
for q=1:co
L(q)=uint8(X1(q));
end;
for q=1:co
W(r:r+7)=dec2bin(L(q),8);
r=r+8;
end;
file=r-1;
x=0;
for i=1:Pm
if x>=(r-1)
break;
end;
for j=1:2:Pn-1
if x>=(r-1)
break;
end;
p11=double(I(i,j));
p21=double(I(i,j+1));
d0=(p11-p21);
if abs(d0)<8
w0=8;
l0=0;
elseif abs(d0)<16&&abs(d0)>7
w0=8;
l0=8;
elseif abs(d0)>15&&abs(d0)<32
w0=16;
l0=16;
elseif abs(d0)>31&&abs(d0)<64
w0=32;
l0=32;
elseif abs(d0)>63&&abs(d0)<128
w0=64;
l0=64;
elseif abs(d0)>127&&abs(d0)<256
w0=128;
l0=128;
else
w0=0;
end;
if(w0>0)
t0=floor(log2(w0));
else
t0=0;
end;
if(t0>0)
if(x<(r-1) && x+t0>(r-1))
b0=bin2dec(W(x+1:(r-1)));
d00=l0+b0;
m0=abs(d00-abs(d0));
if((p11>=p21)&&(d00>abs(d0)))
p00=p11+ceil(m0/2);
p01=p21-floor(m0/2);
end;
if((p11<p21)&&(d00>abs(d0)))
p00=p11-floor(m0/2);
p01=p21+ceil(m0/2);
end;
if((p11>=p21)&&(d00<=abs(d0)))
p00=p11-ceil(m0/2);
p01=p21+floor(m0/2);
end;
if((p11<p21)&&(d00<=abs(d0)))
p00=p11+ceil(m0/2);
p01=p21-floor(m0/2);
end;
block=1;
x=r-1;
end;
if(x+t0)<=(r-1)
b0=bin2dec(W(x+1:x+t0));
d00=l0+b0;
m0=abs(d00-abs(d0));
if((p11>=p21)&&(d00>abs(d0)))
p00=p11+ceil(m0/2);
p01=p21-floor(m0/2);
end;
if((p11<p21)&&(d00>abs(d0)))
p00=p11-floor(m0/2);
p01=p21+ceil(m0/2);
end;
if((p11>=p21)&&(d00<=abs(d0)))
p00=p11-ceil(m0/2);
p01=p21+floor(m0/2);
end;
if((p11<p21)&&(d00<=abs(d0)))
p00=p11+ceil(m0/2);
p01=p21-floor(m0/2);
end;
block=1;
x=x+t0;
end;
end;
if block==1
p0=p00;
p1=p01;
I(i,j)=p0;
I(i,j+1)=p1;
end;
end;
end;
if((i==Pm)&&(j>=Pn-20))
full=0;
else
full=1;
end;
capa=x;
capacity=dec2bin(capa,20);
s=1;
i=Pm;
j=Pn-20;
while(s<21)
temp1=dec2bin(I(i,j),8);
temp1(8)=capacity(s);
I(i,j)=bin2dec(temp1);
s=s+1;
j=j+1;
end;
answer = inputdlg('output image name');
answer1=strcat(answer,'.bmp');
imwrite(I,char(answer1),'bmp');
opfile=char(answer1);
d = mean( (P(:)-I(:)).^2 );
psnr = 10*log10(( 255^2/d) );