绘制两个形状不同的图像的直方图

时间:2020-03-09 10:00:51

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

我想在同一图形上绘制不具有相同形状的不同图像的直方图。 首先,我想得到最大的形状,然后计算较小形状和最大形状之间的增大因子,以最终对其进行归一化。

但这给了我很多变化。

例如,如果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()

2个直方图过于不同。 我怎么能得到比这更现实的东西?

1 个答案:

答案 0 :(得分:0)

通常的方法是对直方图进行归一化,例如通过积分(可以根据直方图的形状通过最大值进行归一化):

<html>
<head>
</head>
<body>
<input type="text" name="n">
</body>
</html>

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

enter image description here