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:
Image forward mapping - urgent!

Subject: Image forward mapping - urgent!

From: Joe Xiao

Date: 3 May, 2012 22:19:19

Message: 1 of 4

Hi:

I am trying to complete a project and it involves forward mapping for images. I have the original image (mxnx3) pixel locations, stored in 'xv' (mxn) and 'yv'(mxn). I have applied a (moving least squares deformation) transformation to it and obtained new pixel locations 'xfv' and 'yfv', both (mxn).
e.g xv(1,1) = 1. yv(1,1) =1
     xfv(1,1) = 5, yfv(1,1) = 2.
     i.e. pixel (1,1) in the original image moved to pixel (5,2) in the new image.

Given this information, how do I do a forward mapping so that I can grab the RGB values from the original image and feed them to the corresponding pixel in the new image. I would appreciate it if you can provide detailed code that will produce the new image. I am aware of 'holes' that might appear so if would be great if there is some sort of interpolation to take care of that.

Thank you in advance!

Joe

Subject: Image forward mapping - urgent!

From: ImageAnalyst

Date: 3 May, 2012 22:34:33

Message: 2 of 4

On May 3, 6:19 pm, "Joe Xiao" <joexiao1...@gmail.com> wrote:
> Hi:
>
> I am trying to complete a project and it involves forward mapping for images. I have the original image (mxnx3) pixel locations, stored in 'xv' (mxn) and 'yv'(mxn). I have applied a (moving least squares deformation) transformation to it and obtained new pixel locations 'xfv' and 'yfv', both (mxn).
> e.g xv(1,1) = 1. yv(1,1) =1
>      xfv(1,1) = 5, yfv(1,1) = 2.
>      i.e. pixel (1,1) in the original image moved to pixel (5,2) in the new image.
>
> Given this information, how do I do a forward mapping so that I can grab the RGB values from the original image and feed them to the corresponding pixel in the new image. I would appreciate it if you can provide detailed code that will produce the new image. I am aware of 'holes' that might appear so if would be great if there is some sort of interpolation to take care of that.
>
> Thank you in advance!
>
> Joe

--------------------------------------------------
How about

newImage = zeros(m, n, 3);
for col = 1 : n
  for row = 1 : m
    oldRow = yv(row, col);
    oldCol = xv(row, col);
    newRow = yfv(row, col);
    newCol = xfv(row, col);
    newImage(newRow, newCol) = oldImage(oldRow, oldCol);
  end
end

Then use TriScatteredInterp() to fill in the holes.

Subject: Image forward mapping - urgent!

From: Joe Xiao

Date: 9 May, 2012 19:32:07

Message: 3 of 4

Hi:

Thank you for the msg! I realized that there is some rounding issues and some of the coordinates in the new image are negative, what should I do there? Also, can you provide a concrete example on how to use scatter3interp() and generate the final image?

Thank you,

Joe


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <c87e70c4-b87c-448d-b101-c0d24190dcd1@vd1g2000pbc.googlegroups.com>...
> On May 3, 6:19 pm, "Joe Xiao" <joexiao1...@gmail.com> wrote:
> > Hi:
> >
> > I am trying to complete a project and it involves forward mapping for images. I have the original image (mxnx3) pixel locations, stored in 'xv' (mxn) and 'yv'(mxn). I have applied a (moving least squares deformation) transformation to it and obtained new pixel locations 'xfv' and 'yfv', both (mxn).
> > e.g xv(1,1) = 1. yv(1,1) =1
> >      xfv(1,1) = 5, yfv(1,1) = 2.
> >      i.e. pixel (1,1) in the original image moved to pixel (5,2) in the new image.
> >
> > Given this information, how do I do a forward mapping so that I can grab the RGB values from the original image and feed them to the corresponding pixel in the new image. I would appreciate it if you can provide detailed code that will produce the new image. I am aware of 'holes' that might appear so if would be great if there is some sort of interpolation to take care of that.
> >
> > Thank you in advance!
> >
> > Joe
>
> --------------------------------------------------
> How about
>
> newImage = zeros(m, n, 3);
> for col = 1 : n
> for row = 1 : m
> oldRow = yv(row, col);
> oldCol = xv(row, col);
> newRow = yfv(row, col);
> newCol = xfv(row, col);
> newImage(newRow, newCol) = oldImage(oldRow, oldCol);
> end
> end
>
> Then use TriScatteredInterp() to fill in the holes.

Subject: Image forward mapping - urgent!

From: ImageAnalyst

Date: 9 May, 2012 21:21:17

Message: 4 of 4

On May 9, 3:32 pm, "Joe Xiao" <joexiao1...@gmail.com> wrote:
> Hi:
>
> Thank you for the msg! I realized that there is some rounding issues and some of the coordinates in the new image are negative, what should I do there? Also, can you provide a concrete example on how to use scatter3interp() and generate the final image?
>
> Thank you,
>
> Joe
-----------------------------------------
If some pixels from your input image get sent to negative coordinates,
then you can just enlarge your canvass to accomodate them, or you can
ignore them, depending on if you want them clipped off your output
image or not.

I don't have demo ready to go. I'd have to write one up specially for
you, but I'm sure you can do that just as well as I can.

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