⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 examp_compression.m

📁 linear time-frequency toolbox
💻 M
字号:
%EXAMP_COMPRESSION  Image compression example%%   This examples shows how to do image compression using a%   two-dimensional Wilson transform.%%   The image is transformed using an orthonormal DWILT2 transform%   followed by N-term approximation and quantization. Then the image is%   reconstructed and compared with the original.%%   This example demonstrates both lossless and lossy compression. An image%   compression is lossless if the truncation error is below the quantization%   error, as the truncation error is not visible in that case.%%   FIGURE 1 The cameraman.%%     This figure to the left shows lossless compression of the%     cameraman. The figure to the right shows a lossy compression.%disp('Type "help examp_compression" to see a description of how this example works.');% -------- defining constants -------------% Image has dimension 256x256.L=256;% The original signal uses 8 bits:origbits=8;% Number of channels.M=32;% Bitratenbits=8;% Number of coefficients to keep for lossy compression.Nkeep=2000;% Constant to use for mulaw encoding / decoding.mu=2;% -------- initial setup ------------------% Load the cameraman picturef=cameraman();f = double(f);% Create window for Wilson orhonormal basis.g=wilorth(M,L);% Get coefficients.c=dwilt2(f,g,M);disp('----- Lossless compression -----');% Find max-value of imagemax_c=max(abs(f(:)));% Determine a thresholdthr_val=.5*max_c/(2^origbits);% Do threshholding[cN,N_thresh]=thresh('hard',c,thr_val);% Do quantization.cQ=uquant('unsigned',cN,nbits);% Reconstruct.f_lossless=idwilt2(cQ,g);% Display itfigure(1);subplot(1,2,1);colormap(gray);imagesc(f_lossless);disp('');disp('Compression ratio:');nbits*N_thresh/(origbits*L*L)disp('')disp('relative l^2 error:'); norm(f_lossless(:)-double(f(:)))/norm(double(f(:)))disp('----- Lossy compression ------');% Do N-term approximation.cN=largestn(c,Nkeep);% Do mulaw encoding[c_mulaw, sigweight] = mulawencode(cN,mu);% Do quantization.c_mulaw_Q=uquant('unsigned',c_mulaw,nbits);% Do mulaw decondingc_Q=mulawdecode(c_mulaw_Q,mu,sigweight);% Reconstruct.f_lossy=idwilt2(c_Q,g);% Display itsubplot(1,2,2);colormap(gray);imagesc(f_lossy);disp('');disp('Compression ratio:');nbits*Nkeep/(origbits*L*L)disp('')disp('relative l^2 error:'); norm(f_lossy(:)-double(f(:)))/norm(double(f(:)))

⌨️ 快捷键说明

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