2014-09-05 45 views
-4

我正在隱藏文本到圖像..但我無法得到確切的文本消息回..可以有人plz幫助我在整理的問題和錯誤我的代碼.. K I正在使用的值是2。這裏的代碼如下:錯誤恢復文本隱藏到圖像

clc; 
close all; clear all; 
clf; 
cov_img=imread('pears.png'); 




cov_img1 =rgb2gray(cov_img); 
cov_img1=imresize(cov_img1,[256 256]); 
imshow(cov_img1); 

k=input('enter no of bits '); 
a='In this context, cryptography, steganography and water marking schemes play a vital role in establishing secret communication through encryption, hiding and embedding secret information in digital medium respectively. '; 

b=dec2bin(double(a),8); 
c=b(:); 


d=reshape(c,[],k); 


e=bin2dec(d); 
[m n]=size(e); 


for i=1:256; 
    for j=1:256; 

    S(i,j)=cov_img1(i,j)-mod(cov_img1(i,j),2^k)+e(i,:); 

    j=j+1; 
    end 
    i=i+1; 
end 

figure, imshow(S,[]); 


%%Extraction 

for i=1:256; 
    for j=1:256; 
     E(i,j)=mod(double(S(i,j)),2^k); 
     j=j+1; 
    end 
    i=i+1; 
end 


e1=dec2bin(E,2); 

e2=e1'; 

e3=reshape(e1,[],8); 

e4=bin2dec(e3); 

e5=char(e4); 

disp(e5) 

[mse psnr]=msepsnr(cov_img1,S); 
disp('PSNR value is : '); 
disp(psnr); 
disp(' db'); 
disp('MSE value is'); 
disp(mse); 
%%%%%%% 
+0

看看你的for循環並測試增量方法嗎? – Austin 2014-09-05 19:54:03

+1

你應該解釋你的代碼。你不能粘貼整個代碼並要求人們進行調試。 – 2014-09-05 20:21:36

+0

@ ParagS.Chandakkar我想使用LSB技術將圖像隱藏到圖像中..我部分能夠從圖像中恢復隱藏的文本,但它不是我嵌入的正確文本:( 可能我是在提取過程中做錯了什麼:( – user3801619 2014-09-05 20:38:25

回答

-1

我不完全理解的方法,但你不會得到完整的消息早在e是長度872,而我只運行到256.因此S不會包含您的完整信息。你也不需要在Matlab的for循環中做j = j + 1。以下作品適用於我(即使e的長度在e1的定義中可能未知):

clc; 
close all; clear all; 
clf; 
cov_img=imread('pears.png'); 

cov_img1 =rgb2gray(cov_img); 
cov_img1=imresize(cov_img1,[256 256]); 
imshow(cov_img1); 

k=2; 
a='In this context, cryptography, steganography and water marking schemes play a vital role in establishing secret communication through encryption, hiding and embedding secret information in digital medium respectively. '; 
b=dec2bin(double(a),8); 
c=b(:); 
d=reshape(c,[],k); 
e=bin2dec(d); 
[m n]=size(e); 

Z = zeros(256); 
Z(1:length(e)) = e; 
for i=1:256; 
    for j=1:256; 

    S(i,j)=cov_img1(i,j)-mod(cov_img1(i,j),2^k)+Z(i,j); 

    end 

end 
figure, imshow(S,[]); 
%%Extraction 
for i=1:256; 
    for j=1:256; 
     E(i,j)=mod(double(S(i,j)),2^k)'; 

    end 

end 
e1=dec2bin(E(1:length(e)),2); 
e2=e1; 
e3=reshape(e2,[],8); 
e4=bin2dec(e3); 
e5=char(e4); 
disp(e5') 
+0

這段代碼與問題中的代碼有什麼不同?除了刪除'j = j + 1'? – Schorsch 2014-09-06 16:54:14

+1

在原文中,'S'的每一行都與'e'中的前256個祕密位相同。在這裏,矩陣'Z'與'cov_img1'具有相同的大小,並且第一個'length(e)'元素保存所有的祕密位,根據需要包裝到下一行/列,以包含它們全部。那麼將它們嵌入'S'中是微不足道的。 – Reti43 2014-09-06 23:36:52

+0

@Schorsch,你是對的,大多數是副本。我最初沒有粘貼任何代碼,但認爲提供快速解決方案會有所幫助。我不會重寫所有的東西。感謝您回答Reti43。作爲進一步的評論,for循環可能不是必需的,因爲for循環中的所有操作隻影響單個元素,而mod則需要矩陣。 – 2014-09-07 18:54:00