Code covered by the BSD License  

Highlights from
Toolbox Wavelets

image thumbnail
from Toolbox Wavelets by Gabriel Peyre
Wavelet transform and coding functions, including other more exotic transforms (laplacian, steerable

test_laplacian_arithmetic_coding.m
% test for laplacian arithemtic coding
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

n = 512;
Jmin = 4;
name = 'lena';
M = load_image(name,n);
MW = perform_wavelet_transform(M,Jmin,+1);


A = MW(1:end/2, end/2+1:end);
n = size(A,1);
% quantize to finite precision
T = 10;
[tmp,A] = perform_quantization(A,T,1);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% arithmetic cosing using generalized laplacian model
options.coder_type = 7;
fprintf('Performing coding ... ');
[stream,nbr_bits_lapl] = perform_arithmetic_coding(A(:),+1,options);
fprintf(' done.\n');
fprintf('Performing decoding ...');
A1 = perform_arithmetic_coding(stream,-1,options);
fprintf(' done.\n');
A1 = reshape(A1,n,n);
disp( ['Error (should be 0) ' num2str(norme(A-A1))] );


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% arithmetic cosing using adaptive coding
options.coder_type = 1;
fprintf('Performing coding ... ');
[stream,nbr_bits_adapt] = perform_arithmetic_coding(A(:),+1,options);
fprintf(' done.\n');
fprintf('Performing decoding ...');
A1 = perform_arithmetic_coding(stream,-1,options);
fprintf(' done.\n');
A1 = reshape(A1,n,n);
disp( ['Error (should be 0) ' num2str(norme(A-A1))] );


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% shannon bound
nbr_bits_shannon = compute_entropy(A(:))*length(A(:));

disp(['Adaptive:  ' num2str(round(nbr_bits_adapt)) 'bits.']);
disp(['Laplacian: ' num2str(round(nbr_bits_lapl)) 'bits.']);
disp(['Shannon:   ' num2str(round(nbr_bits_shannon)) 'bits.']);

Contact us at files@mathworks.com