error with interp2
Afficher commentaires plus anciens
Hi, im trying to do iris recognition using Daugman'a algorithm.
But i get into an error using interp2:

Here is the code. Please somebody help me find a solution.
function [polar_array, polar_noise] = normaliseiris(image, x_iris, y_iris, r_iris,...
x_pupil, y_pupil, r_pupil,eyeimage_filename, radpixels, angulardiv, method)
global DIAGPATH
radiuspixels = radpixels + 2;
angledivisions = angulardiv-1;
r = 0:(radiuspixels-1);
theta = 0:2*pi/angledivisions:2*pi;
x_iris = double(x_iris);
y_iris = double(y_iris);
r_iris = double(r_iris);
x_pupil = double(x_pupil);
y_pupil = double(y_pupil);
r_pupil = double(r_pupil);
% calculate displacement of pupil center from the iris center
ox = x_pupil - x_iris;
oy = y_pupil - y_iris;
if ox <= 0
sgn = -1;
elseif ox > 0
sgn = 1;
end
if ox==0 && oy > 0
sgn = 1;
end
r = double(r);
theta = double(theta);
a = ones(1,angledivisions+1)* (ox^2 + oy^2);
% need to do something for ox = 0
if ox == 0
phi = pi/2;
else
phi = atan(oy/ox);
end
b = sgn.*cos(pi - phi - theta);
% calculate radius around the iris as a function of the angle
r = (sqrt(a).*b) + ( sqrt( a.*(b.^2) - (a - (r_iris^2))));
r = r - r_pupil;
rmat = ones(1,radiuspixels)'*r;
rmat = rmat.* (ones(angledivisions+1,1)*[0:1/(radiuspixels-1):1])';
rmat = rmat + r_pupil;
% exclude values at the boundary of the pupil iris border, and the iris scelra border
% as these may not correspond to areas in the iris region and will introduce noise.
%
% ie don't take the outside rings as iris data.
rmat = rmat(2:(radiuspixels-1), :);
% calculate cartesian location of each data point around the circular iris
% region
xcosmat = ones(radiuspixels-2,1)*cos(theta);
xsinmat = ones(radiuspixels-2,1)*sin(theta);
xo = rmat.*xcosmat;
yo = rmat.*xsinmat;
xo = x_pupil+xo;
yo = y_pupil-yo;
% extract intensity values into the normalised polar representation through
% interpolation
[x,y] = meshgrid(1:size(image,2),1:size(image,1));
polar_array = interp2(x,y,image,xo,yo); % x,y[300,400], image[300,400,3], xo,yo[20,240]
% create noise array with location of NaNs in polar_array
polar_noise = zeros(size(polar_array));
coords = find(isnan(polar_array));
polar_noise(coords) = 1;
polar_array = double(polar_array)./255;
% start diagnostics, writing out eye image with rings overlayed
% get rid of outling points in order to write out the circular pattern
coords = find(xo > size(image,2));
xo(coords) = size(image,2);
coords = find(xo < 1);
xo(coords) = 1;
coords = find(yo > size(image,1));
yo(coords) = size(image,1);
coords = find(yo<1);
yo(coords) = 1;
xo = round(xo);
yo = round(yo);
xo = int32(xo);
yo = int32(yo);
ind1 = sub2ind(size(image),double(yo),double(xo));
image = uint8(image);
image(ind1) = 255;
%get pixel coords for circle around iris
[x,y] = circlecoords([x_iris,y_iris],r_iris,size(image));
ind2 = sub2ind(size(image),double(y),double(x));
%get pixel coords for circle around pupil
[xp,yp] = circlecoords([x_pupil,y_pupil],r_pupil,size(image));
ind1 = sub2ind(size(image),double(yp),double(xp));
image(ind2) = 255;
image(ind1) = 255;
%replace NaNs before performing feature encoding
coords = find(isnan(polar_array));
polar_array2 = polar_array;
polar_array2(coords) = 0.5;
avg = sum(sum(polar_array2)) / (size(polar_array,1)*size(polar_array,2));
polar_array(coords) = avg;
3 commentaires
KSSV
le 9 Oct 2020
It looks like you are using 3D matrix in interp2...You have to run a loop for each slice...or have a look on interpn.
Huynh-Anh Le
le 9 Oct 2020
Modifié(e) : Huynh-Anh Le
le 9 Oct 2020
Huynh-Anh Le
le 9 Oct 2020
Réponses (0)
Catégories
En savoir plus sur Graphics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!