44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
import matplotlib.pyplot as plt
|
|
plt.rcParams['font.sans-serif'] = ['simHei']
|
|
plt.rcParams['axes.unicode_minus'] = False
|
|
from PIL import Image
|
|
|
|
# 读取 128x128 的图片
|
|
image_path = "homework_photo.png"
|
|
image = Image.open(image_path)
|
|
|
|
# 使用三种插值方法放大到 512x512
|
|
image_nearest = image.resize((512, 512), Image.NEAREST) # 最近邻插值
|
|
image_linear = image.resize((512, 512), Image.BILINEAR) # 双线性插值
|
|
image_cubic = image.resize((512, 512), Image.BICUBIC) # 立方插值
|
|
|
|
"""
|
|
# 保存为指定文件名
|
|
image.save("photo/原图.png")
|
|
image_nearest.save("photo/最近邻插值.png")
|
|
image_linear.save("photo/双线性插值.png")
|
|
image_cubic.save("photo/立方插值.png")
|
|
"""
|
|
|
|
plt.subplot(2,2,1)
|
|
plt.imshow(image)
|
|
plt.title('原图')
|
|
plt.axis('off')
|
|
|
|
plt.subplot(2,2,2)
|
|
plt.imshow(image_nearest)
|
|
plt.title('最近邻插值')
|
|
plt.axis('off')
|
|
|
|
plt.subplot(2,2,3)
|
|
plt.imshow(image_linear)
|
|
plt.title('双线性插值')
|
|
plt.axis('off')
|
|
|
|
plt.subplot(2,2,4)
|
|
plt.imshow(image_cubic)
|
|
plt.title('立方插值')
|
|
plt.axis('off')
|
|
|
|
plt.tight_layout()
|
|
plt.show() |