Simple interpolation inside matrix

Simple question, I have matrix A=
[1 1 1 1 1]
[1 1 60 1 1]
[1 1 1 1 1]
and i want to interpolate values inside the matrix to get sometgink like
[1 15 30 15 1]
[15 30 60 30 15]
[1 15 30 15 1]
I know that i have to use interp2 but it is just not working for me...

 Accepted Answer

Andrei Bobrov
Andrei Bobrov on 7 Dec 2013
Edited: Andrei Bobrov on 8 Dec 2013
A =[ 1 1 1 1 1
1 1 60 1 1
1 1 1 1 1];
bw = A>1;
B = bwdist(bw,'cityblock');
v = [60./pow2(0:max(B(:))-1),1];
out = v(B+1);
ADD
use scatteredInterpolant:
A = [40 1 1 1 60
1 1 20 1 1
15 1 1 1 1];
[ii,jj] = find(A > 1);
ii = [ii;size(A,1)];
jj = [jj;size(A,2)];
F = scatteredInterpolant(ii,jj,[A(A>1);A(end)]);
[x,y]=ndgrid(1:size(A,1),1:size(A,2));
out = F(x,y);

5 Comments

This works fine but what if i want to make it more generally. For example to interpolate matrixes like:
[40 1 1 1 60]
[1 1 20 1 1]
[15 1 1 1 1]
and to somehow interpolate between pixels in matrix.
Andrei Bobrov
Andrei Bobrov on 8 Dec 2013
Edited: Andrei Bobrov on 9 Dec 2013
see ADD
what is ADD?
see code after word ADD in my answer
Thank you very much!

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Asked:

on 7 Dec 2013

Commented:

on 9 Dec 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!