How segment correctly the pupil and iris?
I'm trying to target both the iris and pupil border using opencv's Canny Edge, but all of the parameters I've used do not meet the criteria of well delimiting the two edges. The only way I found of segmenting at least the edge of the iris was binarizing it and then applying the Canny Edge and actually gave a good return.
- Is there any way to improve the result? Or is it trial and error?
- How to segment the pupil?
Attempt to segment only the pupil binarizing in the dark range:
#'guarda' o pixel se ele estiver no intervalo que é preto
for x in range(0,suavizada.shape[0]):
for y in range(0,suavizada.shape[1]):
if img[x][y] >=0 and suavizada[x][y] <65:
escala[x][y] = 255
Code to target iris:
img = cv2.imread('path',0)
suavizada = cv2.medianBlur(img,7)
_,limites = cv2.threshold(suavizada,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
bordas = cv2.Canny(limites,0,0)
cv2.imshow('bordas',bordas)
cv2.waitKey(0)
cv2.destroyAllWindows()
This is as close as I could get:
**Image original:
Image after binarizing:
I use python 3.x and opencv via PyPi
You may want to check: Simple, accurate eye center tracking in OpenCV
You should be able to modify the code to segment the pupil and iris since the code should give you the eye center.
Search GitHub on pupil. Lots of projects there. One challenge I have come across is the light reflection in the image confuses algorithms.