Effacer les filtres
Effacer les filtres

Why imnoise function gives pictures with larger size than original image?

2 vues (au cours des 30 derniers jours)
Seyed Mousavikia
Seyed Mousavikia le 4 Oct 2021
Commenté : Walter Roberson le 11 Oct 2021
I have a dataset and after addding noise to images I write them using imwrite function to store them in my data set, but after looking at the generated pictures I see that their size are 2 or 3 times larger than original image, I thought they should be nearly same size(for example my original image is 322KB but my same image + gaussian noise is 780KB ... Can somone explain why?
Here is my code:
%%Speckle
var_speckle=0.05;
%%Salt & Pepper
d=0.05;
%%Gaussian
m=0;
var_gauss=0.01;
%%%%%%%%%%%%%%%
x=0;
imagefiles = dir('*.png');
nfiles = length(imagefiles); % Number of files found
for ii=1:nfiles
currentfilename = imagefiles(ii).name;
currentimage = imread(currentfilename);
%%currentimage = rgb2gray(currentimage);
%%adjusted = imadjust(currentimage);
gaussian = imnoise(currentimage,'gaussian',m,var_gauss);
poisson = imnoise(currentimage,'poisson');
salt = imnoise(currentimage,'salt & pepper',d);
speckle = imnoise(currentimage,'speckle',var_speckle);
imwrite(gaussian,'C:\Users\dell\Desktop\Shabake_Asli\Dataset\ExtendedDataset\Mirror\SleepNoiseAddMirror\'+string(x)+'gaussian.png','WriteMode','append')
imwrite(poisson,'C:\Users\dell\Desktop\Shabake_Asli\Dataset\ExtendedDataset\Mirror\SleepNoiseAddMirror\'+string(x)+'poisson.png','WriteMode','append')
imwrite(salt,'C:\Users\dell\Desktop\Shabake_Asli\Dataset\ExtendedDataset\Mirror\SleepNoiseAddMirror\'+string(x)+'salt.png','WriteMode','append')
imwrite(speckle,'C:\Users\dell\Desktop\Shabake_Asli\Dataset\ExtendedDataset\Mirror\SleepNoiseAddMirror\'+string(x)+'speckle.png','WriteMode','append')
x=x+1;
end
  4 commentaires
Geoff Hayes
Geoff Hayes le 4 Oct 2021
@Seyed Mousavikia try comparing (usng the debugger) the currentImage and the gaussian image. Do both have the same dimension? Do both have the same data type? If so, then both images should be the same size when saved to file.
Seyed Mousavikia
Seyed Mousavikia le 4 Oct 2021
Ok I will try Geoff.. yes they have both same size and same data type

Connectez-vous pour commenter.

Réponses (3)

yanqi liu
yanqi liu le 9 Oct 2021
imwrite(mat2gray(gaussian),'C:\Users\dell\Desktop\Shabake_Asli\Dataset\ExtendedDataset\Mirror\SleepNoiseAddMirror\'+string(x)+'gaussian.png','WriteMode','append')
imwrite(mat2gray(poisson),'C:\Users\dell\Desktop\Shabake_Asli\Dataset\ExtendedDataset\Mirror\SleepNoiseAddMirror\'+string(x)+'poisson.png','WriteMode','append')
imwrite(mat2gray(salt),'C:\Users\dell\Desktop\Shabake_Asli\Dataset\ExtendedDataset\Mirror\SleepNoiseAddMirror\'+string(x)+'salt.png','WriteMode','append')
imwrite(mat2gray(speckle),'C:\Users\dell\Desktop\Shabake_Asli\Dataset\ExtendedDataset\Mirror\SleepNoiseAddMirror\'+string(x)+'speckle.png','WriteMode','append')

Walter Roberson
Walter Roberson le 9 Oct 2021
Modifié(e) : Walter Roberson le 11 Oct 2021
png file size depends on the choice of filter algorithms. imwrite does not offer any choice and is not necessarily offering the best filters.

Seyed Mousavikia
Seyed Mousavikia le 11 Oct 2021
Modifié(e) : Seyed Mousavikia le 11 Oct 2021
So you mean if I change the format of my images (e.g jpeg format) the imwrite result will be same size as original images?
  1 commentaire
Walter Roberson
Walter Roberson le 11 Oct 2021
No. .jpeg uses a different compression method that loses information. Comparing the file size it can create with the file size of PNG (which does not lose information) is not fair.
You might not be able to use imwrite() to get back the original file size.
I would suggest to you that immediately after you imread() the original file, that you imwrite() it out to a new name as a PNG file. And then later you would compare the size of the written image-with-noise PNG to the size of the PNG you saved. It might not be the same size as the original PNG file, but the two would have been saved with the same compression algorithm so it would be fair to compare them.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by