灰度图的直方图均衡化(HistogramEqualization)原理与Python实现

更新时间:2023-07-20 18:38:30 阅读: 评论:0

灰度图的直⽅图均衡化(HistogramEqualization)原理与
Python实现天外飞星
原理
  直⽅图均衡化是⼀种通过使⽤图像直⽅图,调整对⽐度的图像处理⽅法;通过对图像的强度(intensity)进⾏某种⾮线性变换,使得变换后的图像直⽅图为近似均匀分布,从⽽,达到提⾼图像对⽐度和增强图⽚的⽬的。普通的直⽅图均衡化采⽤如下形式的⾮线性变换:
  设f 为原始灰度图像,g 为直⽅图均衡化的灰度图像,则g 和f 的每个像素的映射关系如下:
齐秦个人资料简介
  其中,L 为灰度级,通常为 256,表明了图像像素的强度的范围为 0 ~ L-1;
  p n 等于图像f 中强度为 n 的像素数占总像素数的⽐例,即原始灰度图直⽅图的概率密度函数;
f i,j 表⽰在图像f 中,第 i ⾏,第 j 列的像素强度;
g i,j 表⽰在图像g 中,第 i ⾏,第 j 列的像素强度.
Python 实现心存善念
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""
炸葱油饼的做法# Author: klchang
# Date: 2018.10
# Description:
histogram equalization of a gray image.
"""
from__future__import print_function
import numpy as np
import matplotlib.pyplot as plt
def histequ(gray, nlevels=256):
# Compute histogram
histogram = np.bincount(gray.flatten(), minlength=nlevels)
print ("histogram: ", histogram)
# Mapping function
uniform_hist = (nlevels - 1) * (np.cumsum(histogram)/(gray.size * 1.0))
uniform_hist = uniform_hist.astype('uint8')
print ("uniform hist: ", uniform_hist)
风清月朗
# Set the intensity of the pixel in the raw gray to its corresponding new intensity
唤醒height, width = gray.shape
uniform_gray = np.zeros(gray.shape, dtype='uint8')  # Note the type of elements
for i in range(height):
for j in range(width):
uniform_gray[i,j] = uniform_hist[gray[i,j]]
return uniform_gray
if__name__ == '__main__':
fname = "320px-Unequalized_Hawkes_Bay_NZ.png"# Gray image
# Note, matplotlib natively only read png images.
gray = plt.imread(fname, format=np.uint8)
if gray is None:
print ("Image {} does not exist!".format(fname))
exit(-1)
# Histogram equalization
uniform_gray = histequ(gray)
# Display the result
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.t_title("Raw Image")
ax1.imshow(gray, 'gray')
ax1.t_xticks([]), ax1.t_yticks([])
ax2.t_title("Histogram Equalized Image")
ax2.imshow(uniform_gray, 'gray')
ax2.t_xticks([]), ax2.t_yticks([])
fig.tight_layout()
plt.show()拼音本写拼音
原始图⽚ 320px-Unequalized_Hawkes_Bay_NZ.png
结果显⽰
参考资料
[1]. Histogram_equalization - Wikipedia. en.wikipedia/wiki/Histogram_equalization
[2]. Histogram Equalization. www.math.uci.edu/icamp/cours/math77c/demos/hist_eq.pdf孙灏

本文发布于:2023-07-20 18:38:30,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1089449.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:图像   像素   强度   灰度   均衡化   简介   心存   葱油饼
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图