python 灰度直方图_基于NumPy的灰度图像直方图均衡化

为了完整起见,我在这里给出了一个axsample,它使用了更好的变量名,并在1000个96x96图像上循环执行,这些图像与问题中的4D数组一样。它速度很快(在我的电脑上是1-2秒),只需要几分钟。import numpy as np

def image_histogram_equalization(image, number_bins=256):

# from http://www.janeriksolem.net/2009/06/histogram-equalization-with-python-and.html

# get image histogram

image_histogram, bins = np.histogram(image.flatten(), number_bins, density=True)

cdf = image_histogram.cumsum() # cumulative distribution function

cdf = 255 * cdf / cdf[-1] # normalize

# use linear interpolation of cdf to find new pixel values

image_equalized = np.interp(image.flatten(), bins[:-1], cdf)

return image_equalized.reshape(image.shape), cdf

if __name__ == '__main__':

# generate some test data with shape 1000, 1, 96, 96

data = np.random.rand(1000, 1, 96, 96)

# loop over them

data_equalized = np.zeros(data.shape)

for i in range(data.shape[0]):

image = data[i, 0, :, :]

data_equalized[i, 0, :, :] = image_histogram_equalization(image)[0]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值