Problems with Matlab Projects? You may face many Problems, but do not worry we are ready to solve your Problems. All you need to do is just leave your Comments. We will assure you that you will find a solution to your project along with future tips. On Request we will Mail you Matlab Codes for Registered Members of this site only, at free service...Follow Me.

Image Hider using MATLAB


HIDE A PHOTO INSIDE ANOTHER


This program will hide one image file inside another.

Working: 

Encoder:


First it asks for the two image files. You should enter the filenames with their extensions ,Then the program hides the second image in the first one. For this the last nibble (last four bits) of the first file will be replaced by the first nibble (first 4 bits) of the second image.The resultant image has higher energy for first image. So the hidden image hardly seen.During the process it asks for a name for coded image then the name given shouldn't have any extension.The coded image is saved as BMP instead of JPEG because the JPEG files are compressed images.So while compressing the hidden image will be affected.If the two images are not in the same resolution then the program itself will change the resolution of first image by second.

Decoder:


The image file name given should have extension. The program will do the reverse process of the encoding.



Example photos:


Image 1:




Image 2: (Image to be hid)



Image 3: Encoded image (Image 2 is present inside this)



Decoding image 3 and the decoded images as follows








Download: Hide image.rar



Example :

***** IMAGE HIDER*****
___Program for hidimg one image inside the other image___

_________________________________________________________
---Encode :- 1
---Decode :- 2
Enter your task:1
Welcome to Encoder
Enter the first image file name: vegas_fr.jpg
Enter the second image file name: 54.jpg
Do you want to save the file y/n [y] y
Enter a name for the encoded image: codedvegas
>>

The MATLAB program follows:

-------------------------------------------------------------------------------------------------------------------------------------------------
% Program for hiding an image inside the other
%By% Mr. vipin.p.nair% College of Engineering Kallooppara
% vipinpn@yahoo.com
% 06-Nov-2008
%*****************************************************
clc;
disp(' ');
disp(' ***** IMAGE HIDER*****');
disp('___Program for hidimg one image inside the other image___');
disp(' ');
disp('_________________________________________________________');
task = input('---Encode :- 1 \n---Decode :- 2\n Enter your task:');
% select task
if isempty(task)
task=1;
end
if task == 1
% reads two image files


x = imread(input(' Welcome to Encoder\n Enter the first image file name: ','s'));
y = imread(input(' Enter the second image file name: ','s'));

% check compatibility
sx = size(x);
sy = size(y);
if (sx(1) ~= sy(1))(sx(2)~=sy(2))
x=imresize(x,[sy(1),sy(2)]);
end


%
% clearing Ist files lsb bits & moving IInd files msbits bits to lsbits
x1 = bitand(x,uint8(240));
y1 = bitshift(y,-4);

% inserting IInd to Ist file
z=bitor(x1,y1);

% display the first image
figure(1)
image(x);
xlabel(' Ist Image ');

% display IInd image
figure(2);
image(y);
xlabel(' IInd Image ');

% display encoded image
figure(3);
image(z);
xlabel(' Encoded Image ');
% saving file
sav=input('Do you want to save the file y/n [y] ','s');
if isempty(sav)
sav='y';
end
if sav == 'y'
name=input('Enter a name for the encoded image: ','s');
if isempty(sav)
name='encoded_temp';
end
name=[name,'.bmp']; % concatination
imwrite(z,name,'bmp');
end

else
% Decoding encoded image
z=imread(input(' Welcome to Decoder\n Enter the image file to be decoded:','s'));

% xo is fist file- obtained by clearing lsb bits, yo is IInd file right
% shifting z by 4 bits
xo=bitand(z,uint8(240));
yo=bitshift(z,4);

% display Ist & IInd image from encoded image
figure(4);
image(xo);
xlabel('Ist Decoded Image ');
figure(5);
image(yo);
xlabel('IInd Decoded Image');

% saving file
sav=input('Do you want to save the file y/n [y] ','s');
if isempty(sav)
sav='y';
end
if sav == 'y'
name1=input('Enter a name for the first image: ','s');
name2=input('Enter a name for the second image: ','s');
if isempty(name1)
name1 = 'Ist_temp';
end
if isempty(name2)
name2 = 'IInd_temp';
end


Hide an image file inside another image file :-high quality version


This is a MATLAB based program. Image hider 2.0 is the second part of Image Hider 1.0. Image hider 2.0 is a high quality version. This software helps you to hide one image (photo) in to another image (photo). Suppose image2 is the image to be hid on image1 and the encoded image is image3. Then all the pixel details present in the image2 were encoded in to the image1. So the quality of the image2 will not be affected. Only two bits in every pixels of the image1 is used for encoding. And so the encoded image do not show any patches of the image2. So others will never suspect that image3 as encoded or it may contain any secrets.
The bits in every pixel of the image2 is split into four and placed in four different locations in image1. So it provides some sort of encryption too. So it will be hard for others to decode the hidden image.It supports formats like JPG, BMP etc


    Example: Encoding section
    Image1.jpg :- image on which the encoding to be done
    Image2: Image to be hid
    Image3: the encoded image
    Example: Decoding section - using the above encoded image
    Decoded image1: extracted image from image3.bmp
    Decoded image2: hidden image in image3.bmp


MATLAB Program:


% Program for hiding an image inside the other
% high quality version
%By vipin.p.nair
% College of Engineering Kallooppara
% Kerala, India
% vipinpn@yahoo.com
%01-may-2009
%*****************************************************
% ---Only two bit in pixel of the image 1 is affected
% ---image2 is split & store in two diagonally opposite quadrants
% Algorithm
% the fist image is resize to double its original size
% logically the image is divided to four partitions
% the bits of the image to be hid is stored in the first image as
% shown below
% |-------------|
% |d7,d6 |d3,d2 |
% |-------------|
% |d1,d0 |d5,d4 |
% |____________|
% ****************program********************
clc; % clear the command window
clear; % clear the workspace
disp(' ');
disp(' ***** IMAGE HIDER 2.0 *****');
disp('___Program for hidimg one image inside the other image___');
disp(' ');
disp('_________________________________________________________');
task = input('---Encode :- 1 \n---Decode :- 2\n Enter your task:');
% select task
if isempty(task)
task=1;
end
if task == 1
% reads two image files
x = imread(input(' Welcome to Encoder\n Enter the first image file name: ','s'));
y = imread(input(' Enter the second image file name: ','s'));
% check compatibility
sx = size(x);
sy = size(y);
%if (sx(1) ~= sy(1))|(sx(2)~=sy(2))
x=imresize(x,[2*sy(1),2*sy(2)]);
% end
%sy=2*sy;
%
% clearing Ist files last two lsb bits & moving IInd files msb bits to lsb bits
x1 = bitand(x,uint8(252));
y1 = bitshift(y,-4);
y1_= bitand(y1,12);
y1_= bitshift(y1_,-2); % y1_ has D6 & D7
y1 = bitand(y1,3); % Y1 HAS D4,D5
% clearing II image's msb bits
y_lsb1 = bitshift(bitand(y,12),-2);
y_lsb2 = bitand(y,3);
% inserting IInd to Ist file
z=x1;
for j=1:sy(2) % y variation
for i=1:sy(1) % x variation
for k=1:3
% IInd quadrent
z(i,j,k) = bitor(x1(i,j,k), y1_(i,j,k));
% IV th quadrent
z(i+sy(1),j+sy(2),k) = bitor(x1(i+sy(1),j+sy(2),k), y1(i,j,k));
% I st quadrent
z(i+sy(1),j,k) = bitor(x1(i+sy(1),j,k), y_lsb1(i,j,k));
% IIIrd quadrent
z(i,j+sy(2),k) = bitor(x1(i,j+sy(2),k), y_lsb2(i,j,k));
end
end
end
% display the first image
figure(1)
image(x);
xlabel(' Ist Image ');
% display IInd image
figure(2);
image(y);
xlabel(' IInd Image ');
% display encoded image
figure(3);
image(z);
xlabel(' Encoded Image ');
% saving file
sav=input('Do you want to save the file y/n [y] ','s');
if isempty(sav)
sav='y';
end
if sav == 'y'
name=input('Enter a name for the encoded image: ','s');
if isempty(sav)
name='encoded_temp';
end
name=[name,'.bmp']; % concatination
imwrite(z,name,'bmp');
end
else
% Decoding encoded image
clear;
z=imread(input(' Welcome to Decoder\n Enter the image file to be decoded:','s'));
sy = size(z)/2; % take the size of input file
% xo is fist file- obtained by clearing lsb bits, yo is IInd file right
% shifting z by 4 bits
xo=bitand(z,uint8(252));
xo=imresize(xo,[sy(1),sy(2)]); % reduce the resolution to half so
%that it becoms the original image's resolution
for j=1:sy(2) % y variation
for i=1:sy(1) % x variation
for k=1:3
zout1(i,j,k) = bitshift(bitand(z(i,j,k),uint8(3)),2);
zout2(i,j,k) = bitand(z(i+sy(1),j+sy(2),k), uint8(3));
zout3(i,j,k) = bitshift(bitand(z(i+sy(1),j,k),uint8(3)),2);
zout4(i,j,k) = bitand(z(i,j+sy(2),k),uint8(3));
end
end
end
zout = bitshift((zout1+zout2),4)+zout3+zout4;
yo = zout;
% display Ist & IInd image from encoded image
figure(4);
image(xo);
xlabel('Ist Decoded Image ');
figure(5);
image(yo);
xlabel('IInd Decoded Image');
% saving file
sav=input('Do you want to save the file y/n [y] ','s');
if isempty(sav)
sav='y';
end
if sav == 'y'
name1=input('Enter a name for the first image: ','s');
name2=input('Enter a name for the second image: ','s');
if isempty(name1)
name1 = 'Ist_temp';
end
if isempty(name2)
name2 = 'IInd_temp';
end
name1 = [name1,'.bmp'];
name2 = [name2,'.bmp'];
imwrite(xo,name1,'bmp');
imwrite(yo,name2,'bmp');
end
end

1 comments:

ma said...

how to calculate the psnr since the stego image is of different size from cover image?

Post a Comment

Recent Comments

Popular Matlab Topics

Share your knowledge - help others

Crazy over Matlab Projects ? - Join Now - Follow Me

Sites U Missed to Visit ?

Related Posts Plugin for WordPress, Blogger...

Latest Articles

Special Search For Matlab Projects

MATLAB PROJECTS

counter

Bharadwaj. Powered by Blogger.