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) # im = array(Image.open('E:/python/Python Computer Vision/Image data/empire.jpg').convert('L')) # 打开图像,并转成灰度图像 im = array( Image.open( 'E:/python/Python Computer Vision/Image data/AquaTermi_lowcontrast.JPG' ).convert('L')) im2, cdf = imtools.histeq(im) figure() subplot(2, 2, 1) axis('off') gray() title(u'原始图像', fontproperties=font) imshow(im) subplot(2, 2, 2) axis('off') title(u'直方图均衡化后的图像', fontproperties=font) imshow(im2) subplot(2, 2, 3) axis('off') title(u'原始直方图', fontproperties=font)
from PIL import Image from pylab import * from PCV.tools import imtools im = array(Image.open('./images/empire.jpg').convert('L')) im2, cdf = imtools.histeq(im) figure() hist(im.flatten(),128) title('Before the Histogram Equalization') figure() title('After the Histogram Equalization') hist(im2.flatten(),128) show()