Date: Mar 28, 2013 10:44 PM
Author: anyone
Subject: Re: randn repeating itself

On Thu, 28 Mar 2013 05:17:11 +0000, Nicholas  wrote:

> I'm adding noise (Rician) with randn to a synthetic image for post
> processing. However, for validation reasons, I want to process the image
> with numerous different instances of the noise model applied to the
> image. So, what I did was create a for loop such that at each iteration
> a new/different instance of the noise was added to original image. The
> problem is that the noise is the exact same with each iteration. BUT
> the perplexing thing is that if I use a breakpoint inside the loop and
> 'continue' through it, the noise changes with each iteration (unlike if
> I were to just let it run). At any rate, the code looks something like
> this:
>
> im = imread('lena.tif');
> for i = 1:20
> % add 10% noise
> x = 0.1*randn(size(im)) + im;
> y = 0.1*randn(size(im));
> noisy = sqrt(x.^2 + y.^2);
> % image processing %
> end
>
> So, in this example, noisy is returned as the exact same image 20 times.


I doubt that... 'imread' returns uint8 class, while 'randn' returns 'double', and Matlab won't directly add the two. On top
of that, and assuming you swat the small bug, you don't save anything on each pass so only the last version of
'noisy' gets dumped to the workspace and that one has only one version of "noise".

> This seems like a seeding problem to me,

No, it isn't.
[...]