# Redistributing Color in a RGB Image According to a Gaussian Distribution

I haven't done this stuff in a while.

If I have an image $I$ I can equalize the histogram of the image using some opencv procedure, it's already defined. Equalizing an histogram means essentially to construct a function such that applied to each pixel $p \in I$ the new value it's like it had been sampled from a uniform distribution, assuming gray scale image for such explanation.

I don't remember if what I want to do has a specific name, but I kind of remember it was possible, but suppose I have a gaussian distribution (instead of a uniform one), say $\mathcal{N}(0,\Sigma)$, and I want to re-distribute the colors according to such distribution.

Is there a way to do this in opencv?

• Where each pixel is 3 Dimensional Random Variable? – Royi May 3 '18 at 7:37
• Yes, you can consider it like that. – user8469759 May 3 '18 at 7:39
• Yes, but I haven't implemented it yet – user8469759 May 12 '18 at 8:40

## 1 Answer

After you equalize the histogram you can think of your data as a stream of variables ${X}_{i}$ where $X \sim U \left[ 0, 1 \right]$.

Now all you need is to transform samples of Uniform Random Variable into Gaussian Variable.
You should do that by applying the Inverse CDF of Gaussian Distribution.
Basically applying the Inverse Transform Sampling method.
For Normal Distribution easy choice would be the Box Muller Transform.

After you apply this, you can just multiply each RGB pixel in the Cholesky Factorization of $\Sigma$ to get exactly what you need.