Bat*_*son 6 algorithm hough-transform
我正在研究虹膜识别算法,该算法将这些类型的图像处理成用于识别和认证目的的唯一代码.
在过滤,智能阈值处理,然后在图像中找到边缘之后,下一步显然是将圆圈与瞳孔和虹膜拟合.我环顾四周使用的技术是圆形霍夫变换.这是我实现的代码.对于神秘的变量名称感到抱歉.
print "Populating Accumulator..."
# Loop over image rows
for x in range(w):
# Loop over image columns
for y in range(h):
# Only process black pixels
if inp[x,y] == 0:
# px,py = 0 means pupil, otherwise pupil center
if px == 0:
ra = r_min
rb = r_max
else:
rr = sqrt((px-x)*(px-x)+(py-y)*(py-y))
ra = int(rr-3)
rb = int(rr+3)
# a is the width of the image, b is the height
for _a in range(a):
for _b in range(b):
for _r in range(rb-ra):
s1 = x - (_a + a_min)
s2 = y - (_b + b_min)
r1 = _r + ra
if (s1 * s1 + s2 * s2 == r1 * r1):
new = acc[_a][_b][_r]
if new >= maxVotes:
maxVotes = new
print "Done"
# Average all circles with the most votes
for _a in range(a):
for _b in range(b):
for _r in range(r):
if acc[_a][_b][_r] >= maxVotes-1:
total_a += _a + a_min
total_b += _b + b_min
total_r += _r + r_min
amount += 1
top_a = total_a / amount
top_b = total_b / amount
top_r = total_r / amount
print top_a,top_b,top_r
Run Code Online (Sandbox Code Playgroud)
这是用python编写的,使用Python Imaging Library进行图像处理.正如你所看到的,这是一种非常天真的蛮力方法,可以找到圆圈.它有效,但需要几分钟.基本思路是在有黑色像素的任何地方(从阈值处理和边缘检测)绘制从rmin到rmax的圆圈,构建一个累积器数组,其中图像上的位置被"投票".无论哪个x,y和r得票最多,都是感兴趣的圈子.我试图利用虹膜和瞳孔大约相同的中心(变量ra和rb)来减少r循环的一些复杂性这一事实,但是瞳孔检测需要很长时间以至于无关紧要.
现在,显然我的实施非常幼稚.它使用三维参数空间(x,y和r),遗憾的是它运行速度比可接受的慢.我可以做出哪些改进?有没有办法将其减少到二维参数空间?是否有更有效的方式来访问和设置我不知道的像素?
另外,还有其他技术可以改进我不知道的算法的整体运行时间吗?如近似瞳孔或虹膜最大半径的方法?
注意:我也试过使用OpenCV,但是我无法调整参数以保持一致的准确性.
如果您需要任何其他信息,请告诉我.
注意:我再一次误解了我自己的代码.它在技术上是5维的,但是3维x,y,r环仅在黑色像素上操作.