I managed to add poisson noise to my .fits image, but I need to add noise that is distributed like a gaussian with mean/median (mu_0) of 0 and an increasingly wider distribution (sigma). I couldn't find the syntax governing the adding of noise in this way, so can somebody please walk me through it? At the moment, the poisson noise I added is evenly distributed, which isn't what I want; I need the gaussian randomness.
Here's the relevant bit of code:
im = pf.open(name)
isinstance(im,list)
im0 = im[0]
print im0.data.shape
print np.var(im0.data)
poissonNoise = np.random.poisson(poisson, im0.data.shape).astype(float)
test = im0.data + poissonNoise
print np.var(test)
im0.data = test
stringee = 'POISSON'
pf.writeto(stringee+poisson+name, data=test, clobber=True, header=im0.header)
check = pf.open(stringee+poisson+name)
np.var(check[0].data)
For gaussian distributions (normal distributions) use np.random.normal
.
normalNoise = np.random.normal(center, scale, shape).astype(float)
See more here : NumPy Normal and more generally for all the types: NumPy Random
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.