Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
interpolation for forward mapping

Subject: interpolation for forward mapping

From: Joe Xiao

Date: 10 May, 2012 17:39:13

Message: 1 of 7

Hi:

I am having trouble with interpolation for forward mapping:

I have the input image (mxnx3), and I have the output pixel coordinates in a mxn matrix. I am able to round the output pixel coordinates, and get the corresponding color from the input image. So I have a new image (mxnx3).

The problem is, how do I fill up the holes left behind during forward mapping. I was told to use scatter3interp() to interpolate but I don't understand how it works. Can some one please provide a detailed example on how to interpolate and fill up the holes? Also, what do you do with the output image coordinates that are negative?

Thank you,

Joe

Subject: interpolation for forward mapping

From: Matt J

Date: 10 May, 2012 18:04:21

Message: 2 of 7

"Joe Xiao" <joexiao1030@gmail.com> wrote in message <jogug1$ne4$1@newscl01ah.mathworks.com>...
> Hi:
>
> I am having trouble with interpolation for forward mapping:
>
> I have the input image (mxnx3), and I have the output pixel coordinates in a mxn matrix. I am able to round the output pixel coordinates, and get the corresponding color from the input image. So I have a new image (mxnx3).
================

Seems like a bad idea to do nearest-neighbor rounding. Why not use spline interpolation instead? In fact, why not use IMTRANSFORM to do the total image transformation for you?


> The problem is, how do I fill up the holes left behind during forward mapping.
==============

Why would there be holes? Your new image is the same size as your old one, so there's no reason to think any output grid data will be missing.

Subject: interpolation for forward mapping

From: Joe Xiao

Date: 10 May, 2012 18:30:32

Message: 3 of 7

Hi Matt:

I was implementing the moving least squares algorithm and end up with a mxn matrix where each element contains the coordinates of the new image. The problem is that the new coordinates may not be integers, they may be negative.



"Matt J" wrote in message <jogvv5$12c$1@newscl01ah.mathworks.com>...
> "Joe Xiao" <joexiao1030@gmail.com> wrote in message <jogug1$ne4$1@newscl01ah.mathworks.com>...
> > Hi:
> >
> > I am having trouble with interpolation for forward mapping:
> >
> > I have the input image (mxnx3), and I have the output pixel coordinates in a mxn matrix. I am able to round the output pixel coordinates, and get the corresponding color from the input image. So I have a new image (mxnx3).
> ================
>
> Seems like a bad idea to do nearest-neighbor rounding. Why not use spline interpolation instead? In fact, why not use IMTRANSFORM to do the total image transformation for you?
>
>
> > The problem is, how do I fill up the holes left behind during forward mapping.
> ==============
>
> Why would there be holes? Your new image is the same size as your old one, so there's no reason to think any output grid data will be missing.

Subject: interpolation for forward mapping

From: Matt J

Date: 10 May, 2012 19:51:11

Message: 4 of 7

"Joe Xiao" <joexiao1030@gmail.com> wrote in message <joh1g8$8da$1@newscl01ah.mathworks.com>...
> Hi Matt:
>
> I was implementing the moving least squares algorithm and end up with a mxn matrix where each element contains the coordinates of the new image. The problem is that the new coordinates may not be integers, they may be negative.
============

If they're negative, it means they're trying to access image intensity in the background, You can use the extrapval argument of INTERP2 to assign values to those coordinates.

Subject: interpolation for forward mapping

From: Joe Xiao

Date: 10 May, 2012 20:53:12

Message: 5 of 7

Hi Matt:

The issue is that I don't know how to use the interp2() or other interpolation functions, I don't understand how to apply them in my situation. This is what I have right now.

fvAll = abs(round(fvAll)); % mxn matrix containing the coordinates of the new image
m = size(img,1);
n = size(img,2);
newImage = zeros(m, n, 3);
xfvAll = reshape(fvAll(1,:),size(X));
yfvAll = reshape(fvAll(2,:),size(X));
% grab the color value from the old image
for col = 1 : n
    for row = 1 : m
        oldRow = Y(row, col);
        oldCol = X(row, col);
        if (yfvAll(row,col) == 0)
            yfvAll(row,col) = yfvAll(row,col) +1;
        end
        newRow = yfvAll(row, col);
        if (xfvAll(row,col) == 0)
            xfvAll(row,col) =xfvAll(row,col) +1;
        end
        newCol = xfvAll(row, col);
        newImage(newRow, newCol) = img(oldRow, oldCol);
    end
end
imshow(newImage)

This image right now turns out to be really bad because it doesn't have any interpolation. So based on the stuff I have, how do I apply interpolation. An example would be most helpful!

Thank you,

Joe

"Matt J" wrote in message <joh67e$rc$1@newscl01ah.mathworks.com>...
> "Joe Xiao" <joexiao1030@gmail.com> wrote in message <joh1g8$8da$1@newscl01ah.mathworks.com>...
> > Hi Matt:
> >
> > I was implementing the moving least squares algorithm and end up with a mxn matrix where each element contains the coordinates of the new image. The problem is that the new coordinates may not be integers, they may be negative.
> ============
>
> If they're negative, it means they're trying to access image intensity in the background, You can use the extrapval argument of INTERP2 to assign values to those coordinates.

Subject: interpolation for forward mapping

From: Matt J

Date: 10 May, 2012 21:45:19

Message: 6 of 7

"Joe Xiao" <joexiao1030@gmail.com> wrote in message <joh9ro$gte$1@newscl01ah.mathworks.com>...
>
> This image right now turns out to be really bad because it doesn't have any interpolation. So based on the stuff I have, how do I apply interpolation. An example would be most helpful!
===================

The following example is adapted from Example 1 in "doc interp2" where X,Y are the initial coordinates and XI,YI are the transformed coordinates:

[X,Y] = meshgrid(-3:.25:3);
Z = peaks(X,Y); %hypothetical image data
XI=X+2; YI=Y+2.7; %cooordinate transformation


extrapval=0;
ZI = interp2(X,Y,Z,XI,YI,'spline',extrapval); %Transform image data Z-->ZI

%Display results
mesh(X,Y,Z), hold, mesh(XI,YI,ZI+15)
hold off
axis([-3 3 -3 3 -5 20])

Subject: interpolation for forward mapping

From: ImageAnalyst

Date: 10 May, 2012 21:00:54

Message: 7 of 7

Matt:
Some more background in his duplicate thread:
http://groups.google.com/group/comp.soft-sys.matlab/browse_frm/thread/4b887d61833279b1?hl=en#
I recommended TriScatteredInterp but he can't figure out how to use
it.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us