File Exchange

image thumbnail

2D - 2D Projective Homography (3x3) Estimation

version 1.3 (14.3 KB) by

This function estimates 2D-2D projective homography between two images.

40 Downloads

Updated

View License

This function estimates 2D-2D projective homography between two images using DLT, RANSAC and Lev-Mar optimisation.

The format for calling upon the function is as follows:

[h wim] = homography(im1, im2);

where

im1 -> 1st Image
im2 -> 2nd Image
h -> Returned homography matrix
wim -> Warped version of im1 w.r.t. im2

Comments and Ratings (19)

Aisha

Aisha (view profile)

getting this error: Error using FastHessian_getResponse (line 2)
Not enough input arguments.

Error in FastHessian_BuildDerivative (line 4)
ds = (FastHessian_getResponse(t,r, c) - FastHessian_getResponse(b,r, c, t)) / 2;

for ds, there are only 3 arguments passed which throws an error, plz can anyone tell me urgently what can be the possible 4th argument to run this code successfully?
Any help will be highly appreciated..

want to know

Can anyone please tell me if there any difference between the homest2d of this code and the Normalized NDLT (Hartley and Zisserman: Multiple View Geometry in Computer vision)?

want to know

Hi Mr SasiKanth
I am needed to find estimation for the homography 2D that can relate a big number of points (100, 250...)
And i found this code is very interesting, especially the function homest2D

But if you may I have some question about homest2D:
1) Why you are using approximately the same approach of Fundamental Matrix? and what this can help?
2) if we have 2 sets of points, is homest2D enough to calculate the homography?
3) did you do any experimentation with homest2D? or any comparison with other algorithm, like Normalized DLT (Hartley and Zisserman: Multiple View Geometry in Computer vision)?
Thank you in advance for any help, and if you may have any document that explain each step of the algorithm, i will be very thankful
Thank you again

Sean Lawson

@SasiKanth: thanks. The thing is that I think my images are affine-transformed rather than projective-transformed. I am working on Retinal OCT scans. Also, I used your build-in function to obtain the wim1 image, which is the transformed form of i1, but the registration with i2 doesn't look promising. I met the same situation when I tried SIFT algorithm. I guess it's because of the algorithm itself, if you by any chance have the similar experience, would you please offer me any knowledge? If not, thank you anyway, it's a great algorithm.

Sasikanth

Sasikanth (view profile)

@Hasheem: There is no specification to the king of image you need to use as feature matching takes place on gray images.

@Diogo: RandStream is a function in the newer versions of MATLAB. Why don't you replace it with the function that is present in the version you are using?

@Sean: You are referring to a function called 'imtransform' which transforms images based on a provided transformation matrix. Affine is only one case where as you said, the last column needs to be 0 0 1. however, you may even provide a full projective 3x3 matrix and pass the argument 'projective' to the function 'maketform'.

Sean Lawson

Hi, I wonder how to apply the homography matrix h to the actually i1 or i2 in order to register them. MATLAB provides affine transformation while it requires the h to have [0;...;0;1] in the last column, which is not the case here. Thank you very much -Sean

Diogo

Diogo (view profile)

I could not find the function RandStream. Please, could you provide it so that I can run your code?

Hashem Burki

I use gray-scale images as inputs. Is there any specification to what the inputs should be like?

Sasikanth

Sasikanth (view profile)

Hey Hashem,
That is the reason given by the MATLAB error minimization function for exiting the iterative algorithm. In case it is exiting in the very 1st loop itself, there is something wrong with the input you might be giving.

Hashem Burki

i used this code just to run it
im1=imread('i1.gif');
im2=imread('i2.gif');
[h wim] = homography(im1, im2);

I get this error:
lsqcurvefit stopped because the size of the current step is less than
the default value of the step size tolerance.

Sasikanth

Sasikanth (view profile)

Which version of MATLAB do you use?

blue ice

??? Undefined function or method 'RandStream' for input arguments of type 'char'.

Error in ==> homography>autohomest2d at 61
stream = RandStream('mt19937ar','seed',sum(100*clock));

getting this error??????????????????

blue ice

??? Undefined function or method 'RandStream' for input arguments of type 'char'.

Error in ==> homography>autohomest2d at 61
stream = RandStream('mt19937ar','seed',sum(100*clock));

getting this error??????????????????

Sasikanth

Sasikanth (view profile)

An updated version of the file has been submitted with the ~'s replaced. It should be up soon.

Sasikanth

Sasikanth (view profile)

Hey,

The '~' is a feature in MATLAB 2010 where you need not specify a variable when you do not need it. You can replace all such instances with any arbitrary variable (say 'tmpx') and the code will run. Be careful not to replace wrong instances of '~' (such as in '~isNaN').

Hope this helps.

Qiu

Qiu (view profile)

What a pity, I fail to run the code.

Qiu

Qiu (view profile)

Qiu

Qiu (view profile)

[width, height, ~] = size(im1);

I want to know the meaning and role of '~' in the above command, who can tell me, please!

Updates

1.3

Code containing instances of '~' replaced with arbitrary temporary variables for execution in older versions of MATLAB. Verbosity increased.

MATLAB Release
MATLAB 7.10 (R2010a)
Acknowledgements

Inspired by: OpenSURF (including Image Warp)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video