RE: [Flashcoders] OT: Need math help

2006-07-14 Thread Danny Kodicek
 I wonder if someone would be willing to help me off-list with a math
 problem or can refer me to a more appropriate person/list to ask this
 question:

 I have a photograph of a rectangle where the camera was slightly
 off-center and not parallel to the plane of the rectangle, so in the
 resulting photo, the rectangle is slightly distorted. I want to distort
 the image by repositioning the corner points of the photograph so that
 the interior rectangle is precisely positioned and sized.

 1) I know the size of the photo,
 2) I know the coordinates of the rectangle's corners in the photo
 3) I know the coordinates where I want the rectangle's corners to be
 after the transformation.

 I need to know the new coordinates of the photo's corners to achieve #3.

Just an addendum to my previous email: I didn't think it through properly.
My note about the affine transformations said it all: I forgot perspective.

I don't have time right now to think about the full answer, which may
involve a 4x4 matrix (in order to take into account the third dimension).
But there's probably an easier solution.

Danny

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] OT: Need math help

2006-07-14 Thread Danny Kodicek

 I wonder if someone would be willing to help me off-list with a math
 problem or can refer me to a more appropriate person/list to ask this
 question:

 I have a photograph of a rectangle where the camera was slightly
 off-center and not parallel to the plane of the rectangle, so in the
 resulting photo, the rectangle is slightly distorted. I want to distort
 the image by repositioning the corner points of the photograph so that
 the interior rectangle is precisely positioned and sized.

 1) I know the size of the photo,
 2) I know the coordinates of the rectangle's corners in the photo
 3) I know the coordinates where I want the rectangle's corners to be
 after the transformation.

 I need to know the new coordinates of the photo's corners to achieve #3.

I don't know if you got the offlist answer you asked for, but it's probably
a question worth answering on-list too.

Basically what you need to do is to invert a transformation matrix. So you
need to start by constructing the matrix M used to transform the original
rectangle R = (0,-H,W,0) to the distorted rectangle: that is (using
homogeneous coordinates (the kind used in Flash's own Matrix object)), M
maps (0,0,1) to (x1,y1,1), (0,-H,1) to (x2,y2,1), (W,-H,1) to (x3,y3,1) and
(W,0,1) to (x4,y4,1).  This matrix *ought* to be given by:

( (x1-x2)/H  (x4-x1)/W  x1)
( (y1-y2)/H  (y4-y1)/W  y1)
( 0  0  1 )

I say 'ought' because if your camera has a non-parallel distortion, this
matrix may fail to correctly transform the fourth point to (x3,y3,1). If
that's true, there's no matrix that will work (all matrix transformations
are affine, meaning they transform parallel lines into parallel lines).

Once you have this matrix M, you can invert it to get M'(If you can't do
that, I can explain how) and apply M' to the corners of your image to get
your un-transformed rectangle.

Best
Danny

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] OT: Need math help

2006-07-14 Thread Duncan Reid

I'm not going to pretend to know what you guys are talking about, but you
may be able to garner some useful info from this Distort Image class...

http://sandy.media-box.net/blog/distortimage-20-the-fastest-way-to-freely-distort-image-with-flash-in-actionscript.html

dunc


On 7/13/06, Danny Kodicek [EMAIL PROTECTED] wrote:



 I wonder if someone would be willing to help me off-list with a math
 problem or can refer me to a more appropriate person/list to ask this
 question:

 I have a photograph of a rectangle where the camera was slightly
 off-center and not parallel to the plane of the rectangle, so in the
 resulting photo, the rectangle is slightly distorted. I want to distort
 the image by repositioning the corner points of the photograph so that
 the interior rectangle is precisely positioned and sized.

 1) I know the size of the photo,
 2) I know the coordinates of the rectangle's corners in the photo
 3) I know the coordinates where I want the rectangle's corners to be
 after the transformation.

 I need to know the new coordinates of the photo's corners to achieve #3.

I don't know if you got the offlist answer you asked for, but it's
probably
a question worth answering on-list too.

Basically what you need to do is to invert a transformation matrix. So you
need to start by constructing the matrix M used to transform the original
rectangle R = (0,-H,W,0) to the distorted rectangle: that is (using
homogeneous coordinates (the kind used in Flash's own Matrix object)), M
maps (0,0,1) to (x1,y1,1), (0,-H,1) to (x2,y2,1), (W,-H,1) to (x3,y3,1)
and
(W,0,1) to (x4,y4,1).  This matrix *ought* to be given by:

( (x1-x2)/H  (x4-x1)/W  x1)
( (y1-y2)/H  (y4-y1)/W  y1)
( 0  0  1 )

I say 'ought' because if your camera has a non-parallel distortion, this
matrix may fail to correctly transform the fourth point to (x3,y3,1). If
that's true, there's no matrix that will work (all matrix transformations
are affine, meaning they transform parallel lines into parallel lines).

Once you have this matrix M, you can invert it to get M'(If you can't do
that, I can explain how) and apply M' to the corners of your image to get
your un-transformed rectangle.

Best
Danny

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com