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
|
|
|
|
Reply
|
Anders
|
10/16/2010 6:10:05 PM |
|
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
|
|
|
|
Reply
|
Saurabh
|
10/21/2010 7:59:04 PM
|
|
"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
|
|
|
|
Reply
|
Rob
|
10/22/2010 12:16:03 AM
|
|
freelance writer
|
|
0
|
|
|
|
Reply
|
EUGENIAODOM26
|
5/13/2011 9:22:12 PM
|
|
freelance writer
|
|
0
|
|
|
|
Reply
|
ClaudineSchwartz29
|
5/13/2011 9:44:44 PM
|
|
freelance writer
|
|
0
|
|
|
|
Reply
|
Miranda22Ollie
|
5/14/2011 4:04:12 AM
|
|
|
8 Replies
824 Views
(page loaded in 0.476 seconds)
Similiar Articles: Perspective transform - comp.soft-sys.matlabHi! Im trying to program a method for perspective transformation using this piece of theory: http://alumni.media.mit.edu/~cwren/interpolator/ The ... z-transform on pixel data - comp.soft-sys.matlab2D interpolation - comp.soft-sys.matlab I have 2D data acquired at 0.5 cm intervals in both x ... newbie to 2D interpolation and ... Perspective transform ... Drawing bitmap with glOrtho at a specific depth - comp.graphics ...> > You have (c being clip space coordidates, v eye space coordinates, M the > matrices): > > perspective transform: c1 = M1 * v1 > othro transform c2 = M2 * v2 > you ... Fisheye - comp.graphics.api.openglI think, as OGL only supports perspective and orthographic project... ... ModelViewProjectionMatrix * gl_Vertex; } You can replace this by any transformation ... how to calculate WARPING MATRIX from HOMOGRAPHY MATRIX - comp.soft ...Perspective transform - comp.soft-sys.matlab The key question is: how many such points do you need to find the 9 values of the matrix. ... lighting; Texture mapping ... ROW COL, HOW DO I OPERATE THEM?? (HP49G) - comp.sys.hp48 ...Perspective transform - comp.soft-sys.matlab for row=1:size(im,1) for col=1:size(im,2) oldR = ( (e-f*h)* row - (b-c*h)* col + (b ... How do I convert them to a 2d in... ... glOrtho/gluPerspective/glFrustum ? - comp.graphics.api.opengl ...With a perspective projection, eye > position is important. If you're not specifying a camera transform > (modelview matrix is identity), then your eye is effectively ... image mosaic - comp.soft-sys.matlab... http://cvlab.epfl.ch/~brown/autostitch/autostitch.html From a Matlab perspective ... going to make measurements on the images that will allow you to compute a transform ... Why are lights moving? - comp.graphics.api.openglBut alas, with this change of perspective, the light source moved too, and it moves ... will display a frame with the following pseudocode: Set the view transform. 3d to 2d projection - comp.graphics.api.opengl... would be > projected on screen according > to the current Modelview and Perspective ... subplot (1,2,2) from subplot(1,2,1) of the code below. Is there a set transformation ... 3D projection - Wikipedia, the free encyclopediaGraphics card; Transform and lighting; Texture mapping; Perspective (graphical) Camera matrix; Homography; Homogeneous coordinates; References Perspective Transform Estimation - MIT Media LaboratoryPerspective Transform Estimation. This page is intended as a companion to the online paper A Plane Measuring Device by A. Criminisi, I. Reid, and A. Zisserman at the ... 7/23/2012 11:29:25 AM
|