python 對一幅灰度圖像進(jìn)行直方圖均衡化
from PIL import Imagefrom pylab import *from numpy import *def histeq(im,nbr_bins = 256): '''對一幅灰度圖像進(jìn)行直方圖均衡化''' #計(jì)算圖像的直方圖 #在numpy中,也提供了一個(gè)計(jì)算直方圖的函數(shù)histogram(),第一個(gè)返回的是直方圖的統(tǒng)計(jì)量,第二個(gè)為每個(gè)bins的中間值 imhist,bins = histogram(im.flatten(),nbr_bins,normed= True) cdf = imhist.cumsum() # cdf = 255.0 * cdf / cdf[-1] #使用累積分布函數(shù)的線性插值,計(jì)算新的像素值 im2 = interp(im.flatten(),bins[:-1],cdf) return im2.reshape(im.shape),cdfpil_im = Image.open(’E:Pythonfanwei.jpg’) #打開原圖pil_im_gray = pil_im.convert(’L’) #轉(zhuǎn)化為灰度圖像pil_im_gray.show() #顯示灰度圖像im = array(Image.open(’E:Pythonfanwei.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:進(jìn)行直方圖均衡化后的圖像
圖3:原圖灰度圖的直方圖
圖4:進(jìn)行直方圖均衡化后的直方圖
圖5:灰度變換函數(shù)
以上就是python 對一幅灰度圖像進(jìn)行直方圖均衡化的詳細(xì)內(nèi)容,更多關(guān)于python 直方圖均衡化的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. .Net Core和RabbitMQ限制循環(huán)消費(fèi)的方法2. jsp網(wǎng)頁實(shí)現(xiàn)貪吃蛇小游戲3. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說明4. ASP.NET MVC遍歷驗(yàn)證ModelState的錯(cuò)誤信息5. 用css截取字符的幾種方法詳解(css排版隱藏溢出文本)6. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向7. asp中response.write("中文")或者js中文亂碼問題8. PHP設(shè)計(jì)模式中工廠模式深入詳解9. CSS hack用法案例詳解10. 將properties文件的配置設(shè)置為整個(gè)Web應(yīng)用的全局變量實(shí)現(xiàn)方法
