COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### linear interpolation/applying deformation field in matlab

• Email
• Follow

```Hello everyone,

I have a 2D image and a 2D deformation field that I would like to
apply to this image using linear interpolation. So, each deformation
field element is a 2 element vector that says the new position for
that pixel and I would like to interpolate the intensities at this
position using linear interpolation.

I know how I would do it in C or C++ by just looking at the previous
and next pixels in each dimension and using the relative distance from
the new position as the weight.

However, I am having trouble figuring out how I can do this in Matlab
in a vectorised way without looping through the pixels (which is just
too slow). I want to call this routine a lot and would be nice to do
this in a vectorized way..

Thanks,

Luc
```
 0

See related articles to this posting

```Hello, I am bumping this because I am looking exactly at the same problem. Any imaging  geniuses out there ?

Luca <luca.pamparana@gmail.com> wrote in message <9d9359d7-8260-4928-a316-74a730e83ab7@k14g2000pra.googlegroups.com>...
> Hello everyone,
>
> I have a 2D image and a 2D deformation field that I would like to
> apply to this image using linear interpolation. So, each deformation
> field element is a 2 element vector that says the new position for
> that pixel and I would like to interpolate the intensities at this
> position using linear interpolation.
>
> I know how I would do it in C or C++ by just looking at the previous
> and next pixels in each dimension and using the relative distance from
> the new position as the weight.
>
> However, I am having trouble figuring out how I can do this in Matlab
> in a vectorised way without looping through the pixels (which is just
> too slow). I want to call this routine a lot and would be nice to do
> this in a vectorized way..
>
> Thanks,
>
> Luc
```
 0

```"luis zertuche" <zertuche.luis@gmail.com> wrote in message <jic5p5\$k7e\$1@newscl01ah.mathworks.com>...
> Hello, I am bumping this because I am looking exactly at the same problem. Any imaging  geniuses out there ?

help interp2

Bruno
```
 0
Reply b.luong5955 (6403) 2/26/2012 7:23:12 AM

```Here is an example. I separately interpolate the x and y components of the vector fields. I am not sure if there is a benefit in somehow jointly interpolating the components at this time.

clear;close all
[M,N]=size(X);
%% Define Grid
[Theta,Phi]=meshgrid(linspace(0,1,floor(M/50)),linspace(0,1,floor(N/50)));
%% Define Arbitrary Vector Feild
b(:,:,1)= .7*(.5-Theta);
b(1,:,1)=0;b(end,:,1)=0;b(:,1,1)=0;b(:,end,1)=0;
b(:,:,2)= .7*(.5-Phi);
b(1,:,2)=0;b(end,:,2)=0;b(:,1,2)=0;b(:,end,2)=0;
%% Plot Vector Feild
close all
image(linspace(0,1,M),linspace(0,1,N),X);hold on;
quiver(Theta,Phi,b(:,:,1),b(:,:,2),0,'white','linewidth',1)
%% interpolate at each gridpoint
[theta,phi]=meshgrid(linspace(0,1,M),linspace(0,1,N));
bnew(:,:,1)=interp2(Theta,Phi,b(:,:,1),theta,phi);
bnew(:,:,2)=interp2(Theta,Phi,b(:,:,2),theta,phi);
%% Apply Deformation to the grid
close all
figure(1)
mesh(theta,phi,X'); view([0,0,1]);title('Before')
figure(2)
mesh(theta+bnew(:,:,1),phi+bnew(:,:,2),X');title('After')
view([0,0,1])
```
 0
Reply mmr09 (1) 1/7/2013 5:43:35 PM

3 Replies
690 Views

Similar Articles

12/6/2013 10:56:41 PM
page loaded in 36243 ms. (0)