Face Alignment Algorithm in Images

How can I do basic face alignment in a two-dimensional image with the assumption that I have position / coordinates of the mouth and eyes.

Is there any algorithm that I could implement to adjust the alignment of the face in the images?

+6
source share
3 answers

A face (or image) alignment refers to aligning one image (or face in your case) with respect to another (or reference image / face). It is also referred to as image registration. You can do this using either appearance (intensity-based registration) or key points (function-based registration). The second category stems from image motion models, where one image is considered an offset version of another.

In your case, landmarks (3 points for the eyes and nose?) Provide a good set of links for easy feature-based registration. Assuming you have a point set location on both 2D images, x_1 and x_2 you can evaluate the similarity transformation (rotation, translation, scaling), that is, a flat 2D S transformation that maps x_1 to x_2 . You can add to this a reflection, although for individuals this is likely to be superfluous.

Evaluation can be performed by generating normal equations and solving the linear least squares (LS) problem for the system x_1 = Sx_2 using linear regression. For 5 unknown parameters (2 turns, 2 translations, 1 scaling) you will need 3 points (more precisely 2.5) to solve 5 equations. The solution of the above LS can be obtained by direct linear transformation (for example, by applying SVD or matrix pseudo-inversion). For cases of a sufficiently large number of control points (i.e., Automatically detected), a method of the RANSAC type for point filtering and eliminating uncertainty (although this is not your case here).

After evaluating S apply the image transformation on the second image to get the converted grid (pixel) coordinates of the entire image 2 . The conversion will change the location of the pixels, but not their appearance. Inevitably, some of the converted areas of image 2 will be outside the image 1 grid, and you can select values ​​for these zero locations (for example, 0, NaN, etc.).

Read more: R. Seliski, Image Alignment and Stitching : Textbook "(section 4.3" Geometric Registration ")

In OpenCV, see: Geometric transformations of images . cv::getRotationMatrix2D cv::getAffineTransform and cv::warpAffine. Please note that you must evaluate and apply the similarity transformation (a special case of affine) in order to preserve angles and shapes.

+6
source

For the face, there is a lot of variability in point signs. Thus, it will not be possible to perfectly fit all points of the function with only affine transformations. The only way to align all points perfectly is to warp the image to fit the points. Basically, you can triangulate the image based on the points and make an affine deformation of each triangle to get a distorted image where all the points are aligned.

+1
source

In the Face Recognition section of the OpenCV Face Recognition Guide:

The script aligns the given images in the eyes. It is written in Python, but it is easy to translate into other languages. I know about the C # implementation by Sorin Miron:

0
source

Source: https://habr.com/ru/post/923332/


All Articles