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

### Perspective transform

• Email
• Follow

```Hi!
Im trying to program a method for perspective transformation using this piece of theory: http://alumni.media.mit.edu/~cwren/interpolator/

The problem is I get strange indexes when computing the mapping. Im doing a inverse of the " non-vector form" stated in the article..
Any help is appreciated! Maybe im trying to reinvent something that already exists?
Anders

function squareIm = perspectiveTrans(im,points)
% X,Y: samples from old corners
X = points(:,1);
Y = points(:,2);

% x,y: New Corner coordinates
x = [1 size(im,1) size(im,1) 1]';
y = [1 1 size(im,2) size(im,2)]';

% A matrix
A = [x(1) y(1) 1 0 0 0 (-X(1)*x(1)) (-X(1)*y(1));
0 0 0 x(1) y(1) 1 (-Y(1)*x(1)) (-Y(1)*y(1));

x(2) y(2) 1 0 0 0 (-X(2)*x(2)) (-X(2)*y(2));
0 0 0 x(2) y(2) 1 (-Y(2)*x(2)) (-Y(2)*y(2));

x(3) y(3) 1 0 0 0 (-X(3)*x(3)) (-X(3)*y(3));
0 0 0 x(3) y(3) 1 (-Y(3)*x(3)) (-Y(3)*y(3));

x(4) y(4) 1 0 0 0 (-X(4)*x(4)) (-X(4)*y(4));
0 0 0 x(4) y(4) 1 (-Y(4)*x(4)) (-Y(4)*y(4))];

% B matrix
for i=1:4
B(i*2-1,1) = X(i);
B(i*2,1) = Y(i);
end

% get parameters
unknowns = A\B;
a = unknowns(1); b = unknowns(2); c = unknowns(3); d = unknowns(4);
e = unknowns(5); f = unknowns(6); g = unknowns(7); h = unknowns(8);

% For each pixel in the new image, find what pixel in old it maps to.
for row=1:size(im,1)
for col=1:size(im,2)
oldR = ( (e-f*h)* row - (b-c*h)* col + (b*f-e*c) ) / ( (a*e - b*d) - (e*g - d*h)* row - (a*h - g*b)* col ); %"inverse of the projection formula";
oldC = ( -(d-f*g)* row + (a-c*g)* col - (a*f-c*d) ) / ( (a*e - b*d) - (e*g - d*h)* row - (a*h - g*b)* col ); %"inverse of the projection formula";
squareIm(row,col) = im(round(oldR),round(oldC));
end
end
```
 0

See related articles to this posting

```These are my opinions: The central point of the content available in the link that you sent was:

If I give you n points in one plane and give their mapped views in another plane, is there a transform matrix (which the author calls the perspective projection because of the geometrical approach he takes). The key question is: how many such points do you need to find the 9 values of the matrix. Also, the fact that these n points lying on a plane gives you additional equations (nice!). It is the classic question of solving m equations in n variables. If the number of independent equations be less than the number being solved for, you are lost. The pseudo inverse method that is being used is the solution of the minimization of the cost function of the squares of the errors.

You should simply use the formula he has used in the article under the section for "The Solution". Get the matrix dimension right. Some ideas:

http://www.mathworks.com/help/techdoc/ref/pinv.html

The more interesting problem would have been if the planes were curved surfaces.
```
 0

```"Anders " <lm06aj6@student.lth.se> wrote in message <i9cppt\$im1\$1@fred.mathworks.com>...
> Hi!
> Im trying to program a method for perspective transformation using this piece of theory: http://alumni.media.mit.edu/~cwren/interpolator/

Anders,

You might find additional resources if you search under the more standard term "projective transformation." Perspective typically involves mapping 3D to 2D, but you are mapping 2D to 2D.

Also, the Image Processing Toolbox function cp2tform solves this very problem. (From your variable names, it looks as if your application might involve imagery.) Here's one place to get started:

http://www.mathworks.com/help/toolbox/images/f12-26140.html

Hope this helps,

Rob Comer
Mapping Toolbox Development
MathWorks
```
 0

`freelance writer`
 0

`freelance writer`
 0

`freelance writer`
 0

8 Replies
1079 Views

Similar Articles

12/6/2013 1:48:04 PM
page loaded in 25411 ms. (0)

Similar Artilces:

Transform a matrix
I've a matrix with values between 0.0 and 1.0 I must transform it so that the new values will be comprised between 0.0 and 255.0. Could anyone give me a suggestion? Best regards "elisa " <elisacarli@katamail.com> wrote in message <gkehol\$ep1\$1@fred.mathworks.com>... > I've a matrix with values between 0.0 and 1.0 > I must transform it so that the new values will be comprised between 0.0 and 255.0. > > Could anyone give me a suggestion? > > Best regards How about multiplying your matrix by 255? 255*0 = 0 255*1 = 255 elisa wrote: > I've a matrix with values between 0.0 and 1.0 > I must transform it so that the new values will be comprised between 0.0 and 255.0. Are the values strictly *between* 0.0 and 1.0 -- that is, are 0.0 and 1.0 themselves excluded? And in the output, are 0.0 and 255.0 to be excluded? And do the new values need to be integral, or would (for example) 254.3432432 be a possible output value? -- ..signature note: I am now avoiding replying to unclear or ambiguous postings. Please review questions before posting them. Be specific. Use examples of what you mean, of what you don't mean. Specify

mellin fourier transform......
hi, IS it possible to compute mellin fourier transform directly using matlab(is there any built in function for this?). I want to know about the log polar mapping . Any idea of how can it realized using MATLAB? As i m new to this ,I need some ideas regarding this. waiting for someones help, regds, rukmani.

PEAR Image_Transform
Can anyone help me write a code using this class to scale JPEG pictures? I have n o idea how to write a function that would look like this: function scale(\$picture, \$name, \$size) where: \$picture is the base JPEG file \$path is the the name of the new file \$size is the new size of the longer length f.e. scale("pic.jpeg", "pic_new.jpeg", 300) [the pic.jpeg is f.e. 600x300) i will get a new pic called pic_new.jpeg with dimiensions 300x150 Can anyone help me with that? There are so little examples on PEAR site..If you prefer using GD itself, that is fine. Whatever will

Transform DOM to TableModel
I'm writing an application which will invoke a servlet (via a UrlConnection) and display the (CML) data returned by the servlet in a JTable. (The data returned by this servlet is in row/column format, so in this application a JTable is the appropriate control for displaying the data.) Can someone give me advice on the best approach for converting a DOM to a TableModel: -- Write a Transformer that takes a Document as a source and uses a TableModel as a sink? -- Use XSLT? -- Use SAX instead of DOM (I'm not married to DOM) and build the TableModel as thx SAX parser parses it?

implementing Schwartzian Transform
I believe that Schwartzian Transform will do what I need if I ever understand it. I am trying to sort an array and ignore non alphanumeric characters. Actual data being sorted is many regexes containing all of the usual; regex characters ( )[ ]/ \ \$ " ' . etc and these are what I need to ignore during sort I got this routine from a web site and now have misplaced the link to it but I double checked it as I copied & pasted it and did not key it. The @list data is something I added. I get an error message: error Schwartzian_Transform.pl line 15, near "/ }" #!/usr/bin/perl use warnings; use strict; @list = ( '*=ziggy', '<>Zaggy','animal', ']min&imal' , '-!animal]', '%#Anardvark'); @dictionary_order_list = map { /^\w* (.*)// } # line 15 sort map { my \$d = lc; # convert to lower case \$d =~ s/[\W_]+//g; # remove non-alphanumerics "\$d \$_" # [original, transform] } @list; Thanks jbl On Nov 18, 8:55 am, jbl <jbl0...@SPAMhotmail.com> wrote: > I believe that Schwartzian Transform will do what I need if I ever >

Transform hash key?
either sub, the hash will have only upper case keys. now i doubt that uc will be faster or slower given any mix of input case but it still is wrong. if the transform were something whose speed was data dependent, this benchmark would be very bogus. the map one could be fixed just by assigning it to a different hash. the for one would need a fresh hash each time as it modifies it in place. so you would need to do the same work for each one and my best idea would be to copy the %h to %h2 inside each sub and use that as the input (and you can use it for the output of the map. also choosing... keys. now i doubt that uc will be faster or slower > given any mix of input case Which is why I decided not worry about it (in this case). > but it still is wrong. I am not sure it is that wrong. > if the transform were something whose speed was data dependent, > this benchmark would be very bogus. Absolutely. > the map one could be fixed just by assigning it to a different hash. > the for one would need a fresh hash each time as it modifies it in > place. so you would need to do the same work for each one and my best > idea would be to copy the %h to %h2 inside

Transform a Square Image to Circular
Hi, I'd like to transform a square image and warp it so that it's circular. I know there's a imtransform function in matlab but I have a hard time understanding how it works. Would someone care to give sample code to do this? Also, can this be extend to 3D (i.e. cube to sphere)? Thank you, Mike Mike: <SNIP wants to put his/her friends face onto a sphere... > I'd like to transform a square image and warp it so that it's circular... there are many solutions % 1) a simple texture warp img=load('clown'); figure; [x,y,z]=sphere(128); sh...;, Mike <leunm@hotmail.com> wrote: > Hi, > > I'd like to transform a square image and warp it so that it's > circular. I know there's a imtransform function in matlab but I have > a hard time understanding how it works. Would someone care to give > sample code to do this? > > Also, can this be extend to 3D (i.e. cube to sphere)? > > Thank you, > Mike ------------------------ You haven't placed any restriction on the transform function, Mike, and that leaves a great many possibilities. If you want a mapping that carries equal areas

Laplace transform and Syms
I have a homework assignment due using MATLAB (which I have never used before). I have been thus far able to use the help menu to complete the assignments. I have one final problem that I am unable to complete. It is a problem that is to use Laplace transforms and syms to complete. The problem is y(t) = 1 + 4(e^(-2t))cos(3t). Please help me with the syntax necessary to complete this problem. Cristin Williams wrote: > I have a homework assignment due using MATLAB (which I have never > used before). I have been thus far able to use the help menu to > complete the assignments. > &

How to convert/transform txt to DB
how can I get this type date into Access: Where the Contact_xxxxx is the field name and the other text the data Contact_FullName Martha Fuentes Contact_StreetAddress 185 S. Oleander Contact_Address2 Contact_City Fellsmere Contact_State FL Contact_ZipCode 32948 Contact_WorkPhone Contact_HomePhone 934-5723-Cathy Contact_Email Contact_Work: Contact_FullName Glenda Fuentes Contact_StreetAddress 250 S. Magnolia St. Contact_Address2 Contact_City Fellsmere Contact_State FL Contact_ZipCode 32948 Contact_WorkPhone Contact_HomePhone (7720 571-9999 Contact_Email Contact_Work: I would appreciate a lap-

Details on Weighted Frequency Count transform