python - 如何仅在 png 图像中计算红色和绿色像素的估计联合概率分布?

标签 python numpy probability

我有一个只包含红色和绿色 channel 的 png 图像。出于计算目的,我从图像中删除了蓝色 channel 。我需要计算这些像素的估计联合概率分布。我遇到了这个功能: numpy.random.multivariate_normal(均值,cov[,大小]) 但是这个计算已知分布。我需要计算估计分布。有什么建议么? 多谢。 阿瑞杰

最佳答案

很容易将数据分箱成一组直方图

#2d histogram gives you the counts, in each cell
(H,redEdges,greedEdges) = numpy.histogram2d(
    red.ravel(),green.ravel(),
    bins=nbins
)

#divide by the total to get the probability of 
#each cell -> the joint distribution
Prg = H/H.sum()

#sum over the `green` axis to get the `red` marginal (nx1)
Pr = H2d.sum(1)[:,numpy.newaxis]
#sum over the `red` axis to get the `green` marginal (1xn) 
Pg = H2d.sum(0)[numpy.newaxis,:]

从那里互信息很容易:

#calculate information contribution of each bin
dIrg = Prg*numpy.log(Prg/(Pr*Pg))
#filter nans and sum
Irg = dIrg[~numpy.isnan(dIrg)].mean()

关于python - 如何仅在 png 图像中计算红色和绿色像素的估计联合概率分布?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9002715/

相关文章:

python - 索引中的 NumPy bool 数组

ruby - 如何在 Ruby 中获取具有给定离散分布的随机数

r - 使用 R 生成密度对象的随机偏差

python - 为什么Python中可以省略一些完整引用的包名?

python - 如果添加多个窗口(pyside),进度条将无法正常工作

python - 过滤 numpy 数组以仅保留给定值的一行

python - Matplotlib plot_surface 透明度人工制品

machine-learning - 使用伪随机数生成器与马尔可夫链蒙特卡罗中的真实随机数不同吗?

python - python : java. lang.reflect.InaccessibleObjectException 上的 Apache-Spark 错误

python 电子邮件错误