我有一个只包含红色和绿色 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/