计算机视觉-基本的图像操作和处理


一、常用的库

在这里插入图片描述

二、读取图像及其直方图

直方图原理:图像的直方图用来表征该图像像素值的分布情况。计算图像中的某种信息,例如像素值的多少,然后将数据分为若干个定义好的区间内。

def func1():
    im = array(Image.open('D:\python\projects\计算机视觉\image\img1.jpg').convert('L'))  # 打开图像,并转成灰度图像

    gray()  # 设置为灰度
    subplot(121)
    imshow(im)

    subplot(122)
    hist(im.flatten(), 128)
    title(u'图像直方图', fontproperties=font)
    plt.xlim([0, 260])  # 限制x和y
    plt.ylim([0, 11000])

    show()

在这里插入图片描述

三、图像高斯模糊

高斯模糊(高斯滤波):通过二维高斯函数和像素卷积得到模糊后的图像。
在这里插入图片描述

def func2():
    im = array(Image.open('D:\python\projects\计算机视觉\image\img1.jpg').convert('L'))  # 打开图像,并转成灰度图像
    gray()
    im2 = filters.gaussian_filter(im, 2)
    im3 = filters.gaussian_filter(im, 5)
    im4 = filters.gaussian_filter(im, 10)
    subplot(131)
    imshow(im2)
    title(u'σ=2', fontproperties=font)
    subplot(132)
    imshow(im3)
    title(u'σ=5', fontproperties=font)
    subplot(133)
    imshow(im4)
    title(u'σ=10', fontproperties=font)

    show()

在这里插入图片描述

四、图像和直方图均衡化

图像和直方图均衡化的原理可以归纳为将某个灰度映射到另一个灰度。
在这里插入图片描述

def func3():
    im = array(Image.open('D:\python\projects\计算机视觉\image\img1.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)

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

    show()

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值