第一章 图像处理基础实验小结
一、需要安装代码中所使用到的库,包括PIL图像处理库、Matplotlib库、numpy库、scipy库、PCV库。
安装PIL、numpy、scipy、Matplotlib,在命令行中使用pip install PIL/numpy/scipy/Matplotlib语句,对各库直接进行下载,所参考的教程有:https://blog.****.net/u011321546/article/details/79499598
https://www.cnblogs.com/pcat/p/6790058.html
https://www.cnblogs.com/xuxugui/p/9815237.html
安装PCV,下载本书对应的中译版源码,在命令行界面进入PCV目录下,使用python setup.py install语句,完成安装。所参考的教程为:https://blog.****.net/GarfieldEr007/article/details/50757070。
二、实验测试部分
1、图像的直方图
from PIL import Image
from pylab import *
from PCV.tools import imtools
im=Image.open(‘D:/PCV/1.jpg’)
im1 = array(im.convert(‘L’))
im2, cdf = imtools.histeq(im1)
figure()
subplot(1, 2, 1)
axis(‘off’)
title(u’原图’, fontproperties=font)
imshow(im1)
subplot(1, 2, 2)
axis(‘off’)
title(u’直方图’, fontproperties=font)
hist(im.flatten(), 128, normed=True)
show()
2、图像的直方图均衡
from PIL import Image
from pylab import *
from PCV.tools import imtools
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:\windows\fonts\SimSun.ttc", size=14)
figure()
im = array(Image.open(‘D:/PVC/1.jpg’).convert(‘L’))
im2, cdf = imtools.histeq(im)
subplot(121)
axis(‘off’)
title(u’直方图均衡化后的图像’, fontproperties=font)
imshow(im2)
subplot(122)
axis(‘off’)
title(u’均衡化后的直方图’, fontproperties=font)
hist(im2.flatten(), 128, normed=True)
show()
3、图像的高斯滤波
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:\windows\fonts\SimSun.ttc", size=14)
im = array(Image.open(‘D:/PVC/1.jpg’).convert(‘L’))
G = filters.gaussian_filter(im,10)
figure()
gray()
subplot(1,1,1)
imshow(G)
#axis(‘equal’)
axis(‘off’)
title(u’高斯模糊后的图像’, fontproperties=font)
show()
4、实验过程错误
输入格式错误,Python中\是转义字符,而路径中\t是制表字符,需将 \ 换为 /
因为python2.X版本与python3.X版本输出方式不同而报错,输入内容时需带上括号