Python 计算机视觉 第一章 图像处理基础

Python 计算机视觉 第一章 图像处理基础

第一章 图像处理基础

1.1灰度图
PIL (Python Imaging Library)图像库提供了很多常用的图像处理及很多有用的图像基本操作。

-- coding: utf-8 --

from PIL import Image
from pylab import *

from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:\windows\fonts\SimSun.ttc", size=14)
figure()

pil_im = Image.open(‘D:/05.jpg’)
gray()
subplot(121)
title(u’原图’,fontproperties=font)
axis(‘off’)
imshow(pil_im)

pil_im = Image.open(‘D:/05.jpg’).convert(‘L’)
subplot(122)
title(u’灰度图’,fontproperties=font)
axis(‘off’)
imshow(pil_im)

show()

运行得到如下效果

在这里插入图片描述
在这里插入图片描述

1.2 直方图
from PIL import Image
from pylab import *

from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:\windows\fonts\SimSun.ttc", size=14)
im = array(Image.open(‘D:/05.jpg’).convert(‘L’))

figure()
hist(im.flatten(), 128)
title(u’图像直方图’, fontproperties=font)
plt.xlim([0,260])
plt.ylim([0,11000])

运行上述代码可以得到直方图,如下:
在这里插入图片描述

1.3直方图均衡化
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(’…/data/empire.jpg’).convert(‘L’))
#im = array(Image.open(’…/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)
#hist(im.flatten(), 128, cumulative=True, normed=True)
hist(im.flatten(), 128, normed=True)

subplot(2, 2, 4)
axis(‘off’)
title(u’均衡化后的直方图’, fontproperties=font)
#hist(im2.flatten(), 128, cumulative=True, normed=True)
hist(im2.flatten(), 128, normed=True)

show()

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值