Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Image forward mapping - urgent!

23 views
Skip to first unread message

Joe Xiao

unread,
May 3, 2012, 6:19:19 PM5/3/12
to
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

ImageAnalyst

unread,
May 3, 2012, 6:34:33 PM5/3/12
to
--------------------------------------------------
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.

Joe Xiao

unread,
May 9, 2012, 3:32:07 PM5/9/12
to
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 <imagea...@mailinator.com> wrote in message <c87e70c4-b87c-448d...@vd1g2000pbc.googlegroups.com>...

ImageAnalyst

unread,
May 9, 2012, 5:21:17 PM5/9/12
to
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.

Joe Xiao

unread,
May 10, 2012, 12:33:21 PM5/10/12
to
Hi:

Thank you for replying to my post.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/319747#876321

I have a follow up question to what you mentioned and it would be great if you can provide some insight on it. You mentioned to use triscatterinterp() to fill in the holes. Can you please be more specific and provide an example of how to do that? Also, what do you do with output image pixels that are negative?

I really appreciate your help!

Thanks,

Joe

ImageAnalyst

unread,
May 10, 2012, 1:45:50 PM5/10/12
to
I haven't used it. Follow the examples in the help or look to other
sources of examples. What to do with pixels that get rotated out of
the field of view is your choice. You can keep them or crop them out,
whatever you want to do.
0 new messages