which imshow is true?

2 visualizzazioni (ultimi 30 giorni)
majid
majid il 21 Dic 2021
Modificato: DGM il 21 Dic 2021
Hello. I have an image that i add some noise to it. finally i want to show it with imshow.i use two syntax but i dont know which one is right? here is my code:
% 2nd way b
clear all;
close all;
clc;
I=im2double(imread ('cameraman.tif'));
size_I=size(I);
%%adding noises
%adding quantization noise
thresh = multithresh(I,7);
valuesMax = [thresh max(I(:))];
[quant8_I_max,~] = imquantize(I,thresh,valuesMax);
%speckle noise
SI=imnoise(I,'speckle',0.2);
% adding salt and pepper noise or shot noise
Shot_noise = imnoise(I, "salt & pepper", 0.20);
%adding background noise
mean=0.5953;
BG = poissrnd(mean, size_I);
BGR=I+BG;
BGR=BGR./max(BGR);
% total noise
noisy_image=I+quant8_I_max+SI+Shot_noise+BGR;
figure
imshow(I);
title('Original Image')
figure
subplot(121)
imshow(noisy_image,[])
title("noisy image show with []");
subplot(122)
imshow(noisy_image)
title("noisy image show without []");
  1 Commento
Stephen23
Stephen23 il 21 Dic 2021
Do you want to scale the image to its maximum and minimum values, or not? Only you know what your intent is.

Accedi per commentare.

Risposta accettata

DGM
DGM il 21 Dic 2021
Modificato: DGM il 21 Dic 2021
Tools like imshow() and imwrite() expect image data to be scaled according to class-dependent limits. For floating-point image data, black is 0, white is 1. For integer images, black and white correspond to the minimum and maximum values that the integer class can represent.
You're taking five floating point images and adding them together. The result spans (approximately) [0 5]. What will imshow() do with this if it thinks 1 is white? The answer is that most of the data is treated as white.
Will normalizing the data to the extrema give a viewable image? Yes. Is that the appropriate result? Maybe.
If it were me, I'd just divide the image sum by 5. That way the relative range of the image doesn't get stretched.
Consider the example using a source image that has less range:
I=im2double(imread ('pout.tif'));
size_I=size(I);
%%adding noises
%adding quantization noise
thresh = multithresh(I,7);
valuesMax = [thresh max(I(:))];
[quant8_I_max,~] = imquantize(I,thresh,valuesMax);
%speckle noise
SI=imnoise(I,'speckle',0.2);
% adding salt and pepper noise or shot noise
Shot_noise = imnoise(I, "salt & pepper", 0.20);
%adding background noise
mean=0.5953;
BG = poissrnd(mean, size_I);
BGR=I+BG;
BGR=BGR./max(BGR);
% total noise
noisyimg_sum = I+quant8_I_max+SI+Shot_noise+BGR;
noisyimg_avg = noisyimg_sum/5;
subplot(121)
imshow(noisyimg_sum,[])
title("noisy image sum with []");
subplot(122)
imshow(noisyimg_avg)
title("noisy image average");
Using the displayrange parameter with imshow distorts the image range and shows it having more contrast than it actually has.
The question should be whether the average of these images with noise applied is meaningful. I would imagine that what's intended is not the sum or average, but the composition of noise functions. In other words, each call to imnoise() should operate on the result from the prior call to imnoise(). That way the noise contribution doesn't get multiplied by 1/5. In that case, the final result will be within the proper range for the class and this whole rescaling question will be moot.

Più risposte (0)

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by