0

我正在尝试编写一个接收图像和整数的函数,并通过以下公式:公式来放大原始图像。i 和 j 是像素的索引,y 和 x(小或大)是原始图片和大图片的列和行。每个像素都应该放大一个。我正在尝试测试该函数,但我收到“”IndexError:标量变量的无效索引“这是为什么?谢谢你的帮助!

   def nearest_enlarge(img, a):
    new_im= np.zeros(img.shape)
    for i in range(img.shape[0]):
            for j in range(img.shape[1]):
                    smallpixelvalue= img[i,j]
                    new_im[i,j]= smallpixelvalue[np.floor(i*(img.shape[0]/img.shape[0]*a)),np.floor(j*(img.shape[1]/img.shape[1]*a))]
    return new_im
4

0 回答 0