Poisson Noise Added in Image denoising using Pytorch

MayThet: <p>I am researching image-denoising. At first, I used a random Gaussian noise(AWGN) interval within the specified range using the following code. However, I am now extending to add the Poisson noise and mixed noise within the range interval. The question is np. random.poisson () accepts one interval and the size according to this np.random.poisson(lam=1.0, size=None). How can I solve this problem?</p>
<blockquote>
<blockquote>
<p>stdn = np.random.uniform(args.noiseIntL[0], args.noiseIntL[1],<br>
size=noise.size()[0])<br>
for nx in range(noise.size()[0]):<br>
sizen = noise[0, :, :, :].size()<br>
noise[nx, :, :, :] = torch.FloatTensor(sizen).normal_(mean=0, std=stdn[nx])<br>
imgn_train = img_train + noise</p>
</blockquote>
</blockquote>

bloos: <p>I don’t quite understand the problem. You can generate any shape with random.poisson like this:</p>
<pre><code class="lang-auto">np.random.poisson(lam=5.0, size=(10,5))
</code></pre>

MayThet: <p>Thank you for your suggestion and comment. My question is, while AWGN noise can be easily added using PyTorch tensors, adding Poisson noise can only be accomplished using NumPy. Do you have any suggestions for adding Poisson noise using PyTorch tensors?</p>

bloos: <p>either this way:</p>
<pre><code class="lang-auto">poisson_numpy = np.random.poisson(lam=5.0, size=(10,5))
poisson_torch = torch.from_numpy(poisson_numpy)
</code></pre>
<p>or this way ( i don’t know whether this is mathematically equivalent, but it seems to be)</p>
<pre><code class="lang-auto">torch.poisson(torch.ones(10,5)*5)
</code></pre>

bloos: <p>btw: you can generate gaussian distributed tensors of arbitrary shape using:</p>
<pre><code class="lang-auto">torch.randn(your_shape)
</code></pre>
<p>if you want to have different standard deviations along your batch dimension you can do something like this:</p>
<pre><code class="lang-auto">stdn.view(N,1,1)*torch.randn(N,y,z)
</code></pre>

MayThet: <p>Thank you for your comment. I have implemented Poisson noise according to the following code. I am uncertain whether the use of <code>torch.ones</code> for noise addition is appropriate or not. Additionally, some research papers suggest that Poisson noise is signal-dependent, and the addition of the noise to the original image may not be accurate. Please give me suggestions and comments for this point.</p>
<blockquote>
<p>noise = torch.zeros(img_train.size())<br>
stdn = np.random.uniform(args.noiseIntL[0], args.noiseIntL[1], size=noise.size()[0])<br>
for nx in range(noise.size()[0]):<br>
sizen = noise[0, :, :, :].size()<br>
noise[nx, :, :, :] = torch.poisson(<br>
torch.ones(sizen) * stdn[nx])  # Pass a tensor of the same shape as noise<br>
imgn_train = img_train + noise</p>
</blockquote>

bloos: <p>as far as I understand the documentation the argument of torch.poisson corresponds to the lamda parameter of np.random.poisson. You just have the option do define different lambdas for different dimensions. This is why</p>
<pre><code class="lang-auto">torch.poisson(torch.ones(your_shape))
</code></pre>
<p>makes actually sense. In this case all dimensions have the same lambda parameter.<br>
Additionally you multiply a standard deviation to your lambda. I don’t see any reason why you should do that. Gaussian Noise is parameterized by standard deviation, but poisson noise is not. Its solely defined by the lambda (even though you can calculate a standard deviation for the poisson distribution).</p>
<p>I have found different Information in the internet on whether poisson noise is additive or not. Some say it is, others say it isn’t (<a href="https://perso.esiee.fr/~talboth/articles/Mine/Efficient_Poisson_Denoising_ICIP_2009_0003881.pdf" rel="noopener nofollow ugc">https://perso.esiee.fr/~talboth/articles/Mine/Efficient_Poisson_Denoising_ICIP_2009_0003881.pdf</a>).</p>
<p>You should be aware that adding poisson distributed random values can only make your image brighter and never darker, because they are strictly positive</p>

MayThet: <p>I originally used <code>std = np.random.uniform()</code> to create different noise ranges, like 0 to 70, during neural network training. Later, I changed the code to use <code>lambdas = torch.randint(76, size=(noise.size()[0],))</code> .</p>