When working with confocal data, I found out that both noise and signal pixel value distribution could be very well fitted by a gamma distribution, with an offset.
The pixel values were of the form Y=offset+X, where X is a random variable following the distribution G(k,t), with k and t the shape and scale parameter respectively.
The first job was to fit the parameters of the distribution. This is very easily done as there is a relationship between offset,k,t and the three first moments of the distribution ; I wrote a function gamma_params.m that does just that.
The second was to generate gamma-distributed random variables. For this, I relied on code from the octave library. This code is originally in C, and I implemented it in Matlab’s, using Matlab’s matrix algebra abilities to parallelize the generation – and it’s now decently fast. This is availabe in parallel_randg.m.
Distribution of pixel values for noise (red, n=23000 pixels) and signal (blue, n=1000 pixels), for a confocal microscopy image (dots) and for a simulated microscopy image (lines). y-axis : pixel fraction, x-axis : normalized pixel insensity.