当前位置:首页 > 彩色图像转灰度图像
彩色图像转灰度图像
L=imread('i:\\1.jpg') L=double(L);
Xrgb=0.2990*L(:,:,1)+0.5870*L(:,:,2)+0.1140*L(:,:,3); NbColors=255;
X=wcodemat(Xrgb,NbColors); map1=gray(NbColors); image(X);
colormap(map1); title('原图像的灰度图');
小波压缩-低频信息保留压缩方式 L=imread('i:\\1.jpg') L=double(L);
Xrgb=0.2990*L(:,:,1)+0.5870*L(:,:,2)+0.1140*L(:,:,3); NbColors=255;
X=wcodemat(Xrgb,NbColors); map1=gray(NbColors);
image(X);
colormap(map1);
title('原图像的灰度图'); axis square;
disp('灰度图像X的大小'); whos('X')
[c,s]=wavedec2(X,2,'bior3.7'); ca1=appcoef2(c,s,'bior3.7',1);
ch1=detcoef2('h',c,s,1);%水平方向 cv1=detcoef2('v',c,s,1);%垂直方向 cd1=detcoef2('d',c,s,1);%斜线方向 a1=wrcoef2('a',c,s,'bior3.7',1); h1=wrcoef2('h',c,s,'bior3.7',1); v1=wrcoef2('v',c,s,'bior3.7',1);
d1=wrcoef2('d',c,s,'bior3.7',1);%各频率成分重构 c1=[a1,h1;v1,d1];
image(c1);
colormap(gray); axis square;
title('分解后低频和高频信息'); ca1=appcoef2(c,s,'bior3.7',1); ca1=wcodemat(ca1,440,'mat',0); ca1=0.5*ca1;
disp('第一次压缩后图像的大小为:');
image(ca1); colormap(gray); %colormap(map); axis square;
title('第一次压缩图像'); whos('ca1')
ca2=appcoef2(c,s,'bior3.7',2); ca2=0.25*ca2;
image(ca2); colormap(gray); %colormap(map); axis square;
title('第二次压缩图像');
disp('第二次压缩后图像大小为:'); whos('ca2')
灰度图像X的大小
Name Size Bytes Class
X 150x125 150000 double array
Grand total is 18750 elements using 150000 bytes
第一次压缩后图像的大小为:
Name Size Bytes Class
ca1 82x70 45920 double array
Grand total is 5740 elements using 45920 bytes
第二次压缩后图像大小为:
Name Size Bytes Class
ca2 48x42 16128 double array
Grand total is 2016 elements using 16128 bytes
二维小波压缩 H=imread('i:\\1.jpg') H=double(H);
Grgb=0.2990*H(:,:,1)+0.5870*H(:,:,2)+0.1140*H(:,:,3); NbColors=255;
G=wcodemat(Grgb,NbColors); map2=gray(NbColors); figure(4); image(G);
colormap(map2);
title('原图像的灰度图'); %转换成为灰度级索引图像
[CA1,CH1,CV1,CD1]=dwt2(G,'bior3.7'); %从分解系数中提取近似和细节 [CA1,CH1,CV1,CD1]=dwt2(G,'bior3.7'); A1=upcoef2('a',CA1,'bior3.7',1); H1=upcoef2('h',CH1,'bior3.7',1); V1=upcoef2('v',CV1,'bior3.7',1); D1=upcoef2('d',CD1,'bior3.7',1); %显示近似和细节
%figure (' name ','近似分量A1'); colormap(map2); subplot(2,2,1);
image(wcodemat(A1,192)); title('近似A1'); subplot(2,2,2);
image(wcodemat(H1,192)); title('水平细节H1'); subplot(2,2,3);
image(wcodemat(V1,192)); title('垂直细节V1');
共分享92篇相关文档