Rigid body, affine, homography (projection), perspective transformation

Perspective Transformation

The relationship between image transformation and plane coordinate system

1. Rotation:

Insert image description here

2. Panning:

Insert image description hereInsert image description here

3. Rigid body transformation

Insert image description here

4. Affine transformation

Insert image description here
Insert image description hereInsert image description here

5. Projection transformation (homography transformation)

Insert image description here

6 To summarize:

1. Rigid body transformation: translation + rotation, only changes the position of the object, not the shape of the object
2. Affine transformation: changes the position and shape of the object, but maintains "straightness"
3. Projective transformation: completely changes the position and shape of the object

Insert image description here

7. Physical meaning of transformation matrix

Insert image description here

2. Homography transformation

imgimg

img

img

img

3. Plane coordinate system and homogeneous coordinate system

What exactly are homogeneous coordinates?
https://img-blog.csdnimg.cn/20210121221108134.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQzNjA5NDc1,size_16,color_FFFFFF,t_70

1. Understanding perspective transformation

1. Definition

The essence of perspective transformation (Perspective Transformation) is to project the image to a new viewing plane (Viewing Plane), also called projection mapping (Projective Mapping).
img
Insert image description here

2. Transformation matrix calculation for perspective transformation

The essence of perspective transformation (Perspective Transformation) is to project the image to a new viewing plane. Its general transformation formula is:
Insert image description here

(x, y, z) are the homogeneous coordinates of the original image pixels, (X'=X/Z, Y'=Y/Z, Z' =Z/Z) are the homogeneous coordinates of the transformed image pixels .

That is, the homogeneous coordinates (x, y, z) of the original image pixel point correspond to the homogeneous coordinates (X';Y';Z') of the transformed image pixel point, where Z'=1, then the point (X'; Y') is the transformed two-dimensional plane coordinates of the pixel corresponding to the original image:
Insert image description here

The perspective transformation matrix is ​​illustrated as follows:
Insert image description here

in

img

The homogeneous coordinates (x, y, z) of the original image pixel correspond to the homogeneous coordinates (X; Y; Z) of the transformed image pixel. After normalizing Z, the normalized homogeneous coordinates (X';Y';1) are obtained, then the two-dimensional plane corresponding to the homogeneous coordinates (X;Y;Z) of the transformed image pixels The coordinate is (X';Y'),
that is, when the homogeneous coordinate Z'=1, then the point (X';Y') is the transformed two-dimensional plane coordinate of the pixel point corresponding to the original image:
Insert image description here
Generally Ground, we set a33=1, expand the above formula, and get the radial transformation of a point:

Insert image description here
In this equation, there are a total of 8 unknowns, so we can find 4 pairs of 8 points (two pairs for each, the point on the original plane and its corresponding point mapped to the new view plane are one pair) and list the
equation . Solve the parameters a11, a12, a13, a21, a22, a23, a31, a32.
Assume that these 8 points are:
the four coordinates of the source point are A: (x0, y0), (x1, y1), (x2, y2), (x3, y3) and the four
coordinates of the target point are B: (X '0,Y'0), (X'1,Y'1), (X'2,Y'2), (X'3,Y'3) are
then brought into the equation (written in matrix form) to get:
Insert image description here

3. How to use the transformation matrix after solving it

1. How to use

First, we assume that the transformed image is new_image and the size is the same as the original image. Then we traverse the rows and columns of the image new_image, that is, traverse each pixel coordinate (Y, X, 1) of new_image, and then use the transformation matrix warpMatrix to calculate the The coordinates correspond to the position (y, x, 1) in the original image, and the pixel value p (y, x, 1) at that position in the original image is assigned to the (Y, X, 1) position in the transformed image new_image. Points beyond the pixel coordinates of the original image can be assigned values ​​​​at will, depending on personal preference. Generally, the value is assigned to the edge pixel value.
2. Method of finding (y, x, 1) coordinates

1. Hand push formula method

Insert image description here2. Matrix operations

2. Matrix operations

Insert image description hereOriginal picture:
Insert image description here

The four points of the original image
src = np.float32 ([[207, 151], [517, 285], [17, 601], [343, 731]])
correspond to the four transformed points
dst = np.float32 ([[0, 0], [337, 0], [0, 488], [337, 488]]) transformation
matrix
[[ 8.92263779e-01 3.76733596e-01 -2.41585375e+02]
[-4.08140258e- 01 9.44205073e-01 -5.80899328e+01]
[-8.53836442e-05 5.16464182e-05 1.00000000e+00]]
Transformed image
Insert image description here

The solved transformation matrix can transform a square into a quadrilateral. Vice versa, the transformation from a quadrilateral to a square is the same. Therefore, we can transform any quadrilateral into another quadrilateral through two transformations: quadrilateral transformation to square + square transformation to quadrilateral.

Insert image description here
Therefore, given the four pairs of pixel coordinates corresponding to the perspective transformation, the perspective transformation matrix can be obtained; conversely, given the perspective transformation matrix, the perspective transformation of the image or pixel point coordinates can be completed, as shown in the following figure:
Insert image description here

Guess you like

Origin blog.csdn.net/dagengen12138/article/details/131276579