Saturday, June 4, 2011

Image Steganography [Matlab code]


Hiding Image in an Image using bit plane technique. This coding is for image steganography. Copy the code and execute in matlab.


%This program hides a message image in the lower
%bit planes of a cover image
%read in cover image filename
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(covername);
message = imread(messagename);

%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

%now add message image and cover image
stego = uint8(coverzero+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,'showmesscolor.bmp'); %use bmp to preserve lower bits

%jpg will get rid of them
%stego file
imwrite(stego,'stegocolor.bmp');

10 comments:

Priyabrata Ghorai said...

Related post

http://pbtstudies.blogspot.com/2011/06/hiding-text-message-in-image-matlab.html

Priyabrata Ghorai said...

Steaganography projects:
http://pbtstudies.blogspot.com/2011/07/high-embedding-capacity-steganography.html

Priyabrata Ghorai said...

to find the performance metrics between two images, check out this matlab code
http://pbtstudies.blogspot.com/2011/07/high-embedding-capacity-steganography.html

NICKU said...

i appreciate your efforts but can you post the reverse also??? that is steganalysis???

Ari Azhari said...

your code is very helpfull for me. thanks. however have u the pvd steganografy code?

Ashwin said...

Hi Priyabrata. thanks for the code.. but there seems to be an error in line stego = uint8(coverzero+messageshift);


can u pls let me know wat to do??

NANDISH slim shady said...

can u tell me execution procedures..?

karthik said...

thnq there is an error in line 40 that is

stego=uint8(coverzero+messageshift);

Unknown said...

Try making the matrices of the images to have the same size. It may be that one picture is of 256*256 and another of 64*64 and they can't be added because of their different sizes :)

Anonymous said...

plz help me out in line no.40 its urgent plz....
stego=uint8(coverzero+messageshift);

Google : The top most search engine

Google : MAGIC BOX

nRelate - Posts and Homepage

LinkWithin

Related Posts Plugin for WordPress, Blogger...

Which is the toughest subject ?