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?

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

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.