Question

I am trying to execute this function for image reconstruction where ra, rh, rv, rd are reconstructed coefficients. but i am facing problem in addition and subtraction.

Please help.

Xhat = ra2 + rh2 + rv2 + rd2 + rh1 + rv1 + rd1;
sprintf('Reconstruction error (using wrcoef2) = %g', max(max(abs(X-Xhat))))

OR

XXhat = waverec2(wc,s,wname);
sprintf('Reconstruction error (using waverec2) = %g', max(max(abs(X-XXhat)))

I decomposed the image using:

   >> a1 = appcoef2(wc,s,wname,1);         
    >> h1 = detcoef2('h',wc,s,1);           
    >> v1 = detcoef2('v',wc,s,1);           
    >> d1 = detcoef2('d',wc,s,1);  

    >> a2 = appcoef2(wc,s,wname,2);
    >> h2 = detcoef2('h',wc,s,2);
    >> v2 = detcoef2('v',wc,s,2);
    >> d2 = detcoef2('d',wc,s,2);

Then reconstructed using above parameters. Now i have to comnbine them.

Was it helpful?

Solution

I'm guessing your problem is almost certainly at the abs(X-Xhat) line.

Why? You seem to be doing some sort of wavelet decomposition/reconstruction, and if you don't pass in the right parameters your output may be larger than the original image. Therefore it makes no sense to ask for X-Xhat if these are of different sizes and you will get an error message.

The best way of fixing this is to when you reconstruct (presumably using upcoef2), is to pass size as an additional parameter to truncate. A truncated (heh) and adjusted example from the docs:

load woman;
[c,s] = wavedec2(X,2,'db4');
siz = s(size(s,1),:); 
ca1 = appcoef2(c,s,'db4',1); 
a = upcoef2('a',ca1,'db4',1,siz);
a2 = upcoef2('a',ca1,'db4',1);

You'll see that size(X) and size(a) are both 256 x 256, but size(a2) is larger. Therefore a-X is fine and a2-X will give you a "Matrix dimensions must agree." error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top