Unable to Segment Iris from Preprocessed Eye Dataset.

The following are some images from my dataset:
I convert the coloured images in grayscale and preprocess them as follows:
function Eye= preprocessing(eyeimage)
if(size(eyeimage, 3) == 3) % if RGB image is inputted
eyeimage = rgb2gray(eyeimage);
end
%%%%%%%%% SHARPENING THE IMAGE %%%%%%%%%%%%%%%%
dimage = im2double(eyeimage);
gradient = convn(dimage,ones(3)/9,"same") - convn(dimage,ones(5)/25,"same");
amount = 5;
eyeimage = dimage + amount.*gradient;
% figure(),imshowpair(dimage,eyeimage,'montage');
% title("Original image (left) vs sharpened image (right)");
%%%%%%%%%%%%%%% Contrast-limited adaptive histogram equalization (CLAHE)%%%
% Eye = adapthisteq(eyeimage,'clipLimit',0.02,'Distribution','rayleigh');
Eye=histeq(eyeimage);
The result is:
After segemting iris from this preprocessed image:
I am not getting the correct segmented iris:
%%%%%%%%%%%%%%%%%%%%%%%% CREATEIRISTEMPLATE %%%%%%%%%%%%%%%%%%
%normalisation parameters
radial_res = 20;
angular_res = 240;
% with these settings a 9600 bit iris template is created
%feature encoding parameters
nscales=1;
minWaveLength=18;
mult=1; % not applicable if using nscales = 1
sigmaOnf=0.5;
%%%%%%%%%%%%%%%%%%%%%%%% SEGMENTIRIS %%%%%%%%%%%%%%%%%%
%CASIA
lpupilradius = 28;
upupilradius = 75;
lirisradius = 80;
uirisradius = 150;
% define scaling factor to speed up Hough transform
scaling = 0.3;
reflecthres = 240;
% find the iris boundary
[row, col, r] = findcircle(eyeimage, lirisradius, uirisradius, scaling, 2, 0.45, 0.19, 1.00, 0.00);
circleiris = [row col r];
rowd = double(row);
cold = double(col);
rd = double(r);
irl = round(rowd-rd);
iru = round(rowd+rd);
icl = round(cold-rd);
icu = round(cold+rd);
imgsize = size(eyeimage);
if irl < 1
irl = 1;
end
if icl < 1
icl = 1;
end
if iru > imgsize(1)
iru = imgsize(1);
end
if icu > imgsize(2)
icu = imgsize(2);
end
% to find the inner pupil, use just the region within the previously
% detected iris boundary
imagepupil = eyeimage( irl:iru,icl:icu);
%find pupil boundary
[rowp, colp, r] = findcircle(imagepupil, lpupilradius, upupilradius,0.2,2,0.35,0.35,1.00,1.00);
rowp = double(rowp);
colp = double(colp);
r = double(r);
row = double(irl) + rowp;
col = double(icl) + colp;
row = round(row);
col = round(col);
circlepupil = [row col r];
% set up array for recording noise regions
% noise pixels will have NaN values
imagewithnoise = double(eyeimage);
%find top eyelid
topeyelid = imagepupil(1:(rowp-r),:);
lines = findline(topeyelid);
if size(lines,1) > 0
[xl yl] = linecoords(lines, size(topeyelid));
yl = double(yl) + irl-1;
xl = double(xl) + icl-1;
yla = max(yl);
y2 = 1:yla;
ind3 = sub2ind(size(eyeimage),yl,xl);
imagewithnoise(ind3) = NaN;
imagewithnoise(y2, xl) = NaN;
end
%find bottom eyelid
bottomeyelid = imagepupil((rowp+r):size(imagepupil,1),:);
lines = findline(bottomeyelid);
if size(lines,1) > 0
[xl yl] = linecoords(lines, size(bottomeyelid));
yl = double(yl)+ irl+rowp+r-2;
xl = double(xl) + icl-1;
yla = min(yl);
y2 = yla:size(eyeimage,1);
ind4 = sub2ind(size(eyeimage),yl,xl);
imagewithnoise(y2, xl) = NaN;
end
imagewithnoise(ind4) = NaN;
%For CASIA, eliminate eyelashes by thresholding
ref = eyeimage < 100;
coords = find(ref==1);
imagewithnoise(coords) = NaN;
% figure,imshow(eyeimage);title('originalimage');
% figure,imshow(imagepupil);title('pupil');
% figure,imshow(imagewithnoise);title('image with noise');
% WRITE NOISE IMAGE
%
imagewithnoise2 = uint8(imagewithnoise);
imagewithcircles = uint8(eyeimage);
%get pixel coords for circle around iris
[xii,yii] = circlecoords([circleiris(2),circleiris(1)],circleiris(3),size(eyeimage));
ind2 = sub2ind(size(eyeimage),double(yii),double(xii));
%get pixel coords for circle around pupil
[xpp,ypp] = circlecoords([circlepupil(2),circlepupil(1)],circlepupil(3),size(eyeimage));
ind1 = sub2ind(size(eyeimage),double(ypp),double(xpp));
% Write noise regions
imagewithnoise2(ind2) = 255;
imagewithnoise2(ind1) = 255;
% Write circles overlayed
imagewithcircles(ind2) = 255;
imagewithcircles(ind1) = 255;
% figure('name',"Hough Transform locating Iris and Pupil");
% subplot(1,3,3);imshow(eyeimage);title('Original image');
% subplot(1,3,1);imshow(imagewithnoise2);title('Segmented');
% subplot(1,3,2);imshow(imagewithcircles);title('Circles');
%%%%%%%%%%%%%%%%%% MODEL2OUTPUT %%%%%%%%%%%%%%%%%
x=xii;
y=yii;
r1=ind2;
xp=xpp;
yp=ypp;
r2=ind1;
[nx,ny,d] = size(I) ;
[X,Y] = meshgrid(1:ny,1:nx) ;
th = linspace(0,2.*pi);
x=double(x);
y=double(y);
r1=double(r1);
xp=double(xp);
yp=double(yp);
r2=double(r2);
idx = inpolygon(X(:),Y(:),x,y) ;
for i = 1:d
I1 = I(:,:,i) ;
I1(~idx) = 255 ;
I(:,:,i) = I1 ;
end
idx = inpolygon(X(:),Y(:),xp,yp) ;
for i = 1:d
I1 = I(:,:,i) ;
I1(idx) = 255 ;
I(:,:,i) = I1 ;
end
figure('name',"Segmented Iris"),imshow(I);
I think the problem is in the findcircle parameters. Can anyone help me with the parameters I must put in findcircle function?
Attaching the findcircle file for the reference.

 Accepted Answer

Have you considered just using imfindcircles?

9 Comments

i don't get you actually.
I tried changing the parameters like scaling, high threshold and lower threshold for these lines:
%find iris boundary
[row, col, r] = findcircle(eyeimage, lirisradius, uirisradius, scaling, 2, 0.45, 0.19, 1.00, 0.00);
%find pupil boundary
[rowp, colp, r] = findcircle(imagepupil, lpupilradius, upupilradius,0.2,2,0.35,0.35,1.00,1.00);
After making changes, it works perfectly for some images but doesn't for the others.
Okay now i get it, imfindcircles doesn't work on this one. It works only where backgrounds are brighter than the objects. @Taylor
@Ridhima Chopra Set the ObjectPolarity to "bright" when the circular objects are brighter than the background and "dark" when the circular objects are darker than the background.
imfindcircles is a built-in function. Try that instead of this home-built findcircles function you're using.
It detected a number of circles
Not as accurate as findcircles function.
There are various ways to fine tune imfindcircles. Namely, using a radius range and adjusting the values for sensitivity and edge threshold.

Sign in to comment.

More Answers (0)

Products

Release

R2021a

Community Treasure Hunt

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

Start Hunting!