Confusion over the compression ratio of an Image.

3 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2015-11-24
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?
Siyomnqoba
Siyomnqoba 2015-11-24
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
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 个评论
Siyomnqoba
Siyomnqoba 2015-11-24
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?
Image Analyst
Image Analyst 2015-11-24
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.

请先登录,再进行评论。

类别

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