2014-01-27 61 views
0

圖3顯示後,此代碼有問題。這兩個圖像沒有被添加。如何糾正?這個程序隱藏在封面圖片的文件名讀取封面圖像的下位平面的消息圖像圖像隱寫 - 在圖像中隱藏圖像

%covername = input('Enter image file name with extension (like jennifer.bmp): ', 's'); 
%read in message image filename 
%messagename = input('Enter message image file name with extension: ', 's'); 
%open cover and message image files 
cover = imread('hand.jpg'); 
message = imread('coins.png'); 
%display on screen the two images 
figure(1), imshow(cover); title('Original Image (Cover Image)'); 
figure(2), imshow(message);title('Image to Hide (Message Image)'); 
%change to double to work with addition below 
cover=double(cover); 
message=double(message); 
%imbed = no. of bits of message image to embed in cover image 
imbed=4; 
%shift the message image over (8-imbed) bits to right 
messageshift=bitshift(message,-(8-imbed)); 
%show the message image with only embed bits on screen 
%must shift from LSBs to MSBs 
showmess=uint8(messageshift); 
showmess=bitshift(showmess,8-imbed); 
figure(3),imshow(showmess);title('4 Bit Image to Hide'); 
%now zero out imbed bits in cover image 
coverzero = cover; 
for i=1:imbed 
coverzero=bitset(coverzero,i,0); 
end 
cove=uint8(coverzero); 
%now add message image and cover image 
stego = imadd(cove,messageshift); 
figure(4),imshow(stego);title('Stego image'); 
%save files if need to 
%4 bit file that was embedded = same as file extracted 
imwrite(showmess,'showmess4.bmp');   
%use bmp to preserve lower bits 
%jpg will get rid of them 
%stego file imwrite(stego,'stego4.bmp'); 

回答

1

我相信你的問題是imadd爲您提供了錯誤的「X和Y必須具有相同的尺寸和類或Y必須是一個標量雙「。這暗示你的圖像不相似。

如果你做whos cove messageshift,你會看到cove是class uint8,而messageshift是double。只是轉換messageshift在16行UINT8,像你這樣的小海灣做:

messageshift=uint8(bitshift(message,-(8-imbed)));

+0

是非常感謝你 – user3219263