0

I am trying to get the 4th level DWT of an image using the 10 point daubechies filter. (and naturally inverting it!)

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

The code above keeps giving me the error :

??? Error using ==> plus Matrix dimensions must agree.

Error in ==> idwt2 at 93 x = upsconv2(a,{Lo_R,Lo_R},sx,dwtEXTM,shift)+ ... % Approximation.

Error in ==> dummy at 18 fullRecon = idwt2(fullRecon,cH{iLevel},cV{iLevel},cD{iLevel},'db10');

This I believe is due to the inverse dwt doing some funky stuff. I also tried changing dwtmode but it didn't help. I would really appriciate any help.

PS: lena512.bmp is just a gray-scale picture of lena. It's dimensions are 512x512.

I am open to fresh ideas =)

foobar
  • 357
  • 1
  • 3
  • 17

1 Answers1

1

Rewriting the code as

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

fixed my problem. Hope it helps others...

foobar
  • 357
  • 1
  • 3
  • 17