python 直方图 显示值_如何在图像直方图上显示超出范围的值?

我想用numpy.histogram绘制图像的RGB直方图。在

(请参阅下面我的函数draw_histogram)

它适用于[0,255]的常规范围:import numpy as np

import matplotlib.pyplot as plt

im = plt.imread('Bulbasaur.jpeg')

draw_histogram(im, minimum=0., maximum=255.)

23dd1fe172f4d234e48bf59fdae000b6.png

67ad50f502ccda6479bf0e314f7cda0c.png

我想做什么:

我希望我使用的图像值超出范围。有时它们会超出范围,有时不会。我想用RGB直方图来分析这些值有多差。在

假设我期望值在区间[-512,512]中最差。我仍然希望直方图在正确的位置显示范围内的强度,而将未填充的范围部分留空。例如,如果我再次绘制Bulbasaur.jpeg的直方图,但范围为[-512,512],我希望看到相同的直方图,但沿“x”轴收缩(在下面的直方图中的两条虚线之间)。在

问题:

当我试图绘制非规则范围的直方图时,出现了一些错误:

^{pr2}$

74519d76deb9888c7897d5b7bf0316fc.png

我的draw_histogram()代码:def draw_histogram(im, minimum, maximum):

fig = plt.figure()

color = ('r','g','b')

for i, col in enumerate(color):

hist, bins = np.histogram(im[:, :, i], int(maximum-minimum), (minimum, maximum))

plt.plot(hist, color=col)

plt.xlim([int(minimum), int(maximum)])

# Draw vertical lines to easily locate the 'regular range'

plt.axvline(x=0, color='k', linestyle='dashed')

plt.axvline(x=255, color='k', linestyle='dashed')

plt.savefig('Histogram_Bulbasaur.png')

plt.close(fig)

return 0

问题

有没有人知道一种正确绘制不规则范围的RGB直方图的方法?在

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值