Clear Filters
Clear Filters

Using Daugmans Rubber Sheet model, I am not able to get the correct normalized image of iris. Please help me out.

2 views (last 30 days)
This is my input image, the output i am getting is:
I am sure the center coordinates , I have found them correctly because I am able to segment the iris from the image:
Below is my code for the same.
clc
clear all
close all
%Any image from CASIA Dataset
eyeimage_filename = "F:\8th SEM\Dataset\CASIA\file1.jpg";
eyeimage = imread(eyeimage_filename);
I = eyeimage;
%%%%%%%%%%%%%%%%%%%%%%%% 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.4;
reflecthres = 240;
% find the iris boundary
[row, col, r] = findcircle(eyeimage, lirisradius, uirisradius, scaling, 2, 0.20, 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.6,2,0.25,0.25,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,subplot(1,3,1);imshow(imagewithnoise2);title('segmented');
subplot(1,3,2);imshow(imagewithcircles);title('circles');
subplot(1,3,3);imshow(eyeimage);title('original image');
%%%%%%%%%%%%%%%%%% 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,imshow(I);
title("INPOLYGON IRIS");
%%%%%%%%%%%%%%%% RUBBER SHEET MODEL%%%%%%%%%%%%%%%%%%%%%%%%%%
xp = rowp;
yp = colp;
rp = r;
xi = rowd;
yi = cold;
ri = rd;
% Initialize samples
angleSamples = 360;
RadiusSamples = 360;
debug =0;
interpolateQ =1;
angles = (0:pi/angleSamples:pi-pi/angleSamples) + pi/(2*angleSamples);%avoiding infinite slope
r = 0:1/RadiusSamples:1;
nAngles = length(angles);
% Calculate pupil points and iris points that are on the same line
x1 = ones(size(angles))*xi;
y1 = ones(size(angles))*yi;
x2 = xi + 10*sin(angles);
y2 = yi + 10*cos(angles);
dx = x2 - x1;
dy = y2 - y1;
slope = dy./dx;
intercept = yi - xi .* slope;
xout = zeros(nAngles,2);
yout = zeros(nAngles,2);
for i = 1:nAngles
[xout(i,:),yout(i,:)] = linecirc(slope(i),intercept(i),xp,yp,rp);
end
% Get samples on limbus boundary
xRightIris = yi + ri * cos(angles);
yRightIris = xi + ri * sin(angles);
xLeftIris = yi - ri * cos(angles);
yLeftIris = xi - ri * sin(angles);
% Get samples in radius direction
xrt = (1-r)' * xout(:,1)' + r' * yRightIris;
yrt = (1-r)' * yout(:,1)' + r' * xRightIris;
xlt = (1-r)' * xout(:,2)' + r' * yLeftIris;
ylt = (1-r)' * yout(:,2)' + r' * xLeftIris;
% Create Normalized Iris Image
if interpolateQ
image = uint8(reshape(interp2(double(I),[yrt(:);ylt(:)],[xrt(:);xlt(:)]),length(r), 2*length(angles))');
else
image = reshape(I(sub2ind(size(I),round([xrt(:);xlt(:)]),round([yrt(:);ylt(:)]))),length(r), 2*length(angles));
end
figure,imshow(image);
title("normalized image")
%%Show all points on original input image
if debug
img = insertShape(eyeimage, 'circle', [yrt(:),xrt(:),2*ones(size(xrt(:)))],'Color','r');
img = insertShape(eyeimage, 'circle', [ylt(:),xlt(:),2*ones(size(xrt(:)))],'Color','r');
figure('name','Sample scheme of the rubber sheet normalization');
imshow(img);
drawnow;
end

Accepted Answer

Aditya
Aditya on 24 Jan 2024
Hi Ridhima,
If you're looking to normalize an iris region using Daugman's Rubber Sheet Model, you can refer to the following resources which can help you in resolving the issue. Here's how you can utilize them:
This submission includes a function for detecting the pupil and limbus (iris boundary) and a function for performing the normalization.
Below is an example code snippet using that resource which demonstrates how to detect the iris and pupil boundaries and then normalize the iris region:
% Read the eye image
img = imread('example.jpg');
% Find the Limbus boundary without GUI
[yPosIris, xPosIris, rIris, image] = daugmanCircleDetection(img);
% Find the Pupil boundary
[yPosPupil, xPosPupil, rPupil, image] = daugmanCircleDetection(img, 'Feature','pupil');
% Normalize the iris region according to Daugman's model
irisRegion = rubberSheetNormalisation(img, xPosPupil, yPosPupil, rPupil, xPosIris, yPosIris, rIris, 'DebugMode', 1);
% Show the resulting image
figure(2);
imshow(irisRegion);
You can adjust the DebugMode, RadiusSamples, UseInterpolation, and AngleSamples parameters to control the visualization and resolution of the normalization process.
This repository includes code for creating an iris template, which is part of the iris recognition pipeline. The normalization step is also included within this process.
You can review the createiristemplate.m script to understand how it integrates the normalization step within the broader context of iris recognition.
If you continue to face difficulties with your code, please provide all the related files, including the image and any custom functions. So that, I can run a test on my side to better diagnose the issue and assist you in resolving it.
Hope this helps!
  1 Comment
Ridhima Chopra
Ridhima Chopra on 25 Jan 2024
Edited: Ridhima Chopra on 25 Jan 2024
Thanks a lot for your response.
I debugged the error. To get the pupil, we are cropping the image and getting the centre coordinates of the pupil with respect to that cropped image. This was where i went wrong.
rowp = double(rowp);
colp = double(colp);
r = double(r);
row = double(irl) + rowp;
col = double(icl) + colp;
Instead of rowp and colp I had to use row and col.
Thus for the rubber sheet model, variables will be initialized like this:
xp = row;
yp = col;
rp = r;
xi = rowd;
yi = cold;
ri = rd;
I appreciate your help. Thanks again @Aditya! :)

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!