Homography and Affine Transformation
Asked Answered
I

2

23

Hi i am a beginner in computer vision and i wish to know what exactly is the difference between a homography and affine tranformation, if you want to find the translation between two images which one would you use and why?. From papers and definitions I found online, I am yet to find the difference between them and where one is used instead of the other.

Thanks for your help.

Icono answered 3/3, 2017 at 14:21 Comment(6)
I'm assuming you're referring to what the individual components of a 3x3 homography matrix are: #12070911, but if you're just after translation then this is just the first two row values in the last column which represent x and y translation respectively, an affine transformation keeps straight lines parallel, see docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/warp_affine/…Earthen
no i understand that but why would you use findhomography instead of let's say getAffineTransform to find the x and y translation?Icono
so you don't get a perspective transformation with affine transformation but you do with full homography: en.wikipedia.org/wiki/…. You don't need a full homography or even affine to find translation, you can use camshift if you want translation and scale. You want a full homography for perspective warping calculation or camera calibration perhaps. You've not explained what your actual aim isEarthen
i am getting the initial frame where x and y 0,0 then any offset i calculate it using findHomography so x will be 5 and y 2 for example...I think perspective will change in this situation as the camera will be attached to a drone which will try to correct itself into initial positon based on those inputs but im still not sure if i should use findhomography i am also using findhomography to perform ransac for better accuracy.Icono
I'm not sure this is a programming question now, you may wish to post on opencv forum or on a different SO site as what you're talking about is too complex to answer in a simple Q+A site hereEarthen
not really i have done the programming but would like to know what is the difference between affine and homography transformation also would like to know if by homography you get perspective of x and yIcono
G
20

I have set it down in the terms of a layman.

Homography

A homography, is a matrix that maps a given set of points in one image to the corresponding set of points in another image.

The homography is a 3x3 matrix that maps each point of the first image to the corresponding point of the second image. See below where H is the homography matrix being computed for point x1, y1 and x2, y2

enter image description here

Consider the points of the images present below:

enter image description here

enter image description here

In the case above, there are 4 homography matrices generated.

Where is it used?

  1. You may want to align the above depicted images. You can do so by using the homography.

enter image description here

Here the second image is mapped with respect to the first

  1. Another application is Panoramic Stitching

Visit THIS BLOG for more

Affine transformation

An affine transform generates a matrix to transform the image with respect to the entire image. It does not consider certain points as in the case of homography.

Hence in affine transformation the parallelism of lines is always preserved (as mentioned by EdChum ).

Where is it used?

It is used in areas where you want to alter the entire image:

  • Rotation (self understood)
  • Translation (shifting the entire image by a certain length either to top/bottom or left/right)
  • Scaling (it is basically shrinking or blowing up an image)

See THIS PAGE for more

Grits answered 3/3, 2017 at 19:8 Comment(4)
So just to be clear, you need a unique homography for each point? I don't know the theory behind it, but for datasets I've seen, there is only one homography per transformed image. Not a separate homography for each pixel.Guessrope
To further clarify, is it that homography is a technique to relate pixel locations between two images, and if the transformations are affine transformations, that is, they are planar transformations, then a single homography can be used. If the scenes are not planar, then homographies for sure cannot be used. That is my understanding. Can you please confirm this? In what type of situations do you need more than one homography?Guessrope
Indeed I think OP has some typos. First, yes I think he meant to say that in the example, a single homography matrix can be generated from the 4 points (except for degenerate cases, this is always true, up to an irrelevant scale factor). Second, I think the equation given needs a scaling factor so that the homogeneous coordinates have a properly normalized 1 in the last row. All planar affine transformations can be expressed as a homography with last row [0 0 1] in which case the scale factor is not needed (since the bottom row will always be 1).Phocis
And indeed homographies can perfectly map a 3d plane in one image to a 3d plane in another, but if there are non-planar parts of the scene then they will be distorted if you apply the homography to the entire image. You might use multiple homographies if you're trying to match multiple planes, for example if you have a photo with 4 books strewn about, you might use 4 separate homographies to get an un-distorted picture of each book cover. Or if you have an open book, you might use 2 homographies: one for the left page and one for the right, to "flatten" the page, assuming each half is flatPhocis
D
29

A picture is worth a thousand words: enter image description here

Darr answered 26/9, 2017 at 22:23 Comment(0)
G
20

I have set it down in the terms of a layman.

Homography

A homography, is a matrix that maps a given set of points in one image to the corresponding set of points in another image.

The homography is a 3x3 matrix that maps each point of the first image to the corresponding point of the second image. See below where H is the homography matrix being computed for point x1, y1 and x2, y2

enter image description here

Consider the points of the images present below:

enter image description here

enter image description here

In the case above, there are 4 homography matrices generated.

Where is it used?

  1. You may want to align the above depicted images. You can do so by using the homography.

enter image description here

Here the second image is mapped with respect to the first

  1. Another application is Panoramic Stitching

Visit THIS BLOG for more

Affine transformation

An affine transform generates a matrix to transform the image with respect to the entire image. It does not consider certain points as in the case of homography.

Hence in affine transformation the parallelism of lines is always preserved (as mentioned by EdChum ).

Where is it used?

It is used in areas where you want to alter the entire image:

  • Rotation (self understood)
  • Translation (shifting the entire image by a certain length either to top/bottom or left/right)
  • Scaling (it is basically shrinking or blowing up an image)

See THIS PAGE for more

Grits answered 3/3, 2017 at 19:8 Comment(4)
So just to be clear, you need a unique homography for each point? I don't know the theory behind it, but for datasets I've seen, there is only one homography per transformed image. Not a separate homography for each pixel.Guessrope
To further clarify, is it that homography is a technique to relate pixel locations between two images, and if the transformations are affine transformations, that is, they are planar transformations, then a single homography can be used. If the scenes are not planar, then homographies for sure cannot be used. That is my understanding. Can you please confirm this? In what type of situations do you need more than one homography?Guessrope
Indeed I think OP has some typos. First, yes I think he meant to say that in the example, a single homography matrix can be generated from the 4 points (except for degenerate cases, this is always true, up to an irrelevant scale factor). Second, I think the equation given needs a scaling factor so that the homogeneous coordinates have a properly normalized 1 in the last row. All planar affine transformations can be expressed as a homography with last row [0 0 1] in which case the scale factor is not needed (since the bottom row will always be 1).Phocis
And indeed homographies can perfectly map a 3d plane in one image to a 3d plane in another, but if there are non-planar parts of the scene then they will be distorted if you apply the homography to the entire image. You might use multiple homographies if you're trying to match multiple planes, for example if you have a photo with 4 books strewn about, you might use 4 separate homographies to get an un-distorted picture of each book cover. Or if you have an open book, you might use 2 homographies: one for the left page and one for the right, to "flatten" the page, assuming each half is flatPhocis

© 2022 - 2024 — McMap. All rights reserved.