实验中用到了matplotlib,简单记录一下。
使用教程:https://matplotlib.org/users/pyplot_tutorial.html
例子:
from matplotlib.font_manager import FontProperties
font_set = FontProperties(fname=r"c:windowsfontssimsun.ttc", size=12)#使用中文需要
from PIL import Image #Pillow图像库
import matplotlib.pyplot as plt
%matplotlib inline #jupyter notebook内联显示
from PIL import ImageFilter #Pillow 滤波
from PIL import ImageEnhance
img = Image.open("./XXX.tif")
plt.figure(figsize=(10,8),dpi=108) #
p1 = plt.subplot(221)
p2 = plt.subplot(222)
p3 = plt.subplot(223)
p4 = plt.subplot(224)
p1.imshow(img)
p1.set_title("原始图像",fontproperties=font_set)
imgEH = ImageEnhance.Contrast(img)
contrast = 1.5
image_contrasted = imgEH.enhance(contrast)
p2.imshow(image_contrasted)
p2.set_title("增强对比度",fontproperties=font_set)
enh_sha = ImageEnhance.Sharpness(img)
sharpness = 3.0
image_sharped = enh_sha.enhance(sharpness)
p3.imshow(image_sharped)
p3.set_title("锐化",fontproperties=font_set)
enh_bri = ImageEnhance.Brightness(img)
brightness = 1.5
image_brightened = enh_bri.enhance(brightness)
p4.imshow(image_brightened)
p4.set_title("亮度增加",fontproperties=font_set)
plt.show()