有人能帮我做些什么来解决这个代码中的索引超出范围的问题吗?在开始之前和之后都有代码。你觉得这有关系吗?
print("1. Sum of Squared Differences")
print("2. Correlation Coefficient")
print("3. Normalized Cross-Correlation")
cross_image_type = input("Enter the type of cross image referencing: ")
if (cross_image_type == "1"):
h = len(grey_picture_data[0])
w = len(grey_picture_data[0])
r = np.zeros((h,w))
for k in range(0,h):
for l in range(0,w):
for i in range(0,w):
for j in range(0,h):
r[i][j] += (((grey_picture_data[i+k][j+l]) - (grey_picture_data_2[k][l]))**2)屏幕上的输出-
Enter the name of a color image: crosswalk.jpg
Enter the name of the color template file: crosswalk_template.jpg
1. Sum of Squared Differences
2. Correlation Coefficient
3. Normalized Cross-Correlation
Enter the type of cross image referencing: 1
Traceback (most recent call last):
File "C:\Program Files\Spyder\pkgs\spyder_kernels\py3compat.py", line 356, in compat_exec
exec(code, globals, locals)
File "d:\purdue\engr 133\proj.py", line 206, in <module>
r[i][j] += (((grey_picture_data[i+k][j+l]) - (grey_picture_data_2[k][l]))**2)
IndexError: index 683 is out of bounds for axis 0 with size 683发布于 2022-10-16 02:06:04
试试这个:
h = len(grey_picture_data[0])
w = len(grey_picture_data[0])
r = np.zeros((h,w))
for k in range(0,h):
for l in range(0,w):
for i in range(0,w):
for j in range(0,h):
r[k][l] = r[k][l] + grey_picture_data[i][j]*np.exp(-1j*2*np.pi*(i*k/w+j*l/h))https://stackoverflow.com/questions/74084137
复制相似问题