Halcon realizes the affine transformation of the image (translation, rotation, scaling, mirroring, oblique cutting)


For beginners in image processing, please correct it if there is any incorrect writing

Affine transformation

Affine transformation includes: affine transformation mainly includes translation transformation , rotation transformation , scaling transformation (also called scale transformation), tilt transformation (also called miscut transformation, shear transformation, offset transformation), and flip transformation . There are six degrees of freedom.

To perform affine transformation, the transformation matrix must be obtained first. To obtain the transformation matrix, you must first obtain the feature point coordinates, angles and other information. Geometric matching and bolb are efficient methods for obtaining feature points. In addition, there are other methods as long as the feature points can be obtained stably.

The main process of affine transformation:

1: Obtain the coordinate and angle of the characteristic point.
2: Calculate the affine transformation matrix.
3: Perform affine transformation on images, regions, and contours

Principles of Mathematical Derivation

https://blog.csdn.net/weixin_41045657/article/details/113522054?spm=1001.2014.3001.5501

Commonly used operators of affine transformation hom_mat (homogeneous Matrix homogeneous matrix)

hom_mat2d_identity

hom_mat2d_identity (HomMat2DIdentity)
Explanation: Define an identity matrix with a diagonal of 1, which is multiplied by any matrix equal to the original matrix itself.
Insert picture description here

hom_mat2d_translate (translation)

hom_mat2d_translate (HomMat2DIdentity, Tx, Ty, HomMat2DTranslate)
Function: add translation to the anti-radiation transformation matrix
HomMat2D (input parameter) : affine transformation matrix
Tx (input parameter) : the distance of translation along the x axis
Ty (input parameter) : the distance of translation along the y axis
HomMat2DTranslate (output parameter) ) : Output transformation matrix
Insert picture description here

read_image (Image, 'C:/Users/Daniel大妞/Desktop/5.png')
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, 300, 300, HomMat2DTranslate)
affine_trans_image (Image, ImageAffineTrans, HomMat2DTranslate, 'constant', 'false')

effect
Insert picture description here

hom_mat2d_rotate (rotate)

hom_mat2d_rotate (:: HomMat2D, Phi, Px, Py: HomMat2DRotate)
Function: add the rotation angle to the affine transformation matrix
HomMat2D (input parameter) : affine transformation matrix
Phi (input parameter) : rotation angle (unit radian)
Px (input parameter) : fixed point row coordinates of the transformation. The fixed point refers to the affine transformation with the point as the support (here refers to the rotation around this point)
Py: (input parameter) : the fixed point column coordinates of the transformation
HomMat2DRotate (output parameter) : the output transformation matrix
Insert picture description here

read_image (Image, 'C:/Users/Daniel大妞/Desktop/5.png')
hom_mat2d_identity (HomMat2DIdentity)
* hom_mat2d_translate (HomMat2DIdentity, 300, 300, HomMat2DTranslate)
hom_mat2d_rotate (HomMat2DIdentity, 0.78, 300, 300, HomMat2DRotate)
affine_trans_image (Image, ImageAffineTrans, HomMat2DRotate, 'constant', 'false')

Effect 1 (rotating coordinates (0, 0))
Insert picture description here
Effect 1 (rotating coordinates (300, 300))
Insert picture description here

hom_mat2d_scale (scale)

hom_mat2d_scale (:: HomMat2D, Sx, Sy, Px, Py: HomMat2DScale)
Function: add scaling to the affine transformation matrix
HomMat2D (input parameter) : affine transformation matrix
Sx (input parameter) : scaling factor
Sy in the x-axis direction (input parameter) : scaling factor
Px in the y-axis direction (input parameter) : Transformed fixed point row coordinates
Py (input parameter) : transformed fixed point column coordinates
HomMat2DScale (output parameter) : output transformation matrix
Insert picture description here

read_image (Image, 'C:/Users/Daniel大妞/Desktop/5.png')
hom_mat2d_identity (HomMat2DIdentity)
* hom_mat2d_translate (HomMat2DIdentity, 300, 300, HomMat2DTranslate)
* hom_mat2d_rotate (HomMat2DIdentity, 0.78, 300, 300, HomMat2DRotate)
hom_mat2d_scale (HomMat2DIdentity, 0.5, 0.5, 0, 0, HomMat2DScale)
affine_trans_image (Image, ImageAffineTrans, HomMat2DScale, 'constant', 'false')

effect
Insert picture description here

hom_mat2d_slant (slant cut)

hom_mat2d_slant (:: HomMat2D, Theta, Axis, Px, Py: HomMat2DSlant)
Function: add chamfer to the anti-radiation transformation matrix
HomMat2D (input parameter) : affine transformation matrix
Theta (input parameter) : chamfer angle (unit: radians)
Axis (input parameter) : the coordinate axis of the chamfer. Value list: x, y
Px (input parameter) : the x coordinate of the transformed fixed point
Py (input parameter) : the y coordinate of the transformed fixed point
HomMat2DSlant (output parameter) : the output affine transformation matrix
Insert picture description here

read_image (Image, 'C:/Users/Daniel大妞/Desktop/5.png')
hom_mat2d_identity (HomMat2DIdentity)
* hom_mat2d_translate (HomMat2DIdentity, 300, 300, HomMat2DTranslate)
* hom_mat2d_rotate (HomMat2DIdentity, 0.78, 300, 300, HomMat2DRotate)
* hom_mat2d_scale (HomMat2DIdentity, 0.5, 0.5, 0, 0, HomMat2DScale)
hom_mat2d_slant (HomMat2DIdentity, 0.52, 'y', 0, 0, HomMat2DSlant)
affine_trans_image (Image, ImageAffineTrans, HomMat2DSlant, 'constant', 'false')

Insert picture description here

vector_angle_to_rigid (rigid affine transformation matrix, supports rotation and translation)

vector_angle_to_rigid(::Row1,Column1,Angle1,Row2,Column2,Angle2:HomMat2D)
Function: Calculate the rigid affine transformation matrix according to the point and angle, support rotation and translation
Row1 (input parameter) : original point row coordinate
Column1 (input parameter) : original point column coordinate
Angle1 (input parameter) : original point angle
Row2 (input parameter) ) : the row coordinate of the transformed destination point
Column2 (input parameter) : the column coordinate of the transformed destination point
Angle2 (input parameter) : the angle of the transformed destination point
HomMat2D (output parameter) : output the affine transformation matrix

Guess you like

Origin blog.csdn.net/weixin_41045657/article/details/113561652