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),cdf pil_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:原图的灰度图
图2:进行直方图均衡化后的图像
图3:原图灰度图的直方图
图4:进行直方图均衡化后的直方图
图5:灰度变换函数
以上就是python 对一幅灰度图像进行直方图均衡化的详细内容,更多关于python 直方图均衡化的资料请关注其它相关文章!
风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 梁汉文2008-EDMONDHITS48[香港]3CD[WAV+CUE]
- 国风大师纯音系列《童丽-[渭城曲]》1CD[WAV分轨][593.5MB]
- 国风大师纯音系列《许菱子《烧筝2》古筝曲集》1CD[WAV分轨][1.3GB]
- 王子异《1996 Part.2》[320K/MP3][18.29MB]
- 群星.1994-宝丽金最倾情3CD【宝丽金】【WAV+CUE】
- 乐俊亨.2024-同泪【CharioticMusic】【FLAC分轨】
- 何耀珊.2006-收获【华纳】【WAV+CUE】
- 梁汉文1994-壹精选[华星][WAV+CUE]
- 洪荣宏1981-歹路不可行·相思雨(飞跃复刻版)[光美][WAV+CUE]
- 旅行团2015-10Day’s[来福胶泥][WAV+CUE]
- 龙千玉.2011-卡将哟【豪记】【WAV+CUE】
- 蔣志光.1993-多情多寂寞(国专)【BMG】【WAV+CUE】
- 陈慧娴.1996-雪映美白96演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 王子异《1996 Part.2》[FLAC/分轨][50.66MB]
- 贵族音乐《古典名曲与轻音乐钢琴 打开宝宝睡眠开关》[320K/MP3][155.91MB]