小波分解的matlab实践以及相关内置函数

小波分解的matlab实践以及相关内置函数参考 http maiqiuzhizhu blog sohu com 110325150 htmlhttp ww2 mathworks cn help wavelet ref wrcoef2 htmlhttp ww2 mathworks cn help wavelet ref appcoef2 htmlhttp ww2 mathworks cn help wavel

1 小波变换的内置函数

1.1 wavedec2函数

详细解释输出c和s

1.2 wrcoef2 函数

clear; close all; file = 'lena_gray_512.tif'; img = imread(file); img = double(img); % 对图像进行3层的小波分解 N = 3; % 设置分解层数 [c,s] = wavedec2(img,N,'db1'); % 对各层的近似图像a进行重构 a1 = wrcoef2('a',c,s,'db1',1); a2 = wrcoef2('a',c,s,'db1',2); a3 = wrcoef2('a',c,s,'db1',3);

1.3 提取低频分量和高频分量

上面我们使用wavedec2对图像进行了多尺度分解,如果你想提取对应层数的高频或者低频分量就可以使用下面的2个函数。

appcoef2 函数

detcoef2 函数

重构函数 waverec2

% X contains the loaded image. % Perform decomposition at level 2  % of X using sym4.  [c,s] = wavedec2(X,2,'sym4'); % Reconstruct X from the wavelet  % decomposition structure [c,s].  a0 = waverec2(c,s,'sym4');

matlab程序

clear; close all; file = 'lena_gray_512.tif'; img = imread(file); figure(10);imshow(img);title('原始图像'); % % ================================================= % 进行小波分解 % % ================================================= % 对图像进行2层的小波分解 N = 2 ; [c,s] = wavedec2(img,N,'db1'); % % ================================================= % 提取各层对应的低频和高频系数 % % ================================================= % 对于原始图像512×512 ,其小波分解第1层维度为256×256,第2层维度为128×128 % 提取小波分解中第1层低频系数和高频系数 a_ca1 = appcoef2(c,s,'db1',1); a_ch1 = detcoef2('h',c,s,1); a_cv1 = detcoef2('v',c,s,1); a_cd1 = detcoef2('d',c,s,1); % 显示第1层的各分量 figure(1); subplot(4,4,[3,4,7,8]);imshow(a_ch1,[]); subplot(4,4,[9,10,13,14]);imshow(a_cv1,[]); subplot(4,4,[11,12,15,16]);imshow(a_cd1,[]); % 提取第2层的低频系数和高频系数 ca2 = appcoef2(c,s,'db1',2); ch2 = detcoef2('h',c,s,2); cv2 = detcoef2('v',c,s,2); cd2 = detcoef2('d',c,s,2); % % 显示第2层的各分量 subplot(4,4,1);imshow(ca2,[]); subplot(4,4,2);imshow(ch2,[]); subplot(4,4,5);imshow(cv2,[]); subplot(4,4,6);imshow(cd2,[]); % % ================================================= % 分别对各频率成分进行重构 % % ================================================= % 使用第2层进行重构 recon_a1 = wrcoef2('a',c,s,'db1',2); recon_h1 = wrcoef2('h',c,s,'db1',2); recon_v1 = wrcoef2('v',c,s,'db1',2); recon_d1 = wrcoef2('d',c,s,'db1',2); % 显示各重构的成分 维度都在512×512 recon_set = [recon_a1,recon_h1;recon_v1,recon_d1]; figure(2);imshow(recon_set,[]);title('第2层小波系数的重构'); % % ================================================= % 重构出原始图像 % % ================================================= recon_img = recon_a1+recon_h1+recon_v1+recon_d1; recon_img = mat2gray(recon_img ); figure(3);imshow(recon_img );title('重构出的原始图像');

程序运行结果

这里写图片描述
这里写图片描述
这里写图片描述




版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/178924.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月26日 下午4:13
下一篇 2026年3月26日 下午4:13


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号