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
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?
回答(1 个)
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 个评论
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 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!