Search code examples
pythonimagenumpyimage-processingpoisson

Image: Numpy random poisson function lam < 0 Value error


I start with an image and do some processing on it. One of its stages involves adding Poisson distribution to the image. I have a function taking an array and which returns a poisson distribution image. In reality when I run the numpy image array through the numpy Poisson function ,I get the following error

File "mtrand.pyx", line 3994, in mtrand.RandomState.poisson
ValueError: lam < 0

My question is it because of my data the error is coming or something else.

import numpy as np
def poisson(mean, shape=1): #mean is the image np array I want Poisson distribution on
        print(mean.shape,'this is the shape')
        np.savetxt('array.txt',mean,delimiter=',')
        return np.random.poisson(mean)

Here is the np array saved in array.txt file. Any help is greatly appreciated. https://drive.google.com/file/d/1bxo49r4qmdaIwxZ7VGV9897TAVU1RIlW/view?usp=sharing


Solution

  • Your error comes from the fact that you defined a Poisson distribution with negative lambda parameter (negative mean) somewhere which makes no sense.