The distribution of distances between two random points in RGB space

discrete geometrydiscrete mathematicsimage processingprobabilityprobability distributions

Suppose we pick pairs of triples from $\{ 0, 1, 2, \dots, 255\}^3$ with a uniform distribution and would like to find a closed form for the distribution of the Euclidean distances

$$ d((x_1, x_2, x_3), (y_1, y_2, y_3)) = \left( \sum_{j=1}^3 (x_j-y_j)^2 \right)^{1/2}.$$

The motivation for this question comes from the cubic lattice that is one of the RGB color spaces. It would be nice to have an exact probability distribution because it would likely have interesting applications in image processing.

This question gives the answer for when a cube includes all real numbers in it, and there's Mathai et al.$^\color{magenta}{\star}$, but what about when it is discrete, like for a cubic lattice?


$\color{magenta}{\star}$ Arak M. Mathai, Peter Moschopoulos, Giorgio Pederzoli, Distance between random points in a cube [PDF], Statistica, Volume 59, Number 1, 1999.

Best Answer

Let $X$ be the random variable you defined. For a natural number $n$, the probability $\mathbb P[X=\sqrt n]$ is going to be some multiple of the number of ways of writing $n$ as a sum of three squares, up to boundary effects. There exist relatively simple ways of counting the number of representations of $n$ as sums of two or four squares, but which rely on the prime factorization of $n$ which already makes them complicated. For three squares, I think it's fair to say that there's no closed form. For example if $n=4^a(8b+7)$ for positive integers $a,b$ then there are no representations as sums of three squares and consequently $\mathbb P[X=\sqrt n]=0$.

These difficulties, of course only exist if you insist on computing the PDF of $X$ in closed form. If you instead ask for $\mathbb P[X\leq t]$ as a function of $t$, you can get fairly good approximations. In fact, that is a three-dimensional version of the Gauss circle problem.

Related Question