Well I am not 100% sure but this is how I think you can do it:
You compute the histogram of the image and rescale it in such a way to get values from 0..1. This probability function we call p.
Then you sum up all pixels as
P(x_i) is how many pixels have color x_i (rescaled from 0..1)
Hope it helps