how to hide an image into a cover image using LSB
Afficher commentaires plus anciens
Im not geting the hidden image using this code
clear all;
% read in the cover object you want to use for embedding
file_name='image.bmp';
cover_object=imread(file_name);
% read the message image you want to hide in the cover image
file_name='index.bmp';
message= imread(file_name);
% conversions needed to spread the image values on a 256 gray-scale
message=double(message);
message=round(message./256);
message=uint8(message);
% determine the size of cover image used for embedding
Mc=size(cover_object,1); %Height
Nc=size(cover_object,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));
% title the message object out to cover object size to generate watermark
for ii = 1:Mc
for jj = 1:Nc
watermark(ii,jj)=message(mod(ii,Mm)+1,mod(jj,Nm)+1);
end
end
% set the LSB of cover_object(ii,jj) to the value of the MSB of watermark(ii,jj)
watermarked_image=cover_object;
for ii = 1:Mc
for jj = 1:Nc
watermarked_image(ii,jj)=bitset(watermarked_image(ii,jj),1,watermark(ii,jj));
end
end
% add noise to watermarked image
noisy = imnoise(watermarked_image,'gaussian');
% write to file the two images
imwrite(watermarked_image,'lsb_watermarked.bmp','bmp');
imwrite(noisy,'lsb_watermarked_noise.bmp','bmp');
% display watermarked image
figure(1)
imshow(watermarked_image,[])
title('Watermarked Image')
% display watermarked and noised image
figure(2)
imshow(noisy,[])
title('Watermarked and noised Image')
%Project: Tutorial on Least Significant Bit Substitution
% Watermark Recover
clear all;
% read in watermarked image
file_name='lsb_watermarked.bmp';
watermarked_image=imread(file_name);
% determine size of watermarked image
Mw=size(watermarked_image,1); %Height
Nw=size(watermarked_image,2); %Width
% use lsb of watermarked image to recover watermark
for ii = 1:Mw
for jj = 1:Nw
watermark(ii,jj)=bitget(watermarked_image(ii,jj),1);
end
end
% scale the recovered watermark
watermark=256*double(watermark);
% scale and display recovered watermark
figure(1)
imshow(watermark,[])
%disp(char(watermark))
title('Recovered Watermark')
1 commentaire
Geoff Hayes
le 12 Juin 2014
Crystal - rather than pasting code into your question body, it would be easier to just add the code as an attachment (especially since the above is not formatted as code). That way you can add relevant information to your question - what exactly do you mean by Im not geting the hidden image using this code? what are you getting instead? have you stepped through the code and checked to see if the two images are being manipulated as you expect?
Consider the following
message=double(message);
message=round(message./256);
message=uint8(message);
message is the image you want to hide/embed in the cover image but due to the division by 256 (assuming that its data type is already uint8) it has been reduced to nothing more than 0's or 1's. How do you expect to recover this image after such a reduction in information?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Watermarking dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!