フィルターのクリア

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

2 ビュー (過去 30 日間)
Seyed Mousavikia
Seyed Mousavikia 2021 年 10 月 4 日
コメント済み: Walter Roberson 2021 年 10 月 11 日
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 件のコメント
Geoff Hayes
Geoff Hayes 2021 年 10 月 4 日
@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 2021 年 10 月 4 日
Ok I will try Geoff.. yes they have both same size and same data type

サインインしてコメントする。

回答 (3 件)

yanqi liu
yanqi liu 2021 年 10 月 9 日
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 2021 年 10 月 9 日
編集済み: Walter Roberson 2021 年 10 月 11 日
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 2021 年 10 月 11 日
編集済み: Seyed Mousavikia 2021 年 10 月 11 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 10 月 11 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by