Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Imnoise problem with double type image

Subject: Imnoise problem with double type image

From: JForma Forma

Date: 15 Jan, 2009 08:13:03

Message: 1 of 3

Hi,

I have an image with all the pixel values being double type. I'm trying to generate Poisson noise with imnoise with following commands.

1. max_value = max(max(I)); -- take the maximum value
2. I = I/max_value; -- normalize, now pixel values range from [0,1] (I know that there?s no negative values in my image.

3. I2 = max_value * imnoise( I , 'poisson'); -- generate noisy image and scale back to the original intensities.

Problem I?m having is that nothing happens! I have read imnoise help, and didn?t understand the scaling with double type images, so maybe there?s the reason for this.

When I change the code to following, the result image looks fine i.e there?s noise:

1. max_value = max(max(I)); I = I / max_value;
2. I2 = max_value * im2double( imnoise( im2uint16(I) , 'poisson' ));

So I?m wondering why the second one works but the first one doesn?t? I understood that key thing is to make sure that image values are normalized before calling imnoise. My second question is: is the latter way to generate noise just fine, or is there some serious bias because of roundoff errors or something?

Thanks
Jussi

Subject: Imnoise problem with double type image

From: Image Analyst

Date: 15 Jan, 2009 16:30:20

Message: 2 of 3

"JForma Forma" <jussi911@luukku.com> wrote in message <gkmr6f$4e1$1@fred.mathworks.com>...
> Hi,
>
> I have an image with all the pixel values being double type. I'm trying to generate Poisson noise with imnoise with following commands.
>
> 1. max_value = max(max(I)); -- take the maximum value
> 2. I = I/max_value; -- normalize, now pixel values range from [0,1] (I know that there?s no negative values in my image.
>
> 3. I2 = max_value * imnoise( I , 'poisson'); -- generate noisy image and scale back to the original intensities.
>
> Problem I?m having is that nothing happens! I have read imnoise help, and didn?t understand the scaling with double type images, so maybe there?s the reason for this.
>
> When I change the code to following, the result image looks fine i.e there?s noise:
>
> 1. max_value = max(max(I)); I = I / max_value;
> 2. I2 = max_value * im2double( imnoise( im2uint16(I) , 'poisson' ));
>
> So I?m wondering why the second one works but the first one doesn?t? I understood that key thing is to make sure that image values are normalized before calling imnoise. My second question is: is the latter way to generate noise just fine, or is there some serious bias because of roundoff errors or something?
>
> Thanks
>
Jussi:
You didn't scale your data properly. Your second example works on integers and the Poisson option works differently for that. Read the manual again. Look at this sample code where I've properly scaled the input image:
% Clean up
clc;
clear all;
% Read in standard MATLAB demo image.
originalImage = imread('cameraman.tif');
% Convert to double.
originalImage = double(originalImage);
subplot(1,3,1);
imshow(originalImage, []);
max_value = max(max(originalImage)); % take the maximum value
normalizedImage = originalImage/ max_value; % normalize, now pixel values range from [0,1] (I know that there's no negative values in my image.
% The Poisson option of imnoise wants the values to be scaled by 1e-12,
% so let's have the values go from 0 to 10e-12:
normalizedImage = normalizedImage * 10e-12;
% Now we'd consider the image as a Poisson process with values of 0-10.
% Now plot.
subplot(1,3,2);
imshow(normalizedImage, []);
noisyImage = max_value * imnoise(normalizedImage, 'poisson'); % generate noisy image and scale back to the original intensities.
subplot(1,3,3);
imshow(noisyImage, []);

Subject: Imnoise problem with double type image

From: Rachel

Date: 12 Jun, 2012 05:39:09

Message: 3 of 3

Sounds like 'law of large numbers' at work. With double precision, MATLAB scales it up by 1e12 and creates a poisson noise based on the new values, which means your mean is scaled up by 1e12. MATLAB then scales the value down by 1e12. It's equal to averaging a bunch of random variables with the same poisson distribution.

Imaging the situation: your expected number of calls per minute at a call center is 5 calls. Now your questions is: what's the probability of getting 7 calls in one minute? Instead of answering that question, MATLAB presents a new question: if your expected number of calls per 1e12 minutes is 5e12 calls, what's the probability of getting 7 calls in one minute? Then MATLAB calculates your probability of getting 7e12 calls in 1e12 minutes and extrapolates your probability of getting 7 calls in one minute by averaging (law of large numbers kicks in here).

Now why that gives you the expected value, which makes your image seemingly noise free? A perfect analogy is when you average a few noisy images to get a relatively smooth image. Back to the call center example, if your poisson mean is 5, your chance of getting 7 calls in one minute is 5^7*exp(-5)/7! = 0.1044. On the other hand, if you do it the MATLAB way, your chance of getting 7e12 calls in 1e12 minutes is 5e12^7e12*exp(-5e12)/7e12! = some extremely small number. That means, you'll almost get nothing else but 5e12 calls in this 1e12 minute duration. Then you average it back to per minute figure, you'll almost certainly get 5 calls.


"JForma Forma" <jussi911@luukku.com> wrote in message <gkmr6f$4e1$1@fred.mathworks.com>...
> Hi,
>
> I have an image with all the pixel values being double type. I'm trying to generate Poisson noise with imnoise with following commands.
>
> 1. max_value = max(max(I)); -- take the maximum value
> 2. I = I/max_value; -- normalize, now pixel values range from [0,1] (I know that there?s no negative values in my image.
>
> 3. I2 = max_value * imnoise( I , 'poisson'); -- generate noisy image and scale back to the original intensities.
>
> Problem I?m having is that nothing happens! I have read imnoise help, and didn?t understand the scaling with double type images, so maybe there?s the reason for this.
>
> When I change the code to following, the result image looks fine i.e there?s noise:
>
> 1. max_value = max(max(I)); I = I / max_value;
> 2. I2 = max_value * im2double( imnoise( im2uint16(I) , 'poisson' ));
>
> So I?m wondering why the second one works but the first one doesn?t? I understood that key thing is to make sure that image values are normalized before calling imnoise. My second question is: is the latter way to generate noise just fine, or is there some serious bias because of roundoff errors or something?
>
> Thanks
> Jussi

Tags for this Thread

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.

Contact us