0

My question is simple: I have an image and I want to add pixel wise independent noise to the image. The noise can be derived from from any distribution such as Gaussian. What are the available modules in numpy/scikit-learn to do the same?

I do not have any code but I am learning about modules such as numpy.random.normal, etc. and I needed more clarification. None of the modules explicitly say that if I draw samples from a distribution multiple times, the draws will be independent.

Thank you for suggestions.

Silver moon
  • 229
  • 3
  • 15
  • One would assume the draws would be independent, but without seeing the code you're using it's hard to be sure. – Mark Ransom Mar 01 '19 at 22:43
  • @MarkRansom I don't have a code unfortunately, I am just learning about modules like numpy.random.normal, etc and wonder if they do the same – Silver moon Mar 01 '19 at 22:45
  • Your question should be more focused then, as is it's hard to follow. – Mark Ransom Mar 01 '19 at 22:46
  • @MarkRansom Also I would very much appreciate if you could point me to code snippets where the draws will be independent versus not independent since your comment seems to indicate that there are also modules for non-independent draws – Silver moon Mar 01 '19 at 22:47
  • I will indicate this in my question then. Thank you for the suggestion – Silver moon Mar 01 '19 at 22:48
  • I'm not familiar with the distribution functions so that's why I wanted to see some code, to know what you're really asking about. I can imagine some scenario where you have multiple objects and they each produce the same set of numbers. – Mark Ransom Mar 01 '19 at 22:52
  • Did you search? https://stackoverflow.com/questions/33327711/how-to-add-gaussian-noise-to-an-image https://stackoverflow.com/questions/19289470/adding-poisson-noise-to-an-image etc. – Cris Luengo Mar 01 '19 at 23:15

2 Answers2

1

You have several options. If you want to take random samples with replacement, just use one of the numpy's builtin random modules (i.e., numpy.random.random). You could also use numpy.random.pareto for more dramatic/bursty noise. These methods generate independent samples.

If you have a distribution in the form of a set or array that you want to pull samples from without repetition (for instance you have an array [0.1, 0.3, 0.9] and want to generate noise with ONLY these values), you use python's builtin random.random.choice([0.1, 0.3, 0.9]) to draw independent samples from your custom distribution. You can also specify replace=False.

Matt Hall
  • 331
  • 1
  • 4
  • 13
0

Yes, random means Independent. You can use numpy/scipy to generate noise and add it to the image. Perhaps it's good for you to study this tutorial enter image description here Here the code:

import numpy as np
import matplotlib.pylab as plt

#--- data -----
a = 1
xi, yi = np.linspace(-a,a,nx), np.linspace(-a,a,ny)
x, y = np.meshgrid(xi,yi)    # 2-dimensional grid
U = np.exp(-x*x - y*y)       # picture/signal
V = np.random.randn(nx, ny)  # random noise

#--- grafics -----
fig = plt.figure(figsize=(22,11)) 
ax1 = fig.add_subplot(131)
ax1.imshow(U)
ax2 = fig.add_subplot(132)
ax2.imshow(V)
ax3 = fig.add_subplot(133)
ax3.imshow(U+0.2*V)
plt.show()
fig.savefig('signal_noise.png', transparency=True)
pyano
  • 1,885
  • 10
  • 28