Which of the following method is correct for finding the image compression ratio in matlab

조회 수: 2 (최근 30일)
I am using Huffman coding for image compression.Here I have mentioned three methods for finding the compression ratio.
clear all
clc
%Read the input image
Ao=imread('Lena.bmp');
Ao = imresize(Ao,[256 256]);
in = imfinfo('Lena.bmp')
% figure,
subplot(221)
imshow(Ao);
title('input image')
A=double(Ao);
%
% A=[10 2 3 4;5 6 7 8];
% display(A);
e=A;
tic
%Perform prediction error
for i = 1:size(A,1)
for j = 2:size(A,2)
e(i,j)=e(i,j)-A(i,j-1);
end
end
display(e);
%Huffman coding
C=reshape(e,[],1);
[D1,x]=hist(C,min(min(e)):max(max(e)));
sym=x(D1>0);
prob=D1(D1>0)/numel(e);
[dict,avglen] = huffmandict(sym,prob);
compressed = huffmanenco(C,dict);
imwrite(uint8(compressed),'comp.bmp')
cmprsd = imfinfo('comp.bmp');
%Three methods for finding the compression ratio
Compression_Ratio_1 = in.FileSize/length(compressed)
Compression_Ratio_2 = (in.Width*in.Height*in.BitDepth/8)/cmprsd.FileSize
Compression_Ratio_3 = (in.Width*in.Height*in.BitDepth/8)/length(compressed)
Kindly help me to identify which among the 3 is correct for finding the compression ratio.

답변 (1개)

ahcen aliouat
ahcen aliouat 2022년 1월 28일
편집: ahcen aliouat 2022년 1월 28일
Hello,
I think the third is the correct. W*H*BitDepth will give you the number of bits needed for the uncompressed image, divided by the number of bits of the compressd image (compressed) gives you the exact compression Ratio.

카테고리

Help CenterFile Exchange에서 Denoising and Compression에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by