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.