imratio.m

来自「霍夫曼coding程序」· M 代码 · 共 28 行

M
28
字号
function cr = imratio(f1 , f2)
%IMRATIO Computes the ratio of the bytes in two images/variables.
%   CR = IMRSTIO(F1 , F2) returns the ratio of the number of bytes in
%   variables/files F1 and F2. If F1 and F2 are an original and 
%   compressed image, respectively, CR is the compression ratio.

error(nargchk(2 , 2 , nargin));
cr = bytes(f1) / bytes(f2);

%--------------------------------------------------------------%
function b = bytes(f)
% Return the number of bytes in input f. If f is a string, assume
% that it is an image filename; if not, it is an image variable.
if ischar(f)
    info = dir(f);  b = info.bytes;
elseif isstruct(f)
    % MSTLaB's whos function reports an extra 124 bytes of memory
    % per structure field because of the way MATLAB stores
    % structures in memory. Don't count this extra memory; instead,
    % add up the memory associated with each field.
    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

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?