Remove eye shine on image

Asked

Viewed 247 times

5

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

  • How to remove pupil brightness?

Code to extract edge:

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:

IOG

Desired image (done in Paint!!):

inserir a descrição da imagem aqui

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

inserir a descrição da imagem aqui

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

  • Do you own the color photo? Or just grayscale?

  • Grayscale only, size 200x150

1 answer

1

Upshot

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

Resultado

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

  • Load the image and convert to grayscale (gray)
  • Create an image mask, with the values between range 215 and 255 (next to white)
  • Uses AND logic to remove pixels from the image between the range set in the mask mask
  • Fills the empty spaces with interpolation Inpaint of Alexandru Telea, predicting what should be in that empty place

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.