function r = compressSPIHT(A, nameA, bitrates)
% compressSPIHT   compress an image (matrix) using SPIHT from
%                 http://www.cipr.rpi.edu/research/SPIHT/spiht3.html
% with files stored in a catalog available from the Matlab search path.
% 
% use:
% r = compressSPIHT(A, nameA, bitrates)

if ~(exist('mSpiht_n','file') == 2)
    % add path where files from 
    %    http://www.cipr.rpi.edu/research/SPIHT/spiht3.html
    % are stored
    addpath('f:\matlab\SPIHT');  
end
if (exist('mSpiht_n','file') == 2)
    disp('Use mSpiht_n for SPIHT from http://www.cipr.rpi.edu/research/SPIHT/spiht3.html.')
else
    r = struct('message','compressSPIHT: can not find mSpiht_n.');
    return;
end

br = zeros(size(bitrates));
PSNR = zeros(size(bitrates));

for i=1:numel(bitrates)
    rate = bitrates(i);
    [PSNR(i),br(i)] = mSpiht_n(A, size(A), rate, 'n0');
end
r = struct('bitrate',br,'bits',br*(numel(A)),'PSNR',PSNR,...
    'met','SPIHT','text','SPIHT',...
    'image',nameA,'size',size(A));

return

