【问题标题】:Plotting the histogram of 2 images which have different shapes绘制 2 张具有不同形状的图像的直方图
【发布时间】:2020-03-09 10:00:51
【问题描述】:

我想在同一个图上绘制不同形状的不同图像的直方图。 首先,我想获得最大的形状并计算较小形状和最大形状之间的增强因子,最后通过它进行归一化。

但它给了我很多变化。

例如,如果 a 具有 (100,100,1) 图像形状和 (25,25,1) 图像形状,则因子为 16,因为第一个具有比第二个多 16 倍的像素。 (4*4)

代码是

import scipy.ndimage as scim
import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure(figsize = (12,8))

band = np.random.uniform(0,1, size = (100,100,1))
ax = fig.add_subplot(2, 2, 1)    ## a voir comment modifier en fct du nb de canaux
x = np.linspace(band.min(), band.max(), 50)
y = scim.histogram(band, band.min(), band.max(), 50)
ax.plot(x, y)

band = np.random.uniform(0,1, size = (25,25,1))
ax = fig.add_subplot(2, 2, 1)    ## a voir comment modifier en fct du nb de canaux
x = np.linspace(band.min(), band.max(), 50)
y = scim.histogram(band, band.min(), band.max(), 50)
ax.plot(x, y*16) #here i multiply by 16 to get the same size
plt.show()

两个直方图相差太大。 我怎样才能得到比这更现实的东西?

【问题讨论】:

    标签: python python-3.x numpy matplotlib histogram


    【解决方案1】:

    一种常用的方法是对直方图进行归一化,例如通过它们的积分(您也可以通过它们的最大值来做到这一点,具体取决于直方图的形状):

    import scipy.ndimage as scim
    import numpy as np
    import matplotlib.pyplot as plt
    
    fig = plt.figure(figsize = (12,8))
    
    band = np.random.uniform(0,1, size = (100,100,1))
    ax = fig.add_subplot(2, 2, 1)    ## a voir comment modifier en fct du nb de canaux
    x = np.linspace(band.min(), band.max(), 50)
    y = scim.histogram(band, band.min(), band.max(), 50)
    ax.plot(x, y/y.sum())
    
    band = np.random.uniform(0,1, size = (25,25,1))
    ax = fig.add_subplot(2, 2, 1)  
    x = np.linspace(band.min(), band.max(), 50)
    y = scim.histogram(band, band.min(), band.max(), 50)
    ax.plot(x, y/y.sum()) 
    plt.show()
    

    变化是您生成的随机噪声所固有的,我看不出您期望获得什么“但它给了我很多变化。”。

    【讨论】:

    • 实际上我有 2 张图像代表相同的事物,但其中一张的系数比另一张大。我想绘制 2 张图像的直方图并进行比较。但是与第二张相比,最小的一张图像非常嘈杂,但这些噪音不是真的。
    • 您能否编辑您的帖子以显示这两个图像的实际原始直方图,或者给您带来类似问题的内容?我没有看到您发出的随机噪音的链接
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 2014-01-12
    • 1970-01-01
    • 2019-06-28
    • 2015-03-20
    • 1970-01-01
    • 2019-05-24
    相关资源
    最近更新 更多