Thread Subject: imnoise on derivatives of an image

Subject: imnoise on derivatives of an image

From: Joanne McCullen

Date: 13 Mar, 2010 08:43:11

Message: 1 of 8

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!

Subject: imnoise on derivatives of an image

From: ImageAnalyst

Date: 13 Mar, 2010 14:50:13

Message: 2 of 8

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.

Subject: imnoise on derivatives of an image

From: Joanne McCullen

Date: 13 Mar, 2010 17:41:05

Message: 3 of 8

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@mailinator.com> wrote in message <013c0feb-df4e-476e-8c8e-2ccce46d09ae@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.

Subject: imnoise on derivatives of an image

From: Joanne McCullen

Date: 13 Mar, 2010 17:54:05

Message: 4 of 8

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@mailinator.com> wrote in message <013c0feb-df4e-476e-8c8e-2ccce46d09ae@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.

Subject: imnoise on derivatives of an image

From: ImageAnalyst

Date: 13 Mar, 2010 18:07:46

Message: 5 of 8

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.

Subject: imnoise on derivatives of an image

From: Joanne McCullen

Date: 13 Mar, 2010 18:22:06

Message: 6 of 8

Thank you for making it clear.
As you probably realized, I'm comparing some denoising algorithms, so I wouldn't want to accidentally denoise the image by doing some scaling (and/or clipping) operations on it!

However, if I do the same scaling operations on all noisy images I should be able to evaluate the algorithms' performance objectively all the same, I think...

Subject: imnoise on derivatives of an image

From: ImageAnalyst

Date: 13 Mar, 2010 19:23:36

Message: 7 of 8

Joanne McCullen:
Well then just cast all your images to double, divide by 255 (because
MATLAB usually wants floating point images to be in the range of 0-1,
and then do all your noise adding, denoising, and comparing on the
floating point images. You can leave it in the range of 0-1 if you
want, or multiply by 255 to get it back to the original range. But do
all your comparisons on the floating point images. Don't cast it back
to integer unless you need to save to a disk file. MATLAB can display
floating point images just fine, just be sure to use the [] option in
imshow to autoscaled each image independently to 0-255 so you can see
it.

imshow(doubleArray, []); % Display a double image in the range of
0-1.

Subject: imnoise on derivatives of an image

From: Joanne McCullen

Date: 13 Mar, 2010 21:53:06

Message: 8 of 8

Ok then, I will compare all algorithms on 0..1 range.
I didn't know images within this range could be displayed by Matlab, so thank you for pointing that out for me.
In fact, thank you for all your help, already I'm seeing some results.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
imnoise Joanne McCullen 14 Mar, 2010 18:44:00
imshow Joanne McCullen 14 Mar, 2010 18:44:00
rssFeed for this Thread

Contact us at files@mathworks.com