Homography Matrix
이전 댓글 표시
Can somebody please help me in understanding how to calculate an homography matrix in matlab.
댓글 수: 1
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
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
Sean Lawson
2012년 3월 27일
Hi
I have a question regarding the final transform matrix v.
I want to apply the homography(projective transform) in Matlab, I use this approach to calculate the matrix v. However, v(3,3) ~= 1, whereas Matlab requires v(3,3) = 1, do you know how to fix this? Or just v/v(3,3) works?
David Young
2012년 3월 30일
Hi Sean, I'm adding a function to my answer with I hope deals with this question.
Royi Avital
2012년 7월 30일
What if you want to impose Affine Matrix (Last row to be [0, 0, 1])?
Jason Rebello
2012년 9월 23일
Hi, First of all thanks for the code it really helped. But can you explain to me why exactly are u reshaping only the last column. Im new to matlab so I dont really pick up on things fast. v = (reshape(U(:,9), 3, 3)).'; ?? Thanks, Jason
Erez Farhan
2013년 6월 14일
Hi, David- thanks for your post. Please note: I believe your solution doesn't account for normalization of the homography matrix- which can be done by dividing it by it's second singular value.
pankhuri
2013년 6월 19일
can this be applied for 2D to 3D projection??
sushanth kalva
2016년 5월 9일
i want to know the difference between transformation matrix and homography matrix
Tianya Zhang
2017년 11월 28일
편집: Tianya Zhang
2017년 11월 28일
svd() function returns U, S and V. h can be obtained from the last colum of V. Why you use U to get h in your code? That's confusing.... Is that an obvious mistake?
Edwin Stanley
2018년 3월 8일
Also curious about Tianya's comment above!
"svd() function returns U, S and V. h can be obtained from the last colum of V. Why you use U to get h in your code? That's confusing.... Is that an obvious mistake?"
Albert Dayn
2019년 2월 13일
In response to Tianya and Edwin's question, U is correct. It looks like in this function, h is constructed as the transpose of the usual matrix (each point is represented by 2 columns here, instead of 2 rows). If it were constructed as the link (for the SVD method) specifies, you would indeed use the last column of V.
PENIEL EMANUEL
2020년 12월 1일
how to get target physical coordinates in millimetres
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))];
Ue fitgeotrans().
댓글 수: 1
카테고리
도움말 센터 및 File Exchange에서 Sparse Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!