# Sampling a two-dimensional Gaussian distribution at points along an integer lattice

Please consider a two-dimensional Gaussian of the general form: $A*e^{-(\frac{(x-x_0)}{2\sigma_x^2}+\frac{(y-y_0)}{2\sigma_y^2})}$, where $C$ is the peak of the Gaussian, i.e. the point at which the value of the Gaussian function is largest (equivalently we can say that $C = \mu$, the mean of the distribution). We now conceptually overlay a lattice of pixels (of sidelength $L$) on this two-dimensional Gaussian, and assign each pixel a value corresponding to the mean value of the Gaussian function that falls inside its square borders.

Let $C^*$ be a pixel value weighted average over all pixel vertices in the lattice. To compute $C^*$, we calculate a weighted mean $x_0$ and $y_0$ component in the manner illustrated below this question.

What is $C - C^*$ as a function of $L$? For what lattice overlay geometry is this difference largest?

For example, we might expect that for $L >> (\sigma_x,\sigma_y)$, this difference will be quite large in the worse case (where the Gaussian is near one of the pixel corners), giving us a difference of $C-C^* \approx \frac{\sqrt{2}L}{2}$. Note that by "the worst case" we mean a conspiratorial placement of the integer lattice of pixels over the 2D Gaussian that maximizes the difference between $C$ and $C^*$. In the limit of $L << (\sigma_x,\sigma_y)$, we might expect to have $C - C^* \approx 0$, regardless of how one shifts the lattice around over the 2D Gaussian.

Update -

To better explain what I mean by "pixel value weighted average" consider the following one-dimensional example where we have ten pixels at the positions:

$p = (0,1,2,3,4,5,6,7,8,9)$

With the values:

$v = (0, 0, 1, 2, 3, 0, 0, 0, 1, 0)$

We would then calculate the "pixel value weighted average" as:

$C^*=\frac{\sum_{i=1}^{10}(p(i) v(i))}{\sum_{i=1}^{10} v(i)} = 4$

However, in the problem description we define $C^*$ as a weighted centroid in two-dimensions. To illustrate how we extend the previous method, consider the following $3 \times 3$ matrix of pixel positions:

p = $(((0, 0), (1, 0), (2, 0)), ((0, 1), (1, 1), (2, 1)), ((0, 2), (1, 2), (2, 2)))$

Here, each pixel position has a corresponding value:

v = $((56, 78, 2), (87, 5, 2), (99, 1, 800))$

We now multiply each pixel value by its $x$-coordinate, and compute an average:

$C^*=\frac{\sum_{i=1}^{3} \sum_{k=1}^{3} (p(i,k)_x v(i,k))}{\sum_{i=1}^{3} \sum_{k=1}^{3} v(i,k)} = x_0 = \frac{846}{565}$

And do the same for the $y$-coordinate:

$C^*=\frac{\sum_{i=1}^{3} \sum_{k=1}^{3} (p(i,k)_y v(i,k))}{\sum_{i=1}^{3} \sum_{k=1}^{3} v(i,k)} = y_0 = \frac{947}{565}$

To yield $C^* = (x_0, y_0) = (\frac{846}{565}, \frac{947}{565})$

• Can you define the intensity centroid? – Liviu Nicolaescu Nov 29 '13 at 13:47
• @LiviuNicolaescu Sorry about that, I just meant to say that it should be an average weighted by the values corresponding to the pixels. – Richard Nov 29 '13 at 14:03
• I am still a bit confused. You define $C$ the centroid of this elliptical function. To me the centroid is a point, thus defined by a pair of real numbers $(x_0,y_0)$. According to your update $C^*$ is a number. What is then the meaning of $C-C^*$? – Liviu Nicolaescu Nov 29 '13 at 14:35
• @LiviuNicolaescu The example was meant as a simplified one-dimensional illustration of what I meant by "pixel value weighted average". In the actual problem, one needs to take into consideration both $x$ and $y$-components. Let me clarify the example. – Richard Nov 29 '13 at 15:03
• It would help if in your question you describe precisely the nature of $C$, $C^*$. Also the statement "Imagine that this means we overlay an integer lattice (of edge length L) on top of the Gaussian function, and assign each vertex a value corresponding to the mean value of the function in the area it overlays." is confusing because it seems you are talking about two functions, but you have introduced only a Gaussian function. Also, you need to know that in math, the term elliptic function is reserved to very precise, and quite complicated functions. – Liviu Nicolaescu Nov 29 '13 at 15:16