How segment correctly the pupil and iris?

asked 2018-11-01 01:15:46 -0500

neto gravatar image

updated 2018-11-01 10:37:25 -0500

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)


This is as close as I could get:

image description

**Image original:

inserir a descrição da imagem aqui

Image after binarizing:

inserir a descrição da imagem aqui

I use python 3.x and opencv via PyPi

edit retag flag offensive close merge delete


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.

Eduardo gravatar imageEduardo ( 2018-11-01 16:46:40 -0500 )edit

Search GitHub on pupil. Lots of projects there. One challenge I have come across is the light reflection in the image confuses algorithms.

warpdriv gravatar imagewarpdriv ( 2019-09-13 06:34:24 -0500 )edit