www.gusucode.com > wavelet 源码程序 matlab案例代码 > wavelet/CompressionAndUncompressionOfAGrayscaleImageExample.m
%% Compression and Uncompression of a Grayscale Image %% % This example shows how to compress a grayscale image using the set % partitioning in hierarchical trees (|'spiht'|) compression method. It % also computes the mean square error (MSE) and the peak signal to noise % ratio (PSNR) error values. You use these two measures to quantify the % error between two images. The PSNR is expressed in decibels. %% % Load the image and store it in a file. load mask; [cr,bpp] = wcompress('c',X,'mask.wtc','spiht','maxloop',12) %% % Load the stored image from the file, uncompress it, and delete the file. Xc = wcompress('u','mask.wtc'); delete('mask.wtc') %% % Display the original and compressed images. colormap(pink(255)) subplot(1,2,1); image(X); title('Original image') axis square subplot(1,2,2); image(Xc); title('Compressed image') axis square %% % Compute the MSE and PSNR. D = abs(X-Xc).^2; mse = sum(D(:))/numel(X) psnr = 10*log10(255*255/mse)