1

I am stuck at this homography problem. I have to apply homography and then 2d bilinear interpolation to render a image so that I see a birds eye view.

I successfully computed the homography(I guess). I am unable to figure out how to apply this homography matrix to the source image to generate output image over blank 940x500 image.

Here is my code so far:

I = imread('image.png');
imshow(I)

% Mark more than 4 input points
[x,y] = getpts

xp = [0; 720; 720; 0;];
yp = [0; 0; 1280; 1280;];

for i=1:4
    A(2*i-1,:) = [x(i), y(i), 1, 0, 0, 0, -x(i)*xp(i), -xp(i)*y(i), -xp(i)];
    A(2*i,:) = [0, 0, 0, x(i), y(i), 1, -x(i)*yp(i), -yp(i)*y(i), -yp(i)];
end

[U,S,V] = svd(A);
h = V(:,9);

H = reshape(h,3,3);

How do I apply this H matrix to the source image?

Abhigyan Singh
  • 137
  • 3
  • 14

1 Answers1

1

You can use projective2d and imwarp:

tform = projective2d(H);
outputImage = imwarp(I, tform);

I don't understand the example you gave, so I can't say if you need to invert H.

It could be that my answer is wrong - I can't execute your code sample for verifying the solution.

Please let me know if it solves your problem.

Rotem
  • 30,366
  • 4
  • 32
  • 65
  • 1
    You may use my older answers about image rotation without builtin function: [bilinear interpolation](https://stackoverflow.com/questions/40245959/matlab-image-rotation/40248435#40248435), [bicubic interpolation](https://stackoverflow.com/questions/40334341/rotate-an-image-with-bicubic-interpolation-without-imrotate). Remember to convert form homogeneous coordinates to euclidean coordinates. – Rotem Feb 16 '20 at 23:15