For calculating compressed image file size before & after compression, do I have to save images?Or calculating matrix bytes is enough and correct?
조회 수: 41(최근 30일)
표시 이전 댓글
Hi friends! I want to calculate and compare image file size before and after the operation. As far as I know, image file size info can be get from imfinfo but I have image matrix only.
- Do I have to save the image to get file size?
- Does saving with different extensions make affect image file size (.jpg, .bmp, .png ...etc.) ?
- How can I learn image file size without saving? ( Can I achieve this matrix calculations row*size*dimension or etc.)
Thank you in advance!
댓글 수: 4
Image Analyst 2020년 6월 28일
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.
댓글 수: 1
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!