小波变换图像压缩matlab程序,Matlab小波变换实现图像压缩的简单的程序求助

% Wavelet image compression - RGB images

clear all;

close all;

% Reading an image file

im = input('Enter a image');

X=imread(im);

% inputting the decomposition level and name of the wavelet

n=input('Enter the decomposition level');

wname = input('Enter the name of the wavelet');

x = double(X);

NbColors = 255;

map = gray(NbColors);

x = uint8(x);

%Conversion of RGB to Grayscale

% x = double(X);

% xrgb  = 0.2990*x(:,:,1) + 0.5870*x(:,:,2) + 0.1140*x(:,:,3);

% colors = 255;

% x = wcodemat(xrgb,colors);

% map = pink(colors);

% x = uint8(x);

% A wavelet decomposition of the image

[c,s] = wavedec2(x,n,wname);

% wdcbm2 for selecting level dependent thresholds

alpha = 1.5; m = 2.7*prod(s(1,:));

[thr,nkeep] = wdcbm2(c,s,alpha,m)

% Compression

[xd,cxd,sxd,perf0,perfl2] = wdencmp('lvd',c,s,wname,n,thr,'h');

disp('Compression Ratio');

disp(perf0);

% Decompression

R = waverec2(c,s,wname);

rc = uint8(R);

% Plot original and compressed images.

subplot(221), image(x);

colormap(map);

title('Original image')

subplot(222), image(xd);

colormap(map);

title('Compressed image')

% Displaying the results

xlab1 = ['2-norm rec.: ',num2str(perfl2)];

xlab2 = [' %  -- zero cfs: ',num2str(perf0), ' %'];

xlabel([xlab1 xlab2]);

subplot(223), image(rc);

colormap(map);

title('Reconstructed image');

%Computing the image size

disp('Original Image');

imwrite(x,'original.tif');

imfinfo('original.tif')

disp('Compressed Image');

imwrite(xd,'compressed.tif');

imfinfo('compressed.tif')

disp('Decompressed Image');

imwrite(rc,'decompressed.tif');

imfinfo('decompressed.tif')

麻烦达人稍微帮忙解释注释一下 感激不尽

[本帖最后由 mooni 于 2009-5-31 21:04 编辑]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值