0

I'm having a little bit of trouble using numpy.random.normal. At the bottom of this link (http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.normal.html) there's a graph which shows standard deviations. I'm a little confused about this, because it doesn't look like 0.1, 0.2, 0.3 etc. standard deviations. It also doesn't look like 1, 2, or 3 standard deviations.

What I'm trying to do is to add noise to an image at specific standard deviations. However, the results I get are honestly pretty weird. My code (in Python) is shown below:

poisson = float((raw_input("Noise standard deviation: ")))
.
.
.
name = t+'PHOTO'+s+str(i)+'.fits'

    im = pf.open(name)
    isinstance(im,list)
    im0 = im[0]
    poissonNoise = np.random.normal(0,poisson/1000, im0.data.shape).astype(float)
    test = im0.data + poissonNoise
    im0.data = test
    stringee = 'NOISE'
    pf.writeto(stringee+str(poisson)+name, data=test, clobber=True, header=im0.header)
print poisson

If you notice, I divide "poisson" by 1000 in order to get meaningful results. So what is the real value of the standard deviation, and how do I use it? All I want to do is to be able to input 1, 2, 3, etc. standard deviations and create that much noise.

2
  • 2
    In the example you linked, 0.1 was specified as the standard deviation of the desired distribution, so the values 0.1, 0.2, 0.3 on the X axis correspond to 1, 2, and 3 standard deviations. (Also, poissonNoise seems like a confusing variable name, when you're using a Gaussian distribution.) Commented Nov 3, 2013 at 8:15
  • What exactly does "im0.data.shape" do here? Commented Nov 3, 2013 at 8:19

1 Answer 1

2

It seems you're mixing things together. On the figure of discussion in the question

enter image description here

X axis is just X values not Standard Deviations. Remember that, for one distribution (here, Normal) there is only one single value standard deviation which can be computed easily, numpy.std.

BTW, your code is not quiet Python code. What is this: isinstance(im,list) for? Also remember that, indentation is heart of Python.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.