我一直在尝试处理人眼图像,以获取虹膜的尺寸,已经持续了一个月。我使用这张图片作为输入,有些成功地实现了我的目标,但在检测轮廓和获取感兴趣区域(虹膜)方面仍不够高效。
潜在原因是,由于人眼图像包含通常为黑色的眉毛和睫毛,在我对其应用阈值处理时,它们会在Canny处理期间被包括进去,当我尝试在它们上面绘制轮廓时,它们会干扰我的感兴趣区域即虹膜,并返回一个混乱的区域。
我不太确定如何从中获取ROI的投资回报率。因此,我尝试不使用轮廓,而是采用霍夫圆,但结果不可接受,因为虹膜不是完美的圆形,而是椭圆形。
轮廓似乎是最好的选择,因为我可以轻松地在轮廓上绘制边界框并获取其尺寸,但我的图像处理知识有限,我需要找到一种方法来消除所有噪声和伪影,以获取ROI即人类虹膜。
所以我的问题是:我可以部署哪些图像处理技术来从人眼图像中去除睫毛和眉毛?
替代问题:我如何从已经处理过的图像中提取我的感兴趣区域(人类虹膜)?处理过的图像:
原因:当我尝试从图像中获取轮廓时,不需要的眉毛/睫毛会干扰我的感兴趣区域(虹膜),因此ROI经常与眉毛/睫毛合并在一起,这使得我难以处理/删除,以便计算虹膜尺寸。
以下是代码:
#Libraries
import cv2
import numpy as np
#show image
def display_image(name,current_image):
cv2.imshow(name,current_image)
cv2.waitKey(0)
def image_processing(current_image):
#Grayscaling
grayscaled_image = cv2.cvtColor(current_image, cv2.COLOR_BGR2GRAY)
#display_image("Gray",grayscaled_image)
#Inverting
inverted_image = cv2.bitwise_not(grayscaled_image)
#display_image("Invert",inverted_image)
#Removing Reflection
kernel = np.ones((5, 5), np.uint8)
blackhat_image = cv2.morphologyEx(inverted_image,cv2.MORPH_BLACKHAT,kernel)
#display_image("Backhat",blackhat_image)
removed_refection = cv2.addWeighted(src1=inverted_image,alpha=0.5,src2=blackhat_image,beta=0.5,gamma=0)
#display_image("Removed reflection",removed_refection)
image_without_reflection = cv2.medianBlur(removed_refection, 5)
#display_image("No reflection",image_without_reflection)
#Thresholding
_,thresholded_image= cv2.threshold(image_without_reflection,100,255,cv2.THRESH_BINARY)
#display_image("Thresholded",thresholded_image)
#Canny
region_of_interest = cv2.bitwise_not(thresholded_image)
canny_image = cv2.Canny(region_of_interest, 200, 100)
return canny_image
def iris_detection(image):
circles = cv2.HoughCircles(processed_image, cv2.HOUGH_GRADIENT, 1, 20, param1 = 200, param2 = 20, minRadius = 0)
if circles is not None:
#fifth step mark circles co-ordinates
inner_circle = np.uint16(np.around(circles[0][0])).tolist()
cv2.circle(current_image, (inner_circle[0], inner_circle[1]), inner_circle[2], (0, 255, 0), 1)
display_image("Final",current_image)
x, y,_ = current_image.shape
radius = inner_circle[2]*0.2645833333
diameter = radius * 2
print("The Radius of the iris is:",radius,"mm")
print("The Diameter of the iris is:",diameter,"mm")
def contour_detection(image):
#Countours are less effective
contours,hierarchy = cv2.findContours(image,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
return cv2.drawContours(new_image, contours, -1, (0,255,0), 3)
#input
current_image = cv2.imread("eye.jpg", 1)
display_image("Original",current_image)
#Copy of the original image
new_image = current_image.copy()
#Image pre-processing
processed_image = image_processing(current_image)
display_image("Processed Image",processed_image)
#Iris Detection using Hough circles
iris_detection(processed_image)
contoured_image = contour_detection(processed_image)
display_image("Contours",contoured_image)
cv2.destroyAllWindows()