Confusion over the compression ratio of an Image.

1 visualizzazione (ultimi 30 giorni)
Siyomnqoba
Siyomnqoba il 24 Nov 2015
Commentato: Image Analyst il 24 Nov 2015
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 Commenti
Walter Roberson
Walter Roberson il 24 Nov 2015
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 il 24 Nov 2015
original image is in .tiff format,compressed image is in jpeg format.after compression the resulting image is written into disk as uint8 format

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 24 Nov 2015
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 Commenti
Siyomnqoba
Siyomnqoba il 24 Nov 2015
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 il 24 Nov 2015
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.

Accedi per commentare.

Categorie

Scopri di più su Denoising and Compression in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by