I'm not sure the matrix size in MATLAB will be useful, though it might be interesting. You could use it to figure out how big the headers are for the uncompressed formats like BMP and TIF. What you want to do it use dir() or imfinfo() to get the size on disk, which is usually what people mean when they talk about compression. So just use create different filenames with different extensions representing the format you want to write the image out in, and then imwrite() to write it to disk. Then use dir() to get back the number of bytes on disk. For example
rgbImage = imread('peppers.png');
whos rgbImage
filename = 'image jpg.jpg';
imwrite(rgbImage, filename);
filename = 'image bmp.bmp';
imwrite(rgbImage, filename);
filename = 'image tif.tif';
imwrite(rgbImage, filename);
d = dir('image *.*')
for k = 1 : length(d)
fprintf('%s is %d bytes on disk.\n', d(k).name, d(k).bytes);
end
You'll see:
Name Size Bytes Class Attributes
rgbImage 384x512x3 589824 uint8
d =
3×1 struct array with fields:
name
folder
date
bytes
isdir
datenum
image bmp.bmp is 589878 bytes on disk.
image jpg.jpg is 23509 bytes on disk.
image tif.tif is 593776 bytes on disk.
You can see the header size for BMP is 589878 - 589824 = 54 bytes. Of course that doesn't work for compressed formats like PNG and JPG. By the way, don't save images in a lossy format like JPG if you plan on using them for image analysis.
Best Answer