Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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 Kommentare
Geoff Hayes
Geoff Hayes am 4 Okt. 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 am 4 Okt. 2021
Ok I will try Geoff.. yes they have both same size and same data type

Melden Sie sich an, um zu kommentieren.

Antworten (3)

yanqi liu
yanqi liu am 9 Okt. 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 am 9 Okt. 2021
Bearbeitet: Walter Roberson am 11 Okt. 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 am 11 Okt. 2021
Bearbeitet: Seyed Mousavikia am 11 Okt. 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 Kommentar
Walter Roberson
Walter Roberson am 11 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by