【发布时间】:2022-08-05 17:15:41
【问题描述】:
我一直在尝试处理人眼图像以获得虹膜尺寸过去一个月。我使用这张图片作为我的输入,并且在某种程度上我能够实现我想要做的事情,但在检测轮廓和获取我的感兴趣区域(虹膜)时仍然没有效率。
其背后的潜在原因是,因为人眼图像包含眉毛和睫毛通常是黑暗的当我申请时阈值在它上面,它们在精明的处理过程中被包含在内,当我尝试在它们上绘制轮廓时,它们会干扰我感兴趣的区域,即虹膜,它们会返回一个区域的混乱--->
我很不确定如何从中获得投资回报率。所以我试着不使用轮廓,而是选择了霍夫圆但他们的结果是不能接受的因为虹膜不是完美的圆,而是椭圆.
轮廓似乎是最好的选择,因为我可以轻松地在轮廓上绘制边界框并获取其尺寸但我的图像处理知识有限,我需要找到一种方法来消除所有噪声和伪影以获得 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()
标签: python opencv image-processing opencv-contour