How can I do a basic face alignment on a 2-dimensional image with the assumption that I have the position/coordinates of the mouth and eyes.
Is there any algorithm that I could implement to correct the face alignment on images?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Face (or image) alignment refers to aligning one image (or face in your case) with respect to another (or a reference image/face). It is also referred to as image registration. You can do that using either appearance (intensity-based registration) or key-point locations (feature-based registration). The second category stems from image motion models where one image is considered a displaced version of the other.
In your case the landmark locations (3 points for eyes and nose?) provide a good reference set for straightforward feature-based registration. Assuming you have the location of a set of points in both of the 2D images,
x_1andx_2you can estimate a similarity transform (rotation, translation, scaling), i.e. a planar 2D transformSthat mapsx_1tox_2. You can additionally add reflection to that, though for faces this will most-likely be unnecessary.Estimation can be done by forming the normal equations and solving a linear least-squares (LS) problem for the
x_1 = Sx_2system using linear regression. For the 5 unknown parameters (2 rotation, 2 translation, 1 scaling) you will need 3 points (2.5 to be precise) for solving 5 equations. Solution to the above LS can be obtained through Direct Linear Transform (e.g. by applying SVD or a matrix pseudo-inverse). For cases of a sufficiently large number of reference points (i.e. automatically detected) a RANSAC-type method for point filtering and uncertainty removal (though this is not your case here).After estimating
S, apply image warping on the second image to get the transformed grid (pixel) coordinates of the entireimage 2. The transform will change pixel locations but not their appearance. Unavoidably some of the transformed regions ofimage 2will lie outside the grid ofimage 1, and you can decide on the values for those null locations (e.g. 0, NaN etc.).For more details: R. Szeliski, “Image Alignment and Stitching: A Tutorial” (Section 4.3 “Geometric Registration”)
In OpenCV see: Geometric Image Transformations, e.g.
cv::getRotationMatrix2Dcv::getAffineTransformandcv::warpAffine.Note though that you should estimate and apply a similarity transform (special case of an affine) in order to preserve angles and shapes.