Correct homograph or projective transformation of an inclined image

34 views (last 30 days)
I have some inclined(with respect to camera angle) images that need to be made perpendicular to the camera direction. This could be done probably with homograph or projective transformation as I searched about it.
At first I am cropping the center of the image where the circle is which I am going to use as landmark. Then I pad the RGB image with a white border to visualize the transform.
I_crop_pad = padarray(I_crop, [2, 2], 255);
theta = -30;
pform = projective2d([cosd(theta) -sind(theta) -.0003;
sind(theta) cosd(theta) 0;
0 0 1
]);
outputImage = imwarp(I_crop_pad,pform);
figure,
subplot(121);imshow(I_crop_pad);
subplot(122);imshow(outputImage);
disp([size(I_crop), size(outputImage)])
If the image were taken perpendicularly, then line 1 and line 2 would be equal. and line 1 will be horizontal.
How do I achieve that?
  3 Comments
banikr
banikr on 2 Aug 2023

You seem to assume that lines 1 and 2 have been drawn diametrically, passing through the center of the circle.

Yes.

If you look closely there are some gaps in the circle on the far end side of line 1. Moreover, the lines are approximation. They should be equal to prove the concept of corrected homography of the image.

Matt J
Matt J on 2 Aug 2023
Edited: Matt J on 2 Aug 2023
They should be equal to prove the concept of corrected homography of the image.
But that is not enough information to determine a unique homography. The white region in the uncorrected image is an ellipse and you are saying that all you want is a homography that transforms this ellipse into a circle. There are infinitely many such homographies. If C is the 3x3 conic matrix representing the ellipse, then the transformation equation is,
H'*C*H=diag([1,1,-R])
where R is the radius of the circle and H is the unknown 3x3 homography matrix. Because the left and right hand sides are both symmetric matrices, this gives you 6 equations in 9 unknowns.

Sign in to comment.

Answers (1)

Matt J
Matt J on 1 Aug 2023
Edited: Matt J on 1 Aug 2023
You need 4 non-colinear landmarks in the image, for which you know the real-world coordinates. Then you can use fitgeotrans or fitgeotform2d.
  4 Comments
banikr
banikr on 2 Aug 2023
Thanks for your suggestion.
I used the following codes:
fixedPoints = [303 832; 906 410; 426 85;864 976];
movingPoints = [0 500; 1000 500; 500 0; 500 1000]; % make each diameter of the circular
% structure as 1000
tform = fitgeotform2d(fixedPoints,movingPoints,"projective");
Jregistered = imwarp(I_crop_pad,tform);
figure;
subplot(121);imshow(I_crop_pad)
subplot(122);imshow(Jregistered)
this gives the following result. With euclidean distances of the points in line1 is ~1009 and line2 ~994, which are pretty close considering handpicked points.
Would you call it a good homography correction?
One other thing I am not sure, I chose the moving points as such there shouldn't be any pixel beyond the circle. See the 0 x and y coordinates in the movingPoints. Still I am getting pixels projected beyond line1 and line2 points.. something like the image below:
Matt J
Matt J on 2 Aug 2023
Would you call it a good homography correction?
I suppose, considering as you say that the points are hand picked. Using more landmarks might improve it, if you've anyway to obtain those.
One other thing I am not sure, I chose the moving points as such there shouldn't be any pixel beyond the circle.
You could use imwarp's OutputView option.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!