Reputation: 45
Below is the code and the error I'm getting. Please help me to fix this:
Code:
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
Error:
IndexError Traceback (most recent call last) in () ----> 1 end_point, bifur_point = cross_number(dedot_image, row, col)
in cross_number(enhanced_img, m, n) 294 for j in range(col_start, n): 295 if enhanced_img[i,j] == 1: --> 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 if cn == 1: 298 r = r+1
IndexError: index 352 is out of bounds for axis 1 with size 352
Upvotes: 0
Views: 1471
Reputation: 458
i
goes up to m - 1
, so i + 1
goes up to m
which is out of bounds. Maybe you should stop one earlier? Similar for j
.
The counters r
and g
are initialized 0. You're incrementing them before using them, so they end up starting from 1.
You probably need to swap the r = r + 1
line with the one after it, and similar for g = g + 1
.
Upvotes: 1