python计算机视觉Chapter1 fig1-3

图像的轮廓绘制时,使用的是全局阈值。
代码:

# -*- coding: utf-8 -*-
"""
created on Friday June 22 17:22 2018
@author: Jerry
"""
# 使用 Matplotlib 绘制图像等轮廓线和直方图
from PIL import Image
from pylab import *
# 添加中文字体支持
import matplotlib as mpl
font = mpl.font_manager.FontProperties(fname='/python_work/SimHei.ttf')
im = array(Image.open('empire.jpg').convert('L'))
figure()
subplot(121)
contour(im,origin='image') # 显示的是彩色图像
gray() # 不使用颜色信息
title(u'图像等轮廓线',fontproperties=font)
axis('off')
subplot(122)
hist(im.flatten(),128) # hist输入需是一维数组,flatten()对图像进行压平处理,256影响的是直方图显示的宽度,即指定小区间的数目,数目越大,线越密集
title(u'灰度直方图',fontproperties=font)
show()

结果展示:
这里写图片描述

猜你喜欢

转载自blog.csdn.net/wugui1111/article/details/80776815
今日推荐