Can anyone Help me with the Errors in this code? It's about Face Recognition using Eigenfaces

function varargout = FaceRec(varargin)
gui_Singleton =1;
gui_State = struct('gui_Name' mfilename, ...
'gui_Singleton', gui_Singleton; ...
'gui_OpeningFcn' @FaceRec_OpeningFcn, ...
'gui_OutputFcn' @FaceRec_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 FaceRec is made visible
function FaceRec_OpeningFcn(hObject,~, handles, varargin)
%Choose default command line output for FaceRec
handles.output = hObject;
set(handles.axes1,'visible','off');
set(handles.axex4,'visible','off');
set(handles.axex10,'visible','off');
%providing background image
b=imread('icons\logo.png');
axes(handles.axes1);
imshow(b);
na=axes('unit', 'normalized', 'position', [0,0,1,1]); %to ensure to cover complete GUI
set(na,'handlevisibility','off','visible','off');
uistack(na,'bottom') %stacking the background to bottom of all taxes
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line
function varargout = FaceRec_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
%taking images
function In_image_Callback(hObject, eventdata, handles)
global x
[filename, pathname] = uigetfile ('*.jpg',Load Image');
if filename == 0
msgbox('Please Choose Image','Error','error');
return
end
x = imread(filename);
axes(handles.axes4);
imshow(x);
title('Input Image','fontsize',18);
loc=strcat(pathname,filename);
set(handles.edit2,'string',loc);
%checking
load('mat1.mat');
load('mat2.mat');
% Acquiring new image
InputImage = x;
I1=InputImage;
[row, col, colorchannel] = size(InputImage);
if colorchannel > 1
InputImage=imresize(InputImage,[256,256]);
InputImage=rgb2gray(InputImage);
end
[irow, icol]=size(InputImage);
InImage=reshape(double(InputImage), irow*icol,1);
temp=InImage;
me=mean(temp);
st=std(temp);
temp=(temp-me)*ustd/st+um;
NormImage = temp;
Difference = temp-m;
p = [];
aa= size(u,2);
for i =aa
pare = dot(NormImage,u(:,i));
p = [p; pare];
end
ReshapedImage = m+u(:,1:aa)*p; %m is the mean image,u is the eigen value
ReshapedImage = reshape(ReshapedUmage,icol,irow);
ReshapedImage = ReshapedImage';
%show the reconstructed image
axes(handles.axes10);
cpy=imagesc(ReshapedImage);
colormap('gray'); title('Reconstructed image','fontsize',18);
for i = 1:54
str=strcat(int2str(i),'.jpg');
eval('img==imread(str);');
if(img==cpy)
set(handles.edit2,'string',str);
end
end
%guidata(hObhect,handles);
InImWeight=[];
for i=1:size(u,2)
t=u(:,i)';
WeightOfInputImage=dot(t,Difference');
InImWeight=[InImWeight; WeightOfInputImage];
end
%Find Euclidean distance
e=[];
for i=1:size(omega,2)
q=omega(:,i);
Diffweight=InImWeight-q;
mag=norm(DiffWeight);
e=[e mag];
end
MaximumValue=max(e); %Maximum eculidian Diatance
MinimumValuea=min(e); %minimum eculidian distance
[cdata1]=imread('icons\error.ico'); %setting icons in msgbox
[cdata2]=imread('icons\vsm.png');
if(MinimumValue>2.9000e+04)&&(MinimumValue<3.2200e+04)
msgbox('Present in database','Image Found','custom',cdata2);
else
msgbox('Not Present in database','Image not Found','custom',cdata1);
end
%----Executes on button press in terminate.
function terminate_Callback(hObject,evendata,handles)
exit();
function edit2_Callback(hObject,evendata,handles)
%---Executes during object creation,after setting all properties.
function edit_2CreateFcn(hObject,~,handles)
if ispc && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'Backgroundcolor','white');
end
%--- Executes when user attempts to close figure1
function figure1_CloseRequestFcn(hObject,evendata,handles);
delete(hObject);
clc
%----Executes when figure1 is resized
function figure1_ResizeFcn(hObject,evendata,handles);

Answers (2)

You have

gui_State = struct('gui_Name'       mfilename, ...
                 'gui_Singleton', gui_Singleton; ...
                 'gui_OpeningFcn' @FaceRec_OpeningFcn, ...
                 'gui_OutputFcn'  @FaceRec_OutputFcn, ...
                 'gui_LayoutFcn'  [] , ...
                 'gui_Callback',  []);

You need commas between all of the parts, and the semi-colon needs to be a comma

gui_State = struct('gui_Name',       mfilename, ...
                 'gui_Singleton', gui_Singleton, ...
                 'gui_OpeningFcn', @FaceRec_OpeningFcn, ...
                 'gui_OutputFcn',  @FaceRec_OutputFcn, ...
                 'gui_LayoutFcn',  [] , ...
                 'gui_Callback',  []);

You have

    [filename, pathname] = uigetfile ('*.jpg',Load Image');

You are missing the opening ' for the second string

    [filename, pathname] = uigetfile ('*.jpg','Load Image');

You have

eval('img==imread(str);');

That asks to compare img to the result of imread(). That is a problem because img is probably not defined at that point. But it might be defined, depending on exactly which variables were in the two .mat that you load()'d.

You should probably change that to

img = imread(str);

Warning: the files you are trying to read might not be in the current directory...

You have

cpy=imagesc(ReshapedImage);

That leaves cpy as being the handle to an image() object that is displaying that image.

You have

      if(img==cpy)

but it looks like img is intended to be the result of reading the file in as data. The image data is never going to equal the graphics handle. I do not know what you were trying to do there.

Categories

Find more on Weather and Atmospheric Science in Help Center and File Exchange

Tags

Asked:

on 20 Apr 2018

Community Treasure Hunt

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

Start Hunting!