From: John D'Errico on
"Obaid Mushtaq" <obaidmushtaq(a)yahoo.com> wrote in message <i394fv$8kd$1(a)fred.mathworks.com>...
> Hi,
>
> Thanks for your response. Actually I get random shadowing values at a pre-defined 2D grid and these values have a particular variance as they are normally distributed.
>
> After that I want to interpolate the values over a finer grid but the variance of the interpolated version changes as I showed you in case of ML functions.
>
> See [1] p.p 44. They say that the linear interpolation formula guarantees the same variance. I was confused why ML's function is not preserving.
>

It matters not that they say this. They are wrong.

A linear interpolant is simply NOT a variance
preserving operation on a signal. For example,

n = 3;
x = linspace(0,1,n);
y = rand(size(x));

N = 100;
xN = linspace(0,1,N);
yN = interp1(x,y,xN,'linear');

var(y)
ans =
0.137117842952513

var(yN)
ans =
0.0404878603151538

So despite some statement that it is variance
preserving because they say it is, surely you
can believe that someone managed to publish
a paper with an incorrect statement in it?

John
From: us on
"John D'Errico"
> > See [1] p.p 44. They say that the linear interpolation formula guarantees the same variance. I was confused why ML's function is not preserving.
> >
>
> It matters not that they say this. They are wrong.

correct - but: it's NOT what they say; it's what the OP thinks they are saying...

us
From: Matt J on
"Obaid Mushtaq" <obaidmushtaq(a)yahoo.com> wrote in message <i37490$ic7$1(a)fred.mathworks.com>...
> Hi all,
>
> I have this simple question. If the answer is yes, please tell me if it is possible to preserve the variance of the interpolated data. You can take me as a noobie in Statistics.
==================

As the others have mentioned, interpolation will change the variance of data. To see a little bit how to analyze this, recall that interpolation can be expressed as a matrix/vector multiplication y=T*z where the matrix T represents the operation of interpolation of the 1D vector z. Also, if Zcov is the covariance matrix of z, then the covariance matrix of y is

Ycov=T*Zcov*T.'

If you have uniformly white noise, with variance Zvar=64, as in your example, the above leads to the following expression for diag(Ycov), the variances of Y,

diag(Ycov)=sum( T.^2, 2) *Zvar

So, unless sum( T.^2, 2) is uniformly 1, which it will not generally be, you will not preserve the variance.

However, if you wish, you could use the above expressions to compute the variance map diag(Ycov). You could then post-scale your results to correct the variance, restoring them to their original values.

The code below shows how you can compute the VarianceMap for a 2D image using my interpMatrix and KronProd tools:

http://www.mathworks.com/matlabcentral/fileexchange/26292-regular-control-point-interpolation-matrix-with-boundary-conditions

http://www.mathworks.com/matlabcentral/fileexchange/25969-efficient-object-oriented-kronecker-product-manipulation


sampfactor=.1;
tri=@(x) (1-abs(x)).*(abs(x)<=1);
kernel=tri(-1:sampfactor:1);
[~,origin]=max(kernel);

T=interpMatrix(kernel,origin,r,1/sampfactor); %Factor of 10 2D interpolation as matrix

Timg=KronProd({T},[1,1]); %2D version as KronProd Object

Vars = full(sum( Timg.^2 ,2)*var(Z(:))); %variances of interpolated result

VarianceMap=reshape(Vars,sqrt(numel(Vars)),[]);
From: Obaid Mushtaq on
Thanks to all for your comments and OK I agree that variance doesn't need to be preserved but I would appreciate if someone could explain me why in the following code the variance is preserved. Here I am trying to interpolate using the linear interpolation formula given in the document I mentioned before.

@US: If you think I misunderstood something in the document, please let me know. I would appreciate.

BR,

Obaid

d=20; sigma=10;
xMin=300; xMax=900; yMin=200; yMax=600;
xmin=xMin-d; xmax=xMax+d; ymin=yMin-d; ymax=yMax+d;

% Coarse grid to be interpolated
xg=xmin:d:xmax; yg=ymin:d:ymax;
[Xg,Yg]=meshgrid(xg,yg);
[rg,cg]=size(Xg);
Zg=sqrt(sigma)*randn(rg,cg);
fprintf('Variance of original data %f\n',var(reshape(Zg,1,numel(Zg))))

% Finer grid
res=d/50;
xi=xMin:res:xMax; yi=yMin:res:yMax;
[Xi,Yi]=meshgrid(xi,yi);
[ri,ci]=size(Xi);

% Matlab Interpolation
Zm=interp2(Xg,Yg,Zg,Xi,Yi);
figure
colormap(jet)
imagesc(Zm)
set(gca,'YDir','normal')
colorbar

fprintf('Variance of ML interpolated data %f\n',var(reshape(Zm,1,numel(Zm))))

% Interpolation using IEEE doc
Zf=zeros(rg,cg);
l=1; m=1;
for ii=rg:-1:1
for jj=1:cg
Zf(jj,ii)=Zg(l,m);
m=m+1;
end
l=l+1;
m=1;
end

S=zeros(4);
Zi=zeros(ri,ci);
for i=1:ri
for j=1:ci
idx=fix((Xi(i,j)-xmin)/d);
idy=fix((Yi(i,j)-ymin)/d);
q=idx+1;
p=idy+1;
S(1)=Zf(q,p+1);
S(2)=Zf(q+1,p+1);
S(4)=Zf(q,p);
S(3)=Zf(q+1,p);
xpos=rem((Xi(i,j)-xmin),d);
ypos=rem((Yi(i,j)-ymin),d);
Zi(i,j) = sqrt(1-xpos/d)*(S(1)*sqrt(ypos/d) + ...
S(4)*sqrt(1-ypos/d)) + ...
(S(2)*sqrt(ypos/d) + ...
S(3)*sqrt(1-ypos/d) )*sqrt(xpos/d);
end
end

fprintf('Variance interpolated data %f\n',var(reshape(Zi,1,numel(Zi))))

% Flip for displaying purpose
Zii=zeros(ci,ri);
l=1; m=1;
for ii=ri:-1:1
for jj=1:ci
Zii(jj,ii)=Zi(l,m);
m=m+1;
end
l=l+1;
m=1;
end

figure
colormap(jet)
imagesc(Zii')
set(gca,'YDir','normal')
colorbar
From: Matt J on
"Obaid Mushtaq" <obaidmushtaq(a)yahoo.com> wrote in message <i3a618$22d$1(a)fred.mathworks.com>...
> Thanks to all for your comments and OK I agree that variance doesn't need to be preserved but I would appreciate if someone could explain me why in the following code the variance is preserved. Here I am trying to interpolate using the linear interpolation formula given in the document I mentioned before.
==================

The interpolation formula in the IEEE doc is not remotely linear. In particular, if you rerun your code on a uniform image

Zg=ones(rg,cg);

a linear interpolation should give you a nice uniform image, as interp2 in fact does. However, you will see that the IEEE doc interpolation scheme gives a horribly artifacted, non-uniform result.

Admittedly, this nonlinear interpolation method does seem to have an interesting variance preservation property, but it sacrifices other commonly desired properties of interpolators, like uniformity-preservation, to get it.




> % Interpolation using IEEE doc
> Zf=zeros(rg,cg);
> l=1; m=1;
> for ii=rg:-1:1
> for jj=1:cg
> Zf(jj,ii)=Zg(l,m);
> m=m+1;
> end
> l=l+1;
> m=1;
> end
===============

Incidentally, this complicated for-loop looks like it can be done in one line as

Zf=fliplr(Zg.');