多次应用MATLAB的idwt2函数

3

我正在使用MATLAB对图像应用离散小波变换。我多次(3次)应用它,以获得3级变换。我使用MATLAB提供的dwt2函数进行压缩和idwt2进行解压缩。问题是我不知道如何多次解压缩,例如多次应用idwt2到之前接收到的输出上,因为它返回一个矩阵。

x = idwt2(scaled3, vertical3, horizontal3, diagonal3, Lo_R, Ho_R);

如何对 x 应用 idwt2

2个回答

11

查看 dwt2idwt2 的文档,似乎有两个常规选项可以用于重构多次分解的图像:

  • 存储每个分解步骤中所有水平、垂直和对角线细节系数矩阵,并在重构中使用它们。
  • 对于您未从以前的分解步骤保存的任何细节系数矩阵,请输入一个空矩阵([])。

由于这是一个慢慢的一天,下面是一些代码,展示如何做到这一点以及每种情况的结果是什么...

首先,加载样本图像并初始化一些变量:

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

现在,应用分解(在这种情况下是3),并将每个步骤的细节系数矩阵存储在一个单元数组中:
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);

你应该看到类似这样的内容:

enter image description here

现在是重建的时间!以下代码执行“完整”重建(使用所有存储的细节系数矩阵)和“部分”重建(不使用任何细节系数矩阵),然后绘制图像:
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);

enter image description here

请注意,原始图像(左上角)和“完整”重建图像(右上角)看起来无法区分,但是“部分”重建图像(左下角)非常像素化。如果您只应用1或2个分解步骤,差异就不会那么严重。


0
% 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

目前你的回答不够清晰。请编辑并添加更多细节,以帮助其他人理解它如何回答所提出的问题。你可以在帮助中心找到有关如何撰写好答案的更多信息。 - Community

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接