I am trying to apply a similarity transform to align faces:
from skimage.transform import SimilarityTransform, ProjectiveTransform
from skimage import transform
from scipy.misc import imshow
# face image detected facial landmarks
src = np.float32([left_eye_center, right_eye_center, mouth_center, nose_center])
# face template landmarks, see second image below
dst = np.float32([template['left_eye'], template['right_eye'], template['mouth'], template['nose']])
# see result in the third image below
tf = SimilarityTransform()
tf.estimate(src, dst)
result = transform.warp(image, inverse_map=tf.inverse)
imshow(result)
To test that other kinds of transformations do work I also try with a projective transform:
# see result in the fourth image below
tf = ProjectiveTransform()
tf.estimate(src, dst)
result = transform.warp(image, inverse_map=tf.inverse)
imshow(result)
Images of the original image,template, similarity transform and projective transform respectively:
As you can see, there is something wrong with the similarity transform, but I have no clue what it is. The projective transform seems to work fine, with the eyes, mouth and nose lining up with the points in the template.
What's going on? What am I not getting?