图像处理python代码实现之直⽅图均衡化
直⽅图均衡化是⼀种⽐较常⽤的图像处理⽅法,其主要作⽤是增加局部对⽐度⽽不失整体对⽐度,可以突出图像⼀些细节的特征。代码实现:
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
def histeq(img_path,nbr_bins=256):
img = Image.open(img_path)
img = np.array(img,"f")
# """ Histogram equalization of a grayscale image. """
imhist, bins, patches = plt.hist(img.flatten(), nbr_bins, normed = True)
cdf = imhist.cumsum() # cumulative distribution function
cdf =255* cdf /cdf[-1]
result = np.interp(img.flatten(),bins[:-1],cdf)
result = shape(img.shape)
imsave(place("test_corre2d","test_corre2d_histeq"),result)
局部直方图均衡化
直⽅图均衡化前后对⽐:
本⽂来⾃本⼈课题项⽬总结,并⾮最好之⽅案和代码。如有错误,欢迎指正与赐教!

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