How to produce Cauchy noise when the image intensity range is [0,255]?

Viewed 94

I have written the following code to produce Cauchy noise for an image when the image intensity range is [0,1]:

refimg = im2double(((imread('parrot.png')))); % original image
img_height = size(refimg,1);
img_width = size(refimg,2);

r1 = random('Normal',0, 1,[img_height img_width]);
r2 = random('Normal',0, 1,[img_height img_width]);

n = 0.04; % the noise level
u0 = refimg + n.*(r1./r2);

figure(1); imshow(u0);

And this is the result that I obtained:

enter image description here

Now I want to change the intensity range of my reference image to [0,255] and produce the noisy image corrupted by the Cauchy noise. For this purpose, I changed the first line to

refimg = im2double(((imread('parrot.png')))).*255; % original image

and the last line to:

figure(1); imshow(u0,[]);

But this is the output:

enter image description here

I appreciate it if someone could please help me to find the problem with my code when the image intensity range is [0,255].

1 Answers

To create the output the noise can be scaled by 255 and casted as a uint8 after being added to the reference image refimg to match the reference image, refimg. This results in an image that seems to replicate the image you had when it was handled as a double ranging from 0 to 1.

Adding Noise to Image

refimg = 255.*im2double(imread('tire.tif'));
img_height = size(refimg,1);
img_width = size(refimg,2);

r1 = random('Normal',0, 1,[img_height img_width]);
r2 = random('Normal',0, 1,[img_height img_width]);

n = 0.04; %the noise level%

Noise = 255.*n.*(r1./r2);
%Casting the noise as uint8 type and multiplying by 255%
u0 = uint8(refimg + Noise);

figure(1); 
subplot(1,3,1); imshow(uint8(refimg));
subplot(1,3,2); imshow(uint8(Noise));
subplot(1,3,3); imshow(u0);
Related