【发布时间】:2017-07-07 05:27:19
【问题描述】:
我正在尝试围绕图像数组移动内核以创建高斯滤波器。我得到一个 IndexError,我知道为什么。这是代码:第 34 行的错误
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-loop 的缩进不正确,我想知道之后的任何地方是否正确...
标签: python arrays numpy scipy bounds