163
社区成员
发帖
与我相关
我的任务
分享
任务 1)从以下网站:南通大学[学校掠影](https://www.ntu.edu.cn/77/list.htm)任选一副图片下载,用Python程序显示原始图片。
from PIL import Image
img_path = 'C:/Users/LongQian/OneDrive/图片/本机照片/Saved Pictures/111.jpg'
img = Image.open(img_path)
img.show()
任务 2)将图片变成黑白图片,并用Python程序显示。
from PIL import Image
img_path = 'C:/Users/LongQian/OneDrive/图片/本机照片/Saved Pictures/111.jpg'
img = Image.open(img_path)
img_bw = img.convert('L')
img_bw.show()
任务3)将图片左右翻转,并用Python程序显示。
from PIL import Image
img_path = 'C:/Users/LongQian/OneDrive/图片/本机照片/Saved Pictures/111.jpg'
img = Image.open(img_path)
img_lr = img.transpose(Image.FLIP_LEFT_RIGHT)
img_lr.show()
任务4)将图片上下翻转,并用Python程序显示。
from PIL import Image
img_path = 'C:/Users/LongQian/OneDrive/图片/本机照片/Saved Pictures/111.jpg'
img = Image.open(img_path)
img_ud = img.transpose(Image.FLIP_TOP_BOTTOM)
img_ud.show()
任务5)对像素值计算
from PIL import Image
import numpy as np
img_path = 'C:/Users/LongQian/OneDrive/图片/本机照片/Saved Pictures/111.jpg'
img = Image.open('C:/Users/LongQian/OneDrive/图片/本机照片/Saved Pictures/111.jpg')
img_array = np.array(img)
int_cropped = img_array[0:500, 0:500, (2, 1, 2)]
int_flipped = int_cropped[:, ::-1, :]
Image.fromarray(int_flipped*2).show()