## How to estimate the homography matrix

Moderator: Computer Vision

Notschko
Windoof-User
Beiträge: 40
Registriert: 27. Nov 2005 18:00
Wohnort: Frankfurt
Kontaktdaten:

### How to estimate the homography matrix

Hello,

I'm trying to estimate the homography-matrix by using the formulas in lecture 10, slide 20 and 21 but it doesn't work for me and by applying the homography-matrix H to an image, I'm getting the picture you see below.

What I did so far:

1) Estimating four correspondences and I checked them several times.
For the left image (p1) and the right image (p2) I have these points, where the 1.row contains the x- and the 2.row the y-values

Code: Alles auswählen

p1=[
369   385   361   248
204   201   220   251
]

p2=[
171   185   163    47
202   199   217   248
]

2) Using the formulas on slide 21 for scaling and shifting the points. I received

Code: Alles auswählen

(p1) u=[
0.1301    0.2038    0.0933   -0.4271
-0.0691   -0.0829    0.0046    0.1474
]

(p2) u_=[
0.2171    0.3202    0.1583   -0.6956
-0.1067   -0.1288    0.0037    0.2319
]
3) Creating A-Matrix for SVD, I'm using the formula on slide 20 and receive

Code: Alles auswählen

A=[
0         0         0    0.1301   -0.0691    1.0000    0.0139   -0.0074    0.1067
-0.1301    0.0691   -1.0000         0         0         0    0.0282   -0.0150    0.2171
0         0         0    0.2038   -0.0829    1.0000    0.0262   -0.0107    0.1288
-0.2038    0.0829   -1.0000         0         0         0    0.0652   -0.0265    0.3202
0         0         0    0.0933    0.0046    1.0000   -0.0003   -0.0000   -0.0037
-0.0933   -0.0046   -1.0000         0         0         0    0.0148    0.0007    0.1583
0         0         0   -0.4271    0.1474    1.0000    0.0990   -0.0342   -0.2319
0.4271   -0.1474   -1.0000         0         0         0    0.2971   -0.1025   -0.6956
]
4) Denormalize as on slide 21 returns

Code: Alles auswählen

H=[
0.1174    0.0060  -56.7479
-0.1017    0.1684  -87.4186
0.0000   -0.0000    0.1514
]
I already tried a lot of things that didn't help to solve the problem and I have no clue what to try next. Do you have any idea what I can try next?

Thanks a lot!!!
Notschko
Dateianhänge
Image after applying homography-matrix H
problem3.jpg (25.24 KiB) 1662 mal betrachtet

lustiz
Mausschubser
Beiträge: 70
Registriert: 29. Apr 2009 10:28

### Re: How to estimate the homography matrix

Hi! I think your problem is the following:

In the RANSAC step you should definitely discard certain samples that are too close to singularity because they just ill-posed samples.
You can see that by subtracting your points from each other:

Code: Alles auswählen

p1=[
369   385   361   248
204   201   220   251
];

p2=[
171   185   163    47
202   199   217   248
];

p1 - p2
ans =
198   200   198   201
2     2     3     3

Note how close the vectors are to each other! There is not enough information to build a proper homography out of this sample because these vectors are almost linearly dependent.
For this reason: Check the condition of your outcoming homography (before transformation). Then you discard every sample that results in a homography that has really bad condition. By doing that you get rid of samples that are ill-posed.

Cheerso
Zuletzt geändert von lustiz am 15. Jul 2013 16:35, insgesamt 2-mal geändert.

Notschko
Windoof-User
Beiträge: 40
Registriert: 27. Nov 2005 18:00
Wohnort: Frankfurt
Kontaktdaten:

### Re: How to estimate the homography matrix

Thank you very much!!! This clue helped a lot.

hymGo
Sonntagsinformatiker
Beiträge: 209
Registriert: 4. Okt 2009 23:17

### Re: How to estimate the homography matrix

Hi,

my homography estimation is not very stable. Sometimes the resuling image looks very good, sometimes its really messed up. I follow the tipps from here viewtopic.php?f=290&t=28472 (threshold for chi square + use only the remaining pairs for ransac).
Now I included the rank check as well. I don't take samples with rank < 3. However, if tH has rank 3 it can occur that the uncodinitioned matrix H has rank<3. So I require that both matrices have rank 3. But, as said, the process it not very stable at all

Are there any other tipps to achieve more stability?

lustiz
Mausschubser
Beiträge: 70
Registriert: 29. Apr 2009 10:28

### Re: How to estimate the homography matrix

hymGo hat geschrieben: I don't take samples with rank < 3. However, if tH has rank 3 it can occur that the uncodinitioned matrix H has rank<3. So I require that both matrices have rank 3.
Just check the condition number of the untransformed homography (in the conditioned space if you want). I guess homographies often result in pretty bad conditions, but just make sure that it is not too bad (numerics etc) RANSAC then should be good enough to distinguish good from bad homographies.