1.对图像的处理
首先,对图像的处理需要提前安装第三方的PIL,可利用其对图像进行缩放、裁剪、旋转、色彩转换等一些处理工作。
举例一:设置一些图像的不同模式,open().convert(). convert中,可设置出“1”、“L”、“P”等不同模式。【“L”:8 bit像素,黑白】
from PIL import Image
import os
import matplotlib.pyplot as plt
print(os.getcwd())
os.chdir('C:\\Users\\读书人mn\\Desktop\\123123')
print(os.getcwd())
im=Image.open('four.jpg').convert('L')
print(im.format,im.size,im.mode)
#im.show()
plt.imshow(im)
plt.title('wenxuan')
plt.axis('off')
plt.show()
输出结果如下:
注:标题不要用“中文”
举例二:对图像进行模糊处理
从scipy导入过滤器,im2=filters.gaussian_filter(im,20)中数字20为模糊的程度。
from scipy.ndimage import filters
import matplotlib.pyplot as plt
from pylab import *
im=array(Image.open(