pythonimagenoisepoisson

Adding poisson noise to an image


I have some images that I need to add incremental amounts of Poisson noise to in order to more thoroughly analyze them. I know you can do this in MATLAB, but how do you go about doing it in Python? Searches have yielded nothing so far.


Solution

  • If numpy/scipy are available to you, then the following should help. I recommend that you cast the arrays to float for intermediate computations then cast back to uint8 for output/display purposes. As poisson noise is all >=0, you will need to decide how you want to handle overflow of your arrays as you cast back to uint8. You could scale or truncate depending on what your goals were.

    filename = 'myimage.png'
    imagea = (scipy.misc.imread(filename)).astype(float)
    
    poissonNoise = numpy.random.poisson(imagea).astype(float)
    
    noisyImage = imagea + poissonNoise
    
    #here care must be taken to re cast the result to uint8 if needed or scale to 0-1 etc...