DWT的Matlab问题

时间:2011-06-12 14:36:26

标签: matlab transform dwt

我正在尝试使用10点daubechies过滤器获得图像的第4级DWT。 (并自然地反转它!)

host = double(imread('lena512.bmp'));       % Load image data
nLevel = 4;                                 % Number of decompositions
cwA = cell(1,nLevel);                       % Approximation coefficients
cwH = cell(1,nLevel);                       % Horizontal detail coefficients
cwV = cell(1,nLevel);                       % Vertical detail coefficients
cwD = cell(1,nLevel);                       % Diagonal detail coefficients

% Do the DWT
myImage = host;
for iLevel = 1:nLevel,
  [cwA{iLevel},cwH{iLevel},cwV{iLevel},cwD{iLevel}] = dwt2(myImage,'db10');
  myImage = cwA{iLevel};
end

% Do the inverse DWT
fullRecon = cA{nLevel};
for iLevel = nLevel:-1:1
  fullRecon = idwt2(fullRecon,cH{iLevel},cV{iLevel},cD{iLevel},'db10');
end

上面的代码一直给我错误:

  

???使用==>时出错加   矩阵维度必须一致。

     

==>中的错误idwt2 at 93   x = upsconv2(a,{Lo_R,Lo_R},sx,dwtEXTM,shift)+ ...%近似。

     

==>中的错误假人18岁     fullRecon =     idwt2(fullRecon,CH {iLevel},CV {iLevel},CD {iLevel}, 'DB10');

我相信这是因为反dwt做了一些时髦的东西。我也试过改变dwtmode但它没有帮助。我真的很喜欢任何帮助。

PS:lena512.bmp只是莱娜的灰度图片。它的尺寸为512x512。

我愿意接受新的想法=)

1 个答案:

答案 0 :(得分:1)

将代码重写为

clear all;
host = double(imread('lena512.bmp'));       % Load image data
nLevel = 4;                                 % Number of decompositions
cwA = cell(1,nLevel);                       % Approximation coefficients
cwH = cell(1,nLevel);                       % Horizontal detail coefficients
cwV = cell(1,nLevel);                       % Vertical detail coefficients
cwD = cell(1,nLevel);                       % Diagonal detail coefficients

% Size matrix
s = [size(host,1) size(host,2)];

% Do the DWT
myImage = host ;
for iLevel = 1:nLevel
  [cwA{iLevel},cwH{iLevel},cwV{iLevel},cwD{iLevel}] = dwt2(myImage, 'db10');
  s = [s; size(cwH{iLevel},1) size(cwH{iLevel},2)];
  myImage = cwA{iLevel};
end

% Do the inverse DWT
fullRecon = cwA{nLevel};
for iLevel = nLevel:-1:1
  fullRecon = idwt2(fullRecon,cwH{iLevel},cwV{iLevel},cwD{iLevel},'db10',s(iLevel,:));
end

解决了我的问题。希望它能帮助别人......