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');
filename = 'image jpg.jpg';
filename = 'image bmp.bmp';
filename = 'image tif.tif';
d = dir('image *.*')
for k = 1 : length(d)
fprintf('%s is %d bytes on disk.\n', d(k).name, d(k).bytes);
Name Size Bytes Class Attributes
rgbImage 384x512x3 589824 uint8
3×1 struct array with fields:
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.