How to calculate image compression ratio?
66 次查看(过去 30 天)
显示 更早的评论
After doing some processing on the image, say DCT and Quantization, how can I calculate the compression ratio between the compressed image and the original one ?
Thanks in advance
0 个评论
采纳的回答
Walter Roberson
2015-8-29
Let A be the storage size needed to represent the original image. For example use whos() to fetch it.
Let B be total storage size of all the arrays together that are needed to hold the compression information that would be needed to recover the image. For dct type arrangements be sure to include the storage needed to indicate which coefficients have been zeroed.
Now A/B is your compression ratio. If you get a result less than 1.0 then that means that your compression representation takes more space than the original, which does happen for some data and some compression algorithms.
5 个评论
Dibyalekha Nayak
2023-1-11
How to calculate the compression ratio for the dwt compressed images.Please help in this problem.
Walter Roberson
2023-1-12
The ratio is what I outlined in my Answer.
The one thing I would change is to mention that when you are calculating the array sizes, be sure to include any storage you need to indicate the array sizes (explicit size) or any end-of-row/column markers (implicit size).
Mentally plan out: if you were to write the data to a file in a form that allowed you to exactly reconstruct the data in the same size and shape, then how large would the file be ? For example if you have uint8 data then for A, storage size needed to represent the image, include (say) 16 bits for a uint16 for the number of rows, another 16 bits for uint16 for number of columns, and then write out a stream of uint8 data. The total length of the data divided by (rows times columns) tells you how many color planes existed, so you can reconstruct whether you had grayscale or RGB without needing to explicitly write the number of color planes.
For B, the total storage size of all of the arrays together that need to hold the information needed to reconstruct the image, storing the sizes becomes even more important. (In some schemes you can imply sizes -- the size of each layer of detail coefficients is half the rows and columns of the previous level.)
更多回答(1 个)
Sazzad Hosen
2023-7-17
original_image = imread('babu.jpg');
compression_quality = 80;
imwrite(original_image, 'compressed_image.jpg', 'Quality', compression_quality);
original_info = dir('babu.jpg');
original_size = original_info.bytes;
compressed_info = dir('compressed_image.jpg');
compressed_size = compressed_info.bytes;
compression_ratio = original_size / compressed_size;
disp(['Compression Ratio: ', num2str(compression_ratio)]);
Compression Ratio: 4.2251
1 个评论
Walter Roberson
2023-7-17
No, this is not a correct calculation. jpg files can include header information such as size information and comments and resolution information. Your source file might include several kilobytes of header information. You are not copying that header information to the output file, so potentially the portion of the output file that is used to hold the header information might get larger but because of the omitted header information the output file might be smaller. You are not comparing the size of the image portion only.
Furthermore the original jpg file is already compressing the image. The real task for calculation of compression ratio is to compare the size of the image portion of the uncompressed image to the size of the image portion of the compressed image.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Denoising and Compression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!