Discussion:
face recognition using ica codes......please help me debug this code
(too old to reply)
Suzzie
2011-03-31 21:09:08 UTC
Permalink
Raw Message
%Script align_Faces
%
%LabelDir is where Labels.mat is.
%imgDir is where the original images are
%DestDir is where you want the cropped jpegs to go.


LabelDir = '/Users/suzzie/Desktop/FINAL CODE PROJECT 2011/';
ImgDir = '/Users/suzzie/Desktop/FINAL CODE PROJECT 2011/FaceImages/';
DestDir = '/Users/suzzie/Desktop/FINAL CODE PROJECT 2011/AlignFaceImages/';

homeDir = pwd;


%XS = YS = %Size of desired cropped image
%EY = %Number of pixels desired between the EY
%TE = %Desired no. of pixels from teeth to EY.


XS = 240;
YS = 292;
EY = 130;
TE = 165;



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Here is where we load the images and do the preprocessing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

cd(LabelDir)
load Labels
cd(ImgDir)
r = dir;

for i = 3:(size(r,1))
t = r(i).name;

%[X,map] = imread(t);
I=imread(imgName);
I=rgb2gray(I);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Extract face measurements
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%dxEY = x distance between EY in original image
%dyEY = y distance between EY in original image
%dEEY = Euclidean norm distance between EY
%dETE = Euclidean norm distance from teeth to midpt between EY

[height, width] = size(I);
dxEY = marks(i-2,3) - marks(i-2,1);
dyEY = marks (i-2,4) - marks(i-2,2);
dEEY = sqrt(dxEY^2 + dyEY^2);
mean_eye_x = mean([marks(i-2,1), marks(i-2,3)]);
mean_eye_y = mean([marks(i-2,2), marks(i-2,4)]);
dETE = sqrt((marks(i-2,5)-mean_eye_x)^2 + (marks(i-2,6)-mean_eye_y)^2);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%scale
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
yscale = TE / dETE; xscale = EY / dEEY;
height_new = yscale*height; width_new = xscale*width;
tmp0=imresize(I,[height_new,width_new],'bicubic');



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%rotate
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Reye_x = marks(i-2,1);
Reye_y = marks(i-2,2);


W = 500; %For bigger images

%Zero-pad to make sure window never falls outside of image.

padcols = zeros(size(tmp0,1),W);
padrows = zeros(W,size(tmp0,2)+W);
padcols = uint8(padcols);
padrows=uint8(padrows);
tmp = [padrows;padcols,tmp0];


tmpx = xscale*Reye_x - W +W; tmpy = yscale*Reye_y - W +W;
tmp1 = imcrop(tmp,[tmpx,tmpy,2*W,2*W]);
%figure(2);imshow(tmp1)

angle = 180/pi*atan((yscale*dyEY)/(xscale*dxEY));
tmp2 = imrotate(tmp1,angle,'bicubic','crop');
%figure(2); imshow(tmp2);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%crop
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Reye is centered at (W,W) = (100,100).
% For bigger images (W,W) = (500,500)

x = W - (XS-EY)/2;

%y = W - YS/2;
%EY at midpoint

y = W - YS*1/3; %Face box
tmp3=imcrop(tmp2,[x,y,XS,YS]);
figure(1); imshow(tmp3);

%save
[imgName, R] = strtok(imgName, '.');
fname = [DestDir,imgName, '.pgm'];
imwrite(tmp3,fname,'pgm')
end

error:
??? Undefined function or variable 'imgName'.

Error in ==> aligningfaces at 40
I=imread(imgName);
------------------------------------------------------------------------------------------------------------------------------------------------------------------

%Script FeatureMarking
%For marking eye and mouth positions in face images.
%Writes a file called Labels.mat, in which each row indexes an image, and
%the columns are [x,y] positions of subject's right eye, [x,y] left eye,
%and [x,y] of mouth.


ImgDir = '/Users/suzzie/Desktop/FINAL CODE PROJECT 2011/FaceImages/';
DestDir = '/Users/suzzie/Desktop/FINAL CODE PROJECT 2011/AlignFaceImages/';


cd(ImgDir)
r = dir;




%mark feature


marks = [];
for i = 3:(size(r,1))
t = r(i).name;
% [X,map] = imread([ t ]);

figure(1);
colormap gray;
if isfloat(X)
image(gray2ind(mat2gray((X))));
else
image(X);
end
title(t);
disp 'Click the right eye, left eye, then mouth.'

[m,n] = ginput(3);
pos = round([m,n]);
pos = reshape(pos',1,6);
marks = [marks; pos];
end

cd(DestDir)
save Labels marks r

error:
error:
??? Undefined function or variable 'imgName'.

Error in ==> aligningfaces at 40
I=imread(imgName);

------------------------------------------------------------------------------------------------------------------------------------------------------------------
%Script LoadFace

function C = LoadFace(~);
%Loads a directory of images into the rows of C.
%ImgDir is a string with the path to the directory containing the images.

ls(ImgDir)
r =dir;

C = [];
for i = 3:(size(r,1))
t = r(i).name;
I=imread(t);
tmp=mat2gray(double(I));
tmp = reshape(tmp,1,size(tmp,1)*size(tmp,2));
C = [C;tmp];
end


error:
??? Error using ==> imread at 385
Unable to determine the file format.

Error in ==> LoadFace at 16
I=imread(t);
ImageAnalyst
2011-03-31 21:14:27 UTC
Permalink
Raw Message
Why do you think "imgName" should have a value when you never assigned
it?
Suzzie
2011-03-31 22:39:04 UTC
Permalink
Raw Message
Post by ImageAnalyst
Why do you think "imgName" should have a value when you never assigned
it?
i have tried doing that but i keep on getting a different error.
ImageAnalyst
2011-04-01 02:54:17 UTC
Permalink
Raw Message
And you will keep getting an error until you assign some value for
imgName. But you say you have a different error now. But for some
reason you didn't give the different error. Perhaps you're going to
figure it out on your own by learning how to use the debugger.
e***@gmail.com
2018-02-12 10:00:40 UTC
Permalink
Raw Message
load Labels


##### hello, I have an error in this line:

Error using load
Unable to read file 'Labels'. No such file or directory.

Error in align_Faces (line 30)
load Labels


#### can you help me please
e***@gmail.com
2018-02-12 10:14:53 UTC
Permalink
Raw Message
load Labels


##### hello, I have an error in this line:

Error using load
Unable to read file 'Labels'. No such file or directory.

Error in align_Faces (line 30)
load Labels


#### can you help me please

Loading...