I am using RANSAC algorithm for homography estimation between pairs of images taken with cameras which do not have any translation between them (pure rotation and change of scale/zoom). It works well in half of the cases. The correct output looks like this:

enter image description here

The red lines are filtered correspondences and the quadrilaterals illustrate how the homography distorts perspective.

Sometimes, however, many bad cases happen, like these:

enter image description here

enter image description here

enter image description here

I already have a simple test in the RANSAC loop. It makes a simple quadrilateral (a unit square) and transforms it with sample transform. Then it looks whether the transform kept its convexity.

Still, however, bunches of concave quadrilaterals come out.

Do you have any idea how to properly test the homography, if it behaves "nicely" and filter out the incorrect solutions?

I found some code where they test that none of the three transformed points are colinear. But this does not seem sufficient as it will not filter out deltoids and other "invalid" quadrilaterals...


There is an interesting paper on this topic: http://link.springer.com/chapter/10.1007%2F978-3-642-17691-3_19#

The paper describes a method to filter out some wrong correspondences before computing homographies in the RANSAC algorithm.


There is a problem in checking whether the homography is OK.

The algorithm for checking correct homographies may interest someone, so I will write it down here:

1) Create a quadrilateral $ABDC$ with vertex coordinates (in homogenous coordinates):

$$\begin{eqnarray} A:& (-w/2,-h/2, 1.0) \\ B:& (w/2,-h/2, 1.0) \\ C:& (-w/2,h/2, 1.0) \\ D: &(w/2,h/2, 1.0) \end{eqnarray}$$

where $w,h$ are width and height of the image, respectively. If the whole image frame (a rectangle) is transformed to convex quadrilateral, than any convex quadrilateral within it will also be transformed "neatly".

2) Create transformed quadrilateral $A'B'D'C'$ in which every vertex is transformed using the computed homgraphy (e.g. $C'=HC$ ). From now on, all points will be converted to non-homogenous coordinates.

3) Compute vectors $\vec{u}$, $\vec{v}$ for parametric representation of diagonals:

$$\begin{eqnarray}d_{1} :& A+(D-A)s =A+ \vec{u}s \\ d_{2} :& B + (C-B)t=B+\vec{v}t \end{eqnarray}$$

The intersection of diagonal comes from $d_{1}=d_{2}$:

$$t=\frac{1}{d}\left[(B_{y}-A_{y})\vec{u}_{x} - (B_{x}-A_{x})\vec{u}_{y}\right]$$

$$s=\frac{1}{d}\left[(A_{x}-B_{x})\vec{v}_{y} - (A_{y}-B_{y})\vec{v}_{x}\right]$$

Then the convex quadrilateral satisfies $s,t \in (0,1)$.

In practice, one can introduce a fudge factor to avoid not only non-convex and degenerate quadrilaterals, but also near-degenerate ones, like when three points are near colinear. So the test can be modified such that $s,t \in (\lambda, 1.0-\lambda)$, where lambda is a small number (e.g. $\lambda=0.01$).

Older problem, fixed in the above algorith:

I found the problem here - having a certain homography, the test can pass for a smaller quadrilateral, but not for the larger one. This is why some "ill" homographies passed through.

The green square represents a source image, the orange is a transformed one. As you can see, the left hand one is convex, but starts deforming as the source is larger:

enter image description here

Finally even larger source yield non conver quadrilateral:

enter image description here

I made a mistake with scaling. The points in homogenous coordinates $(x,y,w)$ were scaled in $x$ and $y$ direction, but in $w$. This is why the same transform produced different quadrilaterals.

I have corrected the algorithm accordingly.


If you have estimated the homography as $x_i \sim Hx_i^'$ and you calculate the model error as $\sum_{j=1\dots n}\|x_j - Hx_j^'\|$ you may face problems when the estimated planes are almost perpendicular. You can increase the robustness by estimating another homography $H^'$ such that $x^' = H^'x$ and calculating the model error as $\sum_{j=1\dots n}\|x_j - Hx_j^'\| + \|x_j^' - H^'x\|$.

See Hartley and Zisserman - Multiple View Geometry on Computer Vision chapter 4.2 and especially 4.2.3 and equation (4.8).

  • $\begingroup$ The quadrilaterals displayed are just put in there. I am sure about the correspondences as the fit is very good. I have used normalized DLT algorithm suggested by Hartley & Zisserman and then used iterative refinement and guided matching as you mentioned. $\endgroup$ – Libor Apr 10 '12 at 16:59
  • $\begingroup$ But the fit of the homography can not be that good as in the first picture there is two groups of points: ones at the apartment building (which are probably on a same plane) and the ones on the trees (which probably are not even on a same plane inside their own group). Are you sure you did not mean to use fundamental matrix? $\endgroup$ – buq2 Apr 10 '12 at 17:10
  • $\begingroup$ The lines connect corresponding points and I checked them all - when the images are aligned, they all meet. When I exclude the bad matching image pairs, it results in a nice panorama. $\endgroup$ – Libor Apr 10 '12 at 17:17
  • $\begingroup$ The images are made using a rotating camera, so it may seem that the planes change, but since the cameras rotate about optical centre, I am pretty sure the a homography is estimated. I can even compute focal length and rotation matrix from it. But the problem is somewhere else, a quirk in my software I have to find... $\endgroup$ – Libor Apr 10 '12 at 17:21
  • $\begingroup$ Ahh, you did not include the information that there is no translation between the cameras. Then you are right and homography describes the transformation between the images. $\endgroup$ – buq2 Apr 10 '12 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.