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

文章目录一、直方图二、使用步骤1.引入库2.读入数据总结一、直方图二、使用步骤1.引入库代码如下(示例):import numpy as npimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsimport warningswarnings.filterwarnings('ignore')import sslssl._create_default_https_context = ssl._c
摘要由CSDN通过智能技术生成


一、直方图

1. 原理描述

直方图是可以对整幅图的灰度分布进行整体了解的图示,通过直方图我们可以对图像的对比度、亮度和灰度分布等有一个直观了解。
图像的直方图用来表征该图像像素值的分布情况。用一定数目的小区间(bin)来指定表征像素值的范围,每个小区间会得到落入该小区间表示范围的像素数目。该(灰度)图像的直方图可以使用hist()函数绘制。

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)


'''
Parameters:
    path - 文件路径
Returns:
    无
'''
# 函数说明:绘制图像灰度直方图
def histogram(path):
    img = array(Image.open(path))
    img_gray = array(Image.open(path).convert('L'))

    figure()
    subplot(221)
    axis('off')
    title(u'原图像', fontproperties=font)
    imshow(img)

    subplot(222)
    axis('off')
    gray()
    title(u'灰度图像', fontproperties=font)
    imshow(img_gray)

    subplot(212)
    title(u'灰度直方图', fontproperties=font)
    hist
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值