如何使用 Python Matplotlib 将方形图像像素化为 256 个大像素?
matplotlibpythondata visualization更新于 2025/9/12 12:28:17
要使用 Python 将方形图像像素化为 256 个大像素,我们可以采取以下步骤 −
- 设置图形大小并调整子图之间和周围的填充。
- 打开并识别给定的图像文件。
- 调整图像样本的大小。
- 制作结果图像并调整其大小。
- 保存结果图。
示例
from PIL import Image
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
img = Image.open("bird.png")
imgSmall = img.resize((16, 16), resample=Image.BILINEAR)
result = imgSmall.resize(img.size, Image.NEAREST)
result.save('result.png')
输入图像
.jpg)
.jpg)
输出图像
.png)
.png)
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

