Confusion over the compression ratio of an Image.

So here's the deal, I have 2 separate codes for an image, one takes in 2 images (compressed and uncompressed) and then determines the compression ratio. my qualms with it is that the compression ratio is always 8, no matter the quality factor I've used. Its still 8 even thou the image sizes do not reflect that.
The other code, takes a compressed image, uses parameters from imfinfo function to determine the compression and I get something around 45. Which is supposedly not an unreasonable value for JPEG compression.
I'm confused here, which method is more representative if the JPEG compression scheme I am trying to do?
Can an image carry compression information as is the case for the second method?
first method:
function cr = imratio(f1,f2)
error(nargchk(2,2,nargin));
cr = bytes(f1)/bytes(f2);
function b = bytes(f)
if ischar(f)
info = dir(f);
b = info.bytes;
elseif isstruct(f)
b = 0;
fields = fieldnames(f);
for k = 1:length(fields)
b = b+bytes(f.(fields{k}));
end
else
info = whos('f');
b = info.bytes;
end
end
% set(handles.imratiotextbox,'String',cr);
end
second method:
k = imfinfo('3c.jpg');
ib=k.Width*k.Height*k.BitDepth/8;
cb=k.FileSize;
cr=ib/cb

댓글 수: 6

Please show the code for your first method.
I've updated the question,thanks
For the first method, what are the two parameters you are passing to imratio() ?
Original Image and the compressed image
Do you mean strings that are file names? If so then how are those images represented on disk?
Do you mean arrays that resulted from imread()? If so then what is class() for each of them?
original image is in .tiff format,compressed image is in jpeg format.after compression the resulting image is written into disk as uint8 format

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 11월 24일

0 개 추천

For method 1, one of your arrays is uint8() and the other is double(). The one with double() takes 8 times as much memory to store.

댓글 수: 2

Ok that makes sense,since I've ensured that both are the same format the compression ratio is 1.which is still pretty baffling considering that the size of the compressed image is about a tenth of its original size.
Why is this the case?and what about the 2nd method?
Give an exact call for cr = imratio(f1,f2). We're still not clear if you're passing in filename strings, or some kind of structure - your "bytes" function is written to handle both.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Denoising and Compression에 대해 자세히 알아보기

질문:

2015년 11월 24일

댓글:

2015년 11월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by