我正在尝试拍摄一个小图像并使用 Python 制作它的大(“像素化”)版本。我已经尝试在两者中使用最近邻调整大小方法scipy,PIL.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)