Code for hiding a Larger black and white image in a smaller colour image

1 回表示 (過去 30 日間)
chaithra
chaithra 2014 年 2 月 25 日
コメント済み: Image Analyst 2014 年 2 月 25 日
i have written a matlab code for hiding a larger black and white image in a smaller colour image by setting the the first bit of black and white image in lsb of r component , 2nd bit in lsb of g component and 3rd bit in lsb of b component of the colour image and so on. but only half the image is being recovered.how do i correct it?
% read in the cover object you want to use for embedding
file_name='ballon.png';
cover_object=imread(file_name);
cover_object=imresize(cover_object,[200 200]);
cr=cover_object(:,:,1);
cg=cover_object(:,:,2);
cb=cover_object(:,:,3);
% read the message image you want to hide in the cover image
file_name='baboon.bmp';
message=imread(file_name);
message=imresize(message,[600 600]);
% conversions needed to spread the image values on a 256 gray-scale
message=double(message);
message=round(message/256);
figure(1),imshow(message),title('message');
message=uint8(message);
% determine the size of cover image used for embedding
Mc=size(cr,1); %Height
Nc=size(cr,2); %Width
% determine the size of message object to embed
Mm=size(message,1); %Height
Nm=size(message,2); %Width
%y = uint8(wgn(Mm,Nm,1));
% set the LSB of cover_object(ii,jj) to the value of the MSB of watermark(ii,jj)
wr=cr;
wg=cg;
wb=cb;
i=1;
j=1;
for ii= 1:Mc
for jj = 1:Nc
wr(ii,jj)=bitset(wr(ii,jj),1,message(i,j));
wg(ii,jj)=bitset(wg(ii,jj),1,message(i+1,j));
wb(ii,jj)=bitset(wb(ii,jj),1,message(i+2,j));
if j == Nm
j=1;
i=i+3;
else
j=j+1;
end
end
end
message_image=cat(3,wr,wg,wb);
% write to file the image
imwrite(message_image,'lsb_message.bmp','bmp');
% display encoded image
figure(2)
imshow(message_image,[])
title('encoded Image')
//Decryption
% read in encoded cover image
file_name='lsb_message.bmp';
message_image=imread(file_name);
% determine size of encoded cover image
Mw=size(message_image,1); %Height
Nw=size(message_image,2); %Width
enc=message_image;
er=enc(:,:,1);
eg=enc(:,:,2);
eb=enc(:,:,3);
% use lsb of encoded cover image to recover message
for ii = 1:Mw
for jj = 1:Nw
msg(i,j)=bitget(er(ii,jj),1);
msg(i+1,j)=bitget(eg(ii,jj),1);
msg(i+2,j)=bitget(eb(ii,jj),1);
if j == Nm
j=1;
i=i+3;
else
j=j+1;
end
end
end
% scale the recovered message image
msg=256*double(msg);
% scale and display recovered message image
figure(1)
imshow(msg)
title('Recovered image');

回答 (1 件)

Image Analyst
Image Analyst 2014 年 2 月 25 日
I'd guess by stepping through the code to see exactly what it's doing and where it might be going wrong. See http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by