Remove eye glare in the picture

Well, I'm trying to apply canny edge in the image but the brightness that is contained in the pupil hinders the result obtained because to have an edge with cv2.Canny() or feature.canny() need that there is a continuity of the same. As I have to apply media filter it gets even worse because this region of brightness increases!

  • How to remove glare from the pupil?

Code to extract border:

from skimage import feature
from skimage.io import imread
import cv2
img = imread("../olho.jpg",as_gray=True)
img = cv2.blur(img,(5,5))
borda = feature.canny(img)

Original image with noise:

Oji

Desired image (done in paint!!):

insert the description of the image here

Edges obtained (with a hole in the place of the glow and the edges of the glow):

insert the description of the image here

I need these edges right because after extraction I will apply Hough transform to find the circles

Author: sant0will, 2018-11-28

1 answers

Result

The image on the left is the original and the image on the right is without reflection.

Result

Code

import cv2
import numpy as np
import urllib.request


resp = urllib.request.urlopen("https://i.stack.imgur.com/TvChy.jpg")
img = np.asarray(bytearray(resp.read()), dtype="uint8")
img = cv2.imdecode(img, cv2.IMREAD_COLOR)
copia = img.copy()

#Converte para Escala de Cinza
gray = cv2.cvtColor(copia,cv2.COLOR_BGR2GRAY)

#Máscara para obter o que está no intervalo branco
mask = cv2.inRange(gray, 215, 255)

#Lógica AND
mask_not = cv2.bitwise_not(mask)
copia = cv2.bitwise_and(copia, copia, mask=mask_not )


#Interpolação da imagem para preencher os vazios
inpaint = cv2.inpaint(copia, mask, 3,cv2.INPAINT_TELEA)

#Mostra a nova imagem e a original
cv2.imshow("Original / Inpaint", np.hstack([img, inpaint]))
cv2.waitKey(0)

Explanation

  • loads the image and converts to grayscale (gray)
  • creates a mask of the image, with the values between the range 215 and 255 (close to White)
  • uses and logic to remove pixels from the image between the range set in the mask mask
  • fills in the empty spaces with Alexandru Telea's interpolation Inpaint, predicting what should be in that empty place

A fine-tuning can probably be done on the parameters of InRange: mask = cv2.inRange(gray, 215, 255)

 1
Author: danieltakeshi, 2018-11-30 19:20:46