1
votes

Using OpenCV to identify the iris region + pupil region (outer grey area + inner black circle) as seen in this image

Tried the following approaches, but unable to extract the iris region 100%.

Approach 1 Iris area detection using detection of color code of the pixels in the image

import cv2
from PIL import Image
#import cv2.cv as cv

img = cv2.imread('i1.jpg')
im = Image.open('i1.jpg')
pix = im.load()
#cv2.imshow('detected Edge',img)

height, width = img.shape[:2]

print height,width
height=height-1
width=width-1
count=0
print pix[width,height]
print pix[0,0]
for eh in range(height):
    for ew in range(width):
        r,g,b=pix[ew,eh]
        if r<=30 and g<=30 and b<=30:
            print eh,ew
            cv2.circle(img,(ew,eh),1,(0,255,0),1)
print height,width
cv2.imshow('detected Edge',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Click here to view output of the above code.

Approach 2 Iris area detection using Hough Circles method

import cv2
#import cv2.cv as cv
img1 = cv2.imread('i.jpg')
img = cv2.imread('i.jpg',0)
ret, thresh = cv2.threshold(img, 50, 255, cv2.THRESH_BINARY)

edges = cv2.Canny(thresh, 100, 200)
#cv2.imshow('detected ',edges)


cimg=cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)

circles = cv2.HoughCircles(edges, cv2.HOUGH_GRADIENT, 1, 10000, param1 = 50, param2 = 30, minRadius = 0, maxRadius = 0)
#circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,20,
#                            param1=50,param2=30,minRadius=0,maxRadius=0)
print circles
for i in circles[0,:]:
    i[2]=i[2]+4
    cv2.circle(img1,(i[0],i[1]),i[2],(0,255,0),1)

#Code to close Window
cv2.imshow('detected Edge',img1)
cv2.waitKey(0)
cv2.destroyAllWindows()
for i in range (1,5):
    cv2.waitKey(1)

Click here to view the output of the code.

Kindly guide us how we can automatically extract the circular black area in human eye pictures.

3
that is not the cornea. that's the pupil... are such things not teached in schools anymore? :( and what is wrong with the hough output image? what do you want to achieve if this result is not good enough and what is good enough?Piglet
To be precise we want to identify the iris region(outer circle grey area) and the pupil region (inner black circle) as seen in this image www3.sciencedump.com/sites/www.sciencedump.com/files/plaatjes/…. Hough output images are not consistent. In some eye images its not precisely identifying the iris region.Vikram
you can't expect good results when you don't set min and max radius for hough transform...Piglet

3 Answers

1
votes

Using approach 2, could you start at the center of the pupil and then travel outwards staying in the same row (travel left or right of the pupil center) until you hit the sclera of the eye. Use this as the radius for the circle containing the iris.

radius_iris = abs(first_column_of_sclera - column_of_pupil_center)
#this is the yellow line in the attatched image

To Find the Sclera: take a small pixel region like a 3x3 block (or similar, this is the green box in the image) and check for two criteria

  1. The variance of the r,g,b channels is small. White (or gray shades) have R=G=B so that means white would have low variance
  2. You also need to check that the rgb value is above some threshold. Someone with grey or black eyes will meet criteria 1, but unless the pixels are very light (near white) we haven't reached the sclera

Create an iris mask by creating a circle centered at the pupil with radius_iris if you want, you can also use the pupil mask to extract ONLY THE iris

enter image description here

1
votes

I used the following reference. http://www.cvip.uofl.edu/wwwcvip/education/ECE523/Iris%20Biometrics.pdf

To identify iris region in human eye images, you can use the following steps:-

1) Identification of pupil region:- As pupil region intensity would be very close to zero, you can use binary threshold to find pupil region.You can use connected components labelling to get regions of same intensity and then select region having eccentricity near to zero to be identified as pupil circle.The centroid of this connected region would be circle's centre and you can get the radius by the dimensions of connected components box.

2) Identification of Iris region:- Now that you have got your pupil region,you can use hough circle method to get iris region.Use canny edge detection to get edge map.Take the centre of the iris circle in a box around pupil centre and radius of the iris more than pupil radius and less than a fixed amount.Make multiple circles with varying centre and varying radius as specified above and count the number of edge map points lying on such circles.The circle with maximum number of edge points lying on it would be iris circle.

Note:- In my experience, I had found that getting iris circle was very costly as you had to make multiple circles with varying centre and radius.One solution was to keep the circle centre fixed as pupil centre and only varying radius as iris circle would be very near to pupil centre. However, it was giving wrong result as the eyelash edge maps at top and bottom were giving wrong edge map points. To solve this, I did a jugaad. I kept the iris centre fixed as pupil centre and found iris radius only for left hand part of image from pupil centre. Similarly, I found iris radius for right hand side of the image from pupil centre. I used the average of both radius and centre as pupil centre to get iris boundary. It worked for me.

0
votes

To avoid wrong results and improve performance you should always use proper boundaries for HoughCircles. Iris and pupil radii will be in a certain range.

I would look for a black blob of reasonable size in the image to locate the pupil. Once you know where the pupil is you know where to look for the iris. extract a region of interest that will contain the iris (use pupil size to estimate iris size) but not much more. Then do two hough transforms to get iris and pupil position and radius. Afterwards you can further improve accuracy by fitting a circle/ellipse using the knowledge from your hough transform, if necessary.