How to calculate image compression ratio?
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
Sazzad Hosen
le 17 Juil 2023
0 votes
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 commentaire
Walter Roberson
le 17 Juil 2023
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.
Catégories
En savoir plus sur Denoising and Compression dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!