Send Your Paper/Abstract to nsallinone@gmail.com for Implementation/Guidance
Showing posts with label Matlab. Show all posts
Showing posts with label Matlab. Show all posts

Wednesday, 12 February 2014

Forgery Image Detection (Image Authentication) in Matlab



Introduction:

Nowadays, digital images and video are gradually replacing their conventional analog counterparts .This is quite understandable because digital format is easy to edit, modify, and exploit. Digital images and videos can be readily shared via computer networks and conveniently processed for queries in databases. Also, digital storage does not age or degrade with usage. On the other hand, thanks to powerful editing programs, it is very easy even for an amateur to maliciously modify digital media and create "perfect" forgeries. It is usually much more complicated to tamper with analog tapes and images.

Robust authentication scheme:

here is a scheme to ensure the authenticity of digital images is presented. Their authentication technique is able to detect malicious tamperingof images even if they have been incidentally distorted by common image processingoperations.

Code:


Step 1: (Gaussian window function)
 function [window]=gaussian_window()  
% gaussian window
N_window=7; % window length
sigma=1;
[x, y] = meshgrid(-(ceil(sigma*2)):4*sigma/(N_window-1):ceil(sigma*2));
window = (1/(2*pi*sigma^2)).*exp(-0.5.*(x.^2+y.^2)./sigma^2);
return

Step 2: (Function to calculate Variance)


 function [var_map] = getVarianceMap(im,Bayer,dim)  

% extend pattern over all image

pattern = kron(ones(dim(1)/2,dim(2)/2), Bayer);


% separate acquired and interpolate pixels for a 7x7 window

mask = [1, 0, 1, 0, 1, 0, 1;
0, 1, 0, 1, 0, 1, 0;
1, 0, 1, 0, 1, 0, 1;
0, 1, 0, 1, 0, 1, 0;
1, 0, 1, 0, 1, 0, 1;
0, 1, 0, 1, 0, 1, 0;
1, 0, 1, 0, 1, 0, 1];

% gaussian window fo mean and variance

window = gaussian_window().*mask;
mc = sum(sum(window));
vc = 1 - (sum(sum((window.^2))));
window_mean = window./mc;

% local variance of acquired pixels

acquired = im.*(pattern);
mean_map_acquired = imfilter(acquired,window_mean,'replicate').*pattern;
sqmean_map_acquired = imfilter(acquired.^2,window_mean,'replicate').*pattern;
var_map_acquired = (sqmean_map_acquired - (mean_map_acquired.^2))/vc;

% local variance of interpolated pixels

interpolated = im.*(1-pattern);
mean_map_interpolated = imfilter(interpolated,window_mean,'replicate').*(1-pattern);
sqmean_map_interpolated = imfilter(interpolated.^2,window_mean,'replicate').*(1-pattern);
var_map_interpolated = (sqmean_map_interpolated - (mean_map_interpolated.^2))/vc;


var_map = var_map_acquired + var_map_interpolated;


return

Step 3: (Output)





Wednesday, 5 February 2014

Face Recognition using Local Sparse Representaion in Matlab



The Below tutorial is regarding Face Recognition  Implementation using Local sparse representation in matlab.


Step 1:


           Create GUI in matlab using the below code.



function varargout = FR_Processed_histogram(varargin)

gui_Singleton = 1;

gui_State = struct('gui_Name',       mfilename, ...

                   'gui_Singleton',  gui_Singleton, ...

                   'gui_OpeningFcn', @FR_Processed_histogram_OpeningFcn, ...

                   'gui_OutputFcn',  @FR_Processed_histogram_OutputFcn, ...

                   'gui_LayoutFcn',  [] , ...

                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

%--------------------------------------------------------------------------
% --- Executes just before FR_Processed_histogram is made visible.
function FR_Processed_histogram_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to FR_Processed_histogram (see VARARGIN)

% Choose default command line output for FR_Processed_histogram
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes FR_Processed_histogram wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global total_sub train_img sub_img max_hist_level bin_num form_bin_num;

total_sub = 40;
train_img = 200;
sub_img = 10;
max_hist_level = 256;
bin_num = 9;
form_bin_num = 29;
%--------------------------------------------------------------------------
% --- Outputs from this function are returned to the command line.
function varargout = FR_Processed_histogram_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

%--------------------------------------------------------------------------
% --- Executes on button press in train_button.  
function train_button_Callback(hObject, eventdata, handles)
% hObject    handle to train_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global train_processed_bin;
global total_sub train_img sub_img max_hist_level bin_num form_bin_num;

train_processed_bin(form_bin_num,train_img) = 0;
K = 1;
train_hist_img = zeros(max_hist_level, train_img);

for Z=1:1:total_sub 
  for X=1:2:sub_img    %%%train on odd number of images of each subject
    
    I = imread( strcat('ORL\S',int2str(Z),'\',int2str(X),'.bmp') );        
    [rows cols] = size(I);
    
    for i=1:1:rows
       for j=1:1:cols
           if( I(i,j) == 0 )
               train_hist_img(max_hist_level, K) =  train_hist_img(max_hist_level, K) + 1;                            
           else
               train_hist_img(I(i,j), K) = train_hist_img(I(i,j), K) + 1;                         
           end
       end   
    end   
     K = K + 1;        
  end  
 end  

[r c] = size(train_hist_img);
sum = 0;
for i=1:1:c
    K = 1;
   for j=1:1:r        
        if( (mod(j,bin_num)) == 0 )
            sum = sum + train_hist_img(j,i);            
            train_processed_bin(K,i) = sum/bin_num;
            K = K + 1;
            sum = 0;
        else
            sum = sum + train_hist_img(j,i);            
        end
    end
    train_processed_bin(K,i) = sum/bin_num;
end

display ('Training Done')
save 'train'  train_processed_bin;

%--------------------------------------------------------------------------
% --- Executes on button press in Testing_button.    
function Testing_button_Callback(hObject, eventdata, handles)
% hObject    handle to Testing_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global train_img max_hist_level bin_num form_bin_num;
global train_processed_bin;
global filename pathname I

load 'train'
test_hist_img(max_hist_level) = 0;
test_processed_bin(form_bin_num) = 0;


 [rows cols] = size(I);
  
    for i=1:1:rows
       for j=1:1:cols
           if( I(i,j) == 0 )
               test_hist_img(max_hist_level) =  test_hist_img(max_hist_level) + 1;                            
           else
               test_hist_img(I(i,j)) = test_hist_img(I(i,j)) + 1;                         
           end
       end   
    end   
    
  [r c] = size(test_hist_img);
  sum = 0;

    K = 1;
    for j=1:1:c        
        if( (mod(j,bin_num)) == 0 )
            sum = sum + test_hist_img(j);            
            test_processed_bin(K) = sum/bin_num;
            K = K + 1;
            sum = 0;
        else
            sum = sum + test_hist_img(j);            
        end
    end
  
 test_processed_bin(K) = sum/bin_num;
    
sum = 0;
K = 1;

    for y=1:1:train_img
        for z=1:1:form_bin_num        
          sum = sum + abs( test_processed_bin(z) - train_processed_bin(z,y) );  
        end         
        img_bin_hist_sum(K,1) = sum;
        sum = 0;
        K = K + 1;
    end

    [temp M] = min(img_bin_hist_sum);
    M = ceil(M/5);
    getString_start=strfind(pathname,'S');
    getString_start=getString_start(end)+1;
    getString_end=strfind(pathname,'\');
    getString_end=getString_end(end)-1;
    subjectindex=str2num(pathname(getString_start:getString_end));
    if (subjectindex == M)
      axes (handles.axes3)
      %image no: 5 is shown for visualization purpose
      imshow(imread(strcat('ORL\S',num2str(M),'\5.bmp')))    
      msgbox ( 'Correctly Recognized');
    else
     display ([ 'Error==>  Testing Image of Subject >>' num2str(subjectindex) '  matches with the image of subject >> '  num2str(M)])
     axes (handles.axes3)
     %image no: 5 is shown for visualization purpose
     imshow(imread(strcat('ORL\S',num2str(M),'\5.bmp')))    
     msgbox ( 'Recognized');
    end
display('Testing Done')

Step 2:


Run the matlab function and add the database images to path and train the images using train button.




Step 3:


      Now Select the input image button to locate input image.





          

Step 4:




             Click the Testing button to get the recognized images from database.



Note:
          You should download the database before running the code. Instruction to download the database is in the comment section of the file.

Tuesday, 28 January 2014

Soccer Game in matlab

This a Post related to Create simple gaming in Matlab environment.

To do the below things you need Matlab with Visual C++ compiler and True time Packages.

You can download true time packages from http://www.control.lth.se/truetime


Add the above folder into matlab execution path.

run the socceer.mdl file under examples\soccer folder.

The ouputs will be like below,