小编dor*_*bin的帖子

最近邻图像使用 scipy 和 PIL 调整大小错误

我正在尝试拍摄一个小图像并使用 Python 制作它的大(“像素化”)版本。我已经尝试在两者中使用最近邻调整大小方法scipyPIL.Image并且两者都输出相同的错误结果。这是尝试将图像上采样 3 倍的示例:

import numpy as np
from scipy.misc import imresize
from PIL import Image

img = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=np.uint8)
img_nn_scipy = imresize(img, (9, 9), interp='nearest')
img_nn_pil   = np.array(Image.fromarray(img).resize((9, 9), Image.NEAREST))

print img_nn_scipy
print img_nn_pil
Run Code Online (Sandbox Code Playgroud)

两个打印语句输出相同的结果:

[[1 1 1 2 2 2 2 3 3]
 [1 1 1 2 2 2 2 3 3]
 [1 1 1 2 2 2 2 3 3]
 [4 4 4 5 …
Run Code Online (Sandbox Code Playgroud)

python scipy image-resizing python-imaging-library

3
推荐指数
1
解决办法
5133
查看次数