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
