如何在图像上生成概率分布 [英] How to generate a probability distribution on an image
问题描述
我有一个问题,如下:
假设我有一个图像(大小= 360x640(逐行显示)),并且我有一个中心坐标,即(20,100).我想要的是生成一个概率分布,该概率分布在该中心具有最高的值(20,100),而在邻域中具有较低的概率值,而其值远比该中心低得多.
Suppose I have an image(size=360x640(row by col)), and I have a center coordinate that's say is (20, 100). What I want is to generate a probability distribution that has the highest value in that center (20,100), and lower probability value in the neighbor and much more lower value farer than the center.
我所知道的是放一个多元高斯(因为尺寸为2D)并将均值设置为中心(20,100).但这是正确的,我该如何设计协方差矩阵?
All I figure out is to put a multivariate gaussian (since the dimension is 2D) and set mean to the center(20,100). But is that correct and how do I design the covariance matrix?
谢谢!
推荐答案
您可以通过生成径向和极坐标以2D方式实现
You could do it in 2D by generating radial and polar coordinates
沿线:
Pi = 3.1415926
cx = 20
cy = 100
r = sqrt( -2*log(1-U(0,1)) )
a = 2*Pi*U(0,1)
x = scale*r*cos(a)
y = scale*r*sin(a)
return (x + cx, y + cy)
其中,scale
是使它从无单位的高斯变为适用于您的问题的某个单位的参数. U(0,1)
在[0 ... 1)随机值中是一致的.
where scale
is a parameter to make it from unitless gaussian to some unit applicable to your problem. U(0,1)
is uniform in [0...1) random value.
参考: Box-Muller抽样.
如果要使用通用2D高斯,即2D中的椭圆,则必须对X和Y使用不同的比例,并使用众所周知的旋转矩阵按预定角度旋转(x,y)向量
If you want generic 2D gaussian, meaning ellipse in 2D, then you'll have to use different scales for X and Y, and rotate (x,y) vector by predefined angle using well-known rotation matrix
这篇关于如何在图像上生成概率分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!