首页 技术 正文
技术 2022年11月14日
0 收藏 433 点赞 4,955 浏览 764 个字
from PIL import Image
from pylab import *
from numpy import *def histeq(im,nbr_bins = 256):
"""对一幅灰度图像进行直方图均衡化"""
#计算图像的直方图
#在numpy中,也提供了一个计算直方图的函数histogram(),第一个返回的是直方图的统计量,第二个为每个bins的中间值
imhist,bins = histogram(im.flatten(),nbr_bins,normed= True)
cdf = imhist.cumsum() #
cdf = 255.0 * cdf / cdf[-1]
#使用累积分布函数的线性插值,计算新的像素值
im2 = interp(im.flatten(),bins[:-1],cdf)
return im2.reshape(im.shape),cdfpil_im = Image.open('E:\Python\\fanwei.jpg') #打开原图
pil_im_gray = pil_im.convert('L') #转化为灰度图像
pil_im_gray.show() #显示灰度图像im = array(Image.open('E:\Python\\fanwei.jpg').convert('L'))
# figure()
# hist(im.flatten(),256)im2,cdf = histeq(im)
# figure()
# hist(im2.flatten(),256)
# show()im2 = Image.fromarray(uint8(im2))
im2.show()
# print(cdf)
# plot(cdf)
im2.save("junheng.jpg")

图1:原图的灰度图

python——直方图均衡化

图2:进行直方图均衡化后的图像

python——直方图均衡化

图3:原图灰度图的直方图

python——直方图均衡化

图4:进行直方图均衡化后的直方图
python——直方图均衡化

图5:灰度变换函数

python——直方图均衡化

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,093
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,569
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,417
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,190
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,825
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,908