我正在使用MATLAB对图像应用离散小波变换。我多次(3次)应用它,以获得3级变换。我使用MATLAB提供的dwt2
函数进行压缩和idwt2
进行解压缩。问题是我不知道如何多次解压缩,例如多次应用idwt2
到之前接收到的输出上,因为它返回一个矩阵。
x = idwt2(scaled3, vertical3, horizontal3, diagonal3, Lo_R, Ho_R);
如何对 x 应用 idwt2
?
我正在使用MATLAB对图像应用离散小波变换。我多次(3次)应用它,以获得3级变换。我使用MATLAB提供的dwt2
函数进行压缩和idwt2
进行解压缩。问题是我不知道如何多次解压缩,例如多次应用idwt2
到之前接收到的输出上,因为它返回一个矩阵。
x = idwt2(scaled3, vertical3, horizontal3, diagonal3, Lo_R, Ho_R);
如何对 x 应用 idwt2
?
查看 dwt2
和 idwt2
的文档,似乎有两个常规选项可以用于重构多次分解的图像:
[]
)。由于这是一个慢慢的一天,下面是一些代码,展示如何做到这一点以及每种情况的结果是什么...
首先,加载样本图像并初始化一些变量:
load woman; % Load image data
nLevel = 3; % Number of decompositions
nColors = size(map, 1); % Number of colors in colormap
cA = cell(1, nLevel); % Approximation coefficients
cH = cell(1, nLevel); % Horizontal detail coefficients
cV = cell(1, nLevel); % Vertical detail coefficients
cD = cell(1, nLevel); % Diagonal detail coefficients
startImage = X;
for iLevel = 1:nLevel,
[cA{iLevel}, cH{iLevel}, cV{iLevel}, cD{iLevel}] = dwt2(startImage, 'db1');
startImage = cA{iLevel};
end
wcodemat
):tiledImage = wcodemat(cA{nLevel}, nColors);
for iLevel = nLevel:-1:1,
tiledImage = [tiledImage wcodemat(cH{iLevel}, nColors); ...
wcodemat(cV{iLevel}, nColors) wcodemat(cD{iLevel}, nColors)];
end
figure;
imshow(tiledImage, map);
你应该看到类似这样的内容:
现在是重建的时间!以下代码执行“完整”重建(使用所有存储的细节系数矩阵)和“部分”重建(不使用任何细节系数矩阵),然后绘制图像:fullRecon = cA{nLevel};
for iLevel = nLevel:-1:1,
fullRecon = idwt2(fullRecon, cH{iLevel}, cV{iLevel}, cD{iLevel}, 'db1');
end
partialRecon = cA{nLevel};
for iLevel = nLevel:-1:1,
partialRecon = idwt2(partialRecon, [], [], [], 'db1');
end
figure;
imshow([X fullRecon; partialRecon zeros(size(X))], map, ...
'InitialMagnification', 50);
请注意,原始图像(左上角)和“完整”重建图像(右上角)看起来无法区分,但是“部分”重建图像(左下角)非常像素化。如果您只应用1或2个分解步骤,差异就不会那么严重。
% Multi-level reconstruction from DWT coefficients
% The variable "coefs" is what you get when you perform forward dwt2()
% on the image you're decomposing. It is a long row
% vector that has cA- approximation details, cH -horizontal details, cV-
% vertical details, cD-diagonal details
L=3; % For db 3-level reconstruction for example
k=size(image,1)/2^L; % I am assuming a square sized image where both
% dimensions are equal
for level=0:(L-1)
s=k*2^level;
if level==0
cA=reshape(coefs(1,1:s^2),s,s);
figure;imshow(cA,[])
end
cH=reshape(coefs(1,(s^2+1):2*s^2),s,s);
figure;imshow(cH,[])
cV=reshape(coefs(1,(2*s^2+1):3*s^2),s,s);
figure;imshow(cV,[])
cD=reshape(coefs(1,(3*s^2+1):4*s^2),s,s);
figure;imshow(cD,[])
I_rec=idwt2(cA,cH,cV,cD,"db1");
figure;imshow(I_rec,[])
cA=I_rec; % The recosntructed image is the approximation detail-cA
% for next levels of reconstruction
end