0
我正在尝试在图像数组周围移动内核来创建高斯过滤器。我得到一个IndexError和Idk为什么。这是代码:第34行的错误索引超出范围/ IndexError
import numpy as np
import scipy
from scipy import misc
import matplotlib.pyplot as plt
imagen_nueva = np.empty((1931, 1282))
imagen = scipy.misc.imread("C:\\Users\\Reymi\\Downloads\\imagen.png")
imagen_real = scipy.pad(array=imagen, pad_width=[1, 1], mode='constant',
constant_values=0)
(dim_x,dim_y)=np.shape(imagen_real)
print((dim_x,dim_y))
ker1 = np.array([[1/16, 1/8, 1/16],
[1/8, 1/4, 1/8],
[1/16, 1/8, 1/16]])
def multiplicar_entero():
global imagen_nueva
for i in range(1,dim_x+1):
for j in range(1,dim_y+1):
matriz_elemento = np.array([[imagen_real[i + 1, j - 1],
imagen_real[i + 1, j], imagen_real[i + 1, j - 1]],
[imagen_real[i, j - 1], imagen_real[i, j],
imagen_real[i, j + 1]],
[imagen_real[i - 1, j - 1], imagen_real[i - 1, j],
imagen_real[i - 1, j + 1]]])
valor = np.sum(matriz_elemento*ker1)
imagen_real[i, j] = valor
imagen_nueva = np.append(imagen[i, j], (1931, 1282))
至于混淆矩阵与is和js。它是阵列每个元素的矩阵3x3。我知道它可能不是最好的方法
你的线都没有编号,我们不知道的错误...您可以编辑错误? –
python 2或python 3? –
在'multiplicar_entero()'中,第二个for循环的缩进是不正确的,我想知道它在以后的任何地方是否正确... –