apply homography matrix to a set of points in matlab

I have calculated homography matrix using these set of points

trapezium points are

x=[ 102,48; 206,48; 257,143; 53,118]

square points(projected points) are y=[0,0; 335,0; 335,178; 0,178]

Homography matrix

H=
-0.0000   -0.0173   -0.0001
0.0000    0.0382    0.0001
-0.0000   -0.9990    0.0126

Now , I want to apply H to x to get projected points (y)

How can I calculate that in matlab ?

• answered 2019-09-21 19:49

This is the usual way of doing this:

x = [ 102,48; 206,48; 257,143; 53,118];
y = [0,0; 335,0; 335,178; 0,178];
H = [-0.0000   -0.0173   -0.0001;
0.0000    0.0382    0.0001;
-0.0000   -0.9990    0.0126];

x = [x ones(4,1)]; % make your coords homogenous
y = [y ones(4,1)];

x_projected = H*x';
x_projected = x_projected./repmat(x_projected(3,:),3,1); % normalize

x_projected is 3x4 in this case and every column is one of the projected points.

To check the projection vs. your y: euclidean distance of columns of y'-x_projected should be small depending on your H.