The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: randn repeating itself
Replies: 3   Last Post: Mar 29, 2013 5:36 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 7
Registered: 4/28/13
Re: randn repeating itself
Posted: Mar 28, 2013 10:44 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.