How to generate a probability distribution on an image

南楼画角 提交于 2019-12-11 07:06:08

问题


I have a question as follows:

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.

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?

Thanks!!


回答1:


You could do it in 2D by generating radial and polar coordinates

Along the line:

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)

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.

Reference: Box-Muller sampling.

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



来源:https://stackoverflow.com/questions/54394607/how-to-generate-a-probability-distribution-on-an-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!