Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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()

Imagem original:

inserir a descrição da imagem aqui

Imagem depois de binarizar e passar pelo Canny:

inserir a descrição da imagem aqui

Estou utilizando Python 3.x com a biblioteca instalada via PyPi

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()

Imagem original:

inserir a descrição da imagem aqui

Imagem depois de binarizar e passar pelo Canny:

inserir a descrição da imagem aqui

Estou utilizando Python 3.x com a biblioteca instalada via PyPi

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()

Imagem This is as close as I could get:

image description

**Image original:

inserir a descrição da imagem aqui

Imagem depois de binarizar e passar pelo Canny:Image after binarizing:

inserir a descrição da imagem aqui

Estou utilizando Python I use python 3.x com a biblioteca instalada and opencv via PyPi

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 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

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 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