Homography Matrix

51 次查看(过去 30 天)
Tejas Kulkarni
Tejas Kulkarni 2012-1-15
编辑: Matt J 2022-4-26
Can somebody please help me in understanding how to calculate an homography matrix in matlab.
  1 个评论
Lalit Patil
Lalit Patil 2013-1-22
I am finding homography matrix in another way and it is 3*3
So, i want to know that in image where to apply or what to do of this homography matrix.?
Why we are finding this matrix..?

请先登录,再进行评论。

回答(2 个)

David Young
David Young 2012-1-15
You don't say what you are starting from. If you have a set of matched input and output points, one possible method is given here. A simple implementation is below.
function v = homography_solve(pin, pout)
% HOMOGRAPHY_SOLVE finds a homography from point pairs
% V = HOMOGRAPHY_SOLVE(PIN, POUT) takes a 2xN matrix of input vectors and
% a 2xN matrix of output vectors, and returns the homogeneous
% transformation matrix that maps the inputs to the outputs, to some
% approximation if there is noise.
%
% This uses the SVD method of
% http://www.robots.ox.ac.uk/%7Evgg/presentations/bmvc97/criminispaper/node3.html
% David Young, University of Sussex, February 2008
if ~isequal(size(pin), size(pout))
error('Points matrices different sizes');
end
if size(pin, 1) ~= 2
error('Points matrices must have two rows');
end
n = size(pin, 2);
if n < 4
error('Need at least 4 matching points');
end
% Solve equations using SVD
x = pout(1, :); y = pout(2,:); X = pin(1,:); Y = pin(2,:);
rows0 = zeros(3, n);
rowsXY = -[X; Y; ones(1,n)];
hx = [rowsXY; rows0; x.*X; x.*Y; x];
hy = [rows0; rowsXY; y.*X; y.*Y; y];
h = [hx hy];
if n == 4
[U, ~, ~] = svd(h);
else
[U, ~, ~] = svd(h, 'econ');
end
v = (reshape(U(:,9), 3, 3)).';
end
If your initial data is in some other form, such as camera position parameters relative to the plane, please say.
EDIT - added:
To apply the resulting matrix to a set of points, you can use the following function.
function y = homography_transform(x, v)
% HOMOGRAPHY_TRANSFORM applies homographic transform to vectors
% Y = HOMOGRAPHY_TRANSFORM(X, V) takes a 2xN matrix, each column of which
% gives the position of a point in a plane. It returns a 2xN matrix whose
% columns are the input vectors transformed according to the homography
% V, represented as a 3x3 homogeneous matrix.
q = v * [x; ones(1, size(x,2))];
p = q(3,:);
y = [q(1,:)./p; q(2,:)./p];
end
  13 个评论
Wei Han
Wei Han 2022-3-25
编辑:Wei Han 2022-3-25
Hi, I just want to thank for your code, it's really helped me!
Sahana Srivathsa
Sahana Srivathsa 2022-4-25
This is very helpful. I think equation for q needs to be slightly altered.
q = v * [x; y; ones(1, size(x,2))];

请先登录,再进行评论。


Matt J
Matt J 2022-4-25
编辑:Matt J 2022-4-25
  1 个评论
Matt J
Matt J 2022-4-26
编辑:Matt J 2022-4-26
You shouldn't be extracting the matrix. You should be using tform.transformPointsForward().

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Sparse Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by