下面是代码和出现的错误。请帮助我解决此问题:
代码:
def cross_number(enhanced_img, m, n):
# minutiae extraction using crossing number method
r=0
g=0
row_start = 3
col_start = 3
mep = np.zeros((m,2)) # array for indices of minutiae points (end point)
mbp = np.zeros((m,2)) # bifurcation point
for i in range(row_start, m):
for j in range(col_start, n):
if enhanced_img[i,j] == 1:
cn = (1/2)*(abs(enhanced_img[i,j+1] - enhanced_img[i-1,j+1]) + abs(enhanced_img[i-1,j+1] - enhanced_img[i-1,j]) + abs(enhanced_img[i-1,j] - enhanced_img[i-1,j-1]) + abs(enhanced_img[i-1,j-1] - enhanced_img[i,j-1])+ abs(enhanced_img[i,j-1] - enhanced_img[i+1,j-1]) + abs(enhanced_img[i+1,j-1] - enhanced_img[i+1,j])+ abs(enhanced_img[i+1,j] - enhanced_img[i+1,j+1]) + abs(enhanced_img[i+1,j+1] - enhanced_img[i,j+1]))
if cn == 1:
r = r+1
mep[r,:] = [i,j]
elif cn == 3:
g = g+1
mbp[g,:] = [i,j]
return mep, mbp
错误:
IndexError Traceback(最近的呼叫 最后)在() ----> 1个端点,bifur_point =交叉数(dedot_image,行,列)
cross_number中的(enhanced_img,m,n) 294对于范围(col_start,n)中的j: 第295回 -> 296 cn =(1/2)*(abs(enhanced_img [i,j + 1]-Enhanced_img [i-1,j + 1])+ abs(enhanced_img [i-1,j + 1]- Enhanced_img [i-1,j])+ abs(enhanced_img [i-1,j]- Enhanced_img [i-1,j-1])+ abs(enhanced_img [i-1,j-1]- Enhanced_img [i,j-1])+ abs(enhanced_img [i,j-1]-Enhanced_img [i + 1,j-1]) + abs(enhanced_img [i + 1,j-1]-Enhanced_img [i + 1,j])+ abs(enhanced_img [i + 1,j]-Enhanced_img [i + 1,j + 1])+ abs(enhanced_img [i + 1,j + 1]-Enhanced_img [i,j + 1])) 297如果cn == 1: 298 r = r + 1
IndexError:索引352超出了尺寸为352的轴1的边界
答案 0 :(得分:0)
i
上升到m - 1
,因此i + 1
上升到m
,这是超出范围的。也许您应该早一点停下来?与j
类似。
计数器r
和g
的初始化为0。在使用它们之前先对其进行递增,因此它们从1开始。
您可能需要将r = r + 1
行与其后的行交换,对于g = g + 1
也是如此。