From: Joanne McCullen on
Hi,

I have the following situation:
- read an image (0..255 range); cast it to double precision;
- compute its gradient (dIdx and dIdy, which obviously will contain both positive and negative entries)
- try to add noise to the derivatives using imnoise function;
The result of imnoise is scaled from 0 to 1.

My question is how can I cast it back to its original range, which should contain both negative, and positive entries, without losing any information?

Should imnoise only be used on images with positive intensity values?
In this case, how do I scale the derivatives (shift, maybe?) to be able to apply imnoise?

Thank you so much!
From: ImageAnalyst on
Since you now have an array in the range 0-1, simply multiply by 255.
No information is lost due to scaling (ignoring very small truncation
errors). The result will now be in the range 0-255 just like you
started with. However, your original noise-free signal may no longer
be in its original range if you had noise added that gave numbers
outside the 0-255 range. For example, if your signal went from 98-158
(range of 60) and you added noise so that the noisy image went from
-255 to +512 (basically three times your original range) then your
signal after rescaling will now be 1/3 as much range, or will go from
(roughly) 118 - 138 (a range of 20).

You'd better scale your image to floating point between 0 and 1 to use
some of the noise types in imnoise or you won't get what you expect.
So scale before you call imnoise, not after like you said.
Derivatives would scale the same way the image did. Try it and see.
If you had to multiply your image by 1/255, then your derivatives of
your after-scaling image will now also be 1/255 of the derivatives of
the before-scaling image.
From: Joanne McCullen on
Thank you for your detailed reply - I'm trying it right now and hopefully it will work.
I'll let you know.

Have a great day!



ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <013c0feb-df4e-476e-8c8e-2ccce46d09ae(a)d27g2000yqf.googlegroups.com>...
> Since you now have an array in the range 0-1, simply multiply by 255.
> No information is lost due to scaling (ignoring very small truncation
> errors). The result will now be in the range 0-255 just like you
> started with. However, your original noise-free signal may no longer
> be in its original range if you had noise added that gave numbers
> outside the 0-255 range. For example, if your signal went from 98-158
> (range of 60) and you added noise so that the noisy image went from
> -255 to +512 (basically three times your original range) then your
> signal after rescaling will now be 1/3 as much range, or will go from
> (roughly) 118 - 138 (a range of 20).
>
> You'd better scale your image to floating point between 0 and 1 to use
> some of the noise types in imnoise or you won't get what you expect.
> So scale before you call imnoise, not after like you said.
> Derivatives would scale the same way the image did. Try it and see.
> If you had to multiply your image by 1/255, then your derivatives of
> your after-scaling image will now also be 1/255 of the derivatives of
> the before-scaling image.
From: Joanne McCullen on
One question, though: when I scale back, after adding the noise, is it correct to multiply all entries by the initial scaling constant?

I mean this way the noise is scaled to a higher range as well, but I guess its entries are added (by imnoise) within the 0..1 range, so everything should be preserved, right?

ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <013c0feb-df4e-476e-8c8e-2ccce46d09ae(a)d27g2000yqf.googlegroups.com>...
> Since you now have an array in the range 0-1, simply multiply by 255.
> No information is lost due to scaling (ignoring very small truncation
> errors). The result will now be in the range 0-255 just like you
> started with. However, your original noise-free signal may no longer
> be in its original range if you had noise added that gave numbers
> outside the 0-255 range. For example, if your signal went from 98-158
> (range of 60) and you added noise so that the noisy image went from
> -255 to +512 (basically three times your original range) then your
> signal after rescaling will now be 1/3 as much range, or will go from
> (roughly) 118 - 138 (a range of 20).
>
> You'd better scale your image to floating point between 0 and 1 to use
> some of the noise types in imnoise or you won't get what you expect.
> So scale before you call imnoise, not after like you said.
> Derivatives would scale the same way the image did. Try it and see.
> If you had to multiply your image by 1/255, then your derivatives of
> your after-scaling image will now also be 1/255 of the derivatives of
> the before-scaling image.
From: ImageAnalyst on
If you "undo" the scaling by multiplying by 1/(original scale
factor), it's possible that some of the noise may be outside the range
allowed by that integer type. If that happens, those pixels will be
clipped to the min and max values allowed for that integer type. For
example any pixel values less than 0 or more than 255 (after
rescaling) will get set to 0 or 255 respectively. However your
original, noise-free signal will occupy the same range as it did
before, it's just that some noise outlier pixels may get clipped.