Perspective Transformation
The relationship between image transformation and plane coordinate system
1. Rotation:
2. Panning:
3. Rigid body transformation
4. Affine transformation
5. Projection transformation (homography transformation)
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
7. Physical meaning of transformation matrix
2. Homography transformation
3. Plane coordinate system and homogeneous coordinate system
What exactly are homogeneous coordinates?
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).
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:
(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:
The perspective transformation matrix is illustrated as follows:
in
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:
Generally Ground, we set a33=1, expand the above formula, and get the radial transformation of a point:
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:
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
2. Matrix operations
2. Matrix operations
Original picture:
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
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.
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: