python pil 图像加工处理

被刻印的时光 ゝ 提交于 2020-01-29 16:12:53

from PIL import Image
from PIL import ImageEnhance
im=Image.open("d://aa.jpg","r")
print(im.size,im.format,im.mode) #显示图的大小,格式,模式
brightness = ImageEnhance.Brightness(im)
im_brightness = brightness.enhance(1.5)
#im_brightness.show()
im_brightness.save("d://tu1//aa0.jpg")
im_contrast = ImageEnhance.Contrast(im)
im_contrast.enhance(0.8)
#im_contrast.enhance(1.5).show()
im_contrast.enhance(0.8).save("d://tu1//aa1.jpg")
im_resize=im.resize((200,200))
#im_resize.show()
im_resize.save("d://tu1//aa2.jpg")

 

import imageio,os,numpy
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from PIL import Image

tiger_jpg=imageio.imread(os.getcwd()+"aa.jpg") #读取图片.
print("图片的数据类型:", tiger_jpg.dtype) #获取图片数据类型.
img_shape = tiger_jpg.shape #获取图片大小.
print("(图片大小, 通道数):", tiger_jpg.shape)
imageio.imwrite("tiger_mc.jpg", tiger_jpg * [1, 0.5, 0.5] ) #修改图片颜色并保存.
imageio.imwrite("timg_ms.jpg",numpy.array(Image.fromarray(tiger_jpg).resize
((120,70)))) #修改图片大小并保存.
imageio.imwrite("timg_mi.jpg", tiger_jpg[50:130, 100:240]) #裁剪图片并保存.
"""-------------------------绘制图片--------------------------"""
plt.figure()
plt.subplot(2, 2, 1)
tiger_jpg1 = mpimg.imread(os.getcwd()+"\\resource\\tiger.jpg") #读取图片.
plt.imshow(tiger_jpg1) #显示图片.
plt.axis('off')
plt.subplot(2, 2, 2)
tiger_jpg2 = mpimg.imread("tiger_mc.jpg")
plt.imshow(tiger_jpg2)
plt.axis('off')
plt.subplot(2, 2, 3)
tiger_jpg3 = mpimg.imread("timg_ms.jpg")
plt.imshow(tiger_jpg3)
plt.axis('off')
plt.subplot(2, 2, 4)
tiger_jpg4 = mpimg.imread("timg_mi.jpg")
plt.imshow(tiger_jpg4)
plt.axis('off')
plt.show()

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!