Bivariate Gaussian

From neurov.is/on

Jump to: navigation, search

The bivariate Gaussian can be written as:


f(x,y)
=
\frac{1}{2 \pi \sigma_x \sigma_y \sqrt{1-\rho^2}}
\exp
\left(
 -\frac{1}{2 (1-\rho^2)}
 \left[
  \frac{\left(x - \mu_x\right)^2}{\sigma_x^2} +
  \frac{\left(y - \mu_y\right)^2}{\sigma_y^2} -
  \frac{2 \rho \left(x - \mu_x\right) \left(y - \mu_y\right)}{ (\sigma_x \sigma_y)}
 \right]
\right)

where ρ is the correlation between X and Y. In other words


\Sigma =
\begin{bmatrix}
\sigma_x^2              & \rho \sigma_x \sigma_y \\
\rho \sigma_x \sigma_y  & \sigma_y^2
\end{bmatrix}.

[edit] From Wikipedia

In two-dimensions, one can vary a Gaussian in more parameters: not only may one vary a single width, but one may vary two separate widths, and rotate: one thus obtains both circular Gaussians and elliptical Gaussians, accordingly as the level sets are circles or ellipses.

A particular example of a two-dimensional Gaussian function is

f(x,y) = A e^{- \left(\frac{(x-x_o)^2}{2\sigma_x^2} + \frac{(y-y_o)^2}{2\sigma_y^2} \right)}.

Here the coefficient A is the amplitude, xo,yo is the center and σx, σy are the x and y spreads of the blob. The figure on the right was created using A = 1, xo = 0, yo = 0, σx = σy = 1.

In general, a two-dimensional elliptical Gaussian function is expressed as

f(x,y) = A e^{- \left(a(x - x_o)^2 + 2b(x-x_o)(y-y_o) + c(y-y_o)^2 \right)}

where the matrix

\left[\begin{matrix} a & b \\ b & c \end{matrix}\right]

is positive-definite.

Using this formulation, the figure on the right can be created using A = 1, (xo, yo) = (0, 0), a = c = 1/2, b = 0.

[edit] Meaning of parameters for the general equation

For the general form of the equation the coefficient A is the height of the peak and (xoyo) is the center of the blob.

If we set

a = \frac{\cos^2\theta}{2\sigma_x^2} + \frac{\sin^2\theta}{2\sigma_y^2}


b = -\frac{\sin2\theta}{4\sigma_x^2} + \frac{\sin2\theta}{4\sigma_y^2}


c = \frac{\sin^2\theta}{2\sigma_x^2} + \frac{\cos^2\theta}{2\sigma_y^2}

then we rotate the blob by an angle θ. This can be seen in the following examples:

Using the following MATLAB code one can see the effect of changing the parameters easily

A = 1;
x0 = 0; y0 = 0;
 
sigma_x = 1;
sigma_y = 2;
 
for theta = 0:pi/100:pi
a = cos(theta)^2/2/sigma_x^2 + sin(theta)^2/2/sigma_y^2;
b = -sin(2*theta)/4/sigma_x^2 + sin(2*theta)/4/sigma_y^2 ;
c = sin(theta)^2/2/sigma_x^2 + cos(theta)^2/2/sigma_y^2;
 
[X, Y] = meshgrid(-5:.1:5, -5:.1:5);
Z = A*exp( - (a*(X-x0).^2 + 2*b*(X-x0).*(Y-y0) + c*(Y-y0).^2)) ;
surf(X,Y,Z);shading interp;view(-36,36);axis equal;drawnow
end

Such functions are often used in image processing and in computational models of visual system function -- see the articles on scale space and affine shape adaptation.

Also see multivariate normal distribution.

Personal tools