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.