Skimage similartransform不起作用

时间:2018-01-03 11:51:19

标签: python alignment similarity scikit-image face

我正在尝试应用相似变换来对齐面孔:

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) 

为了测试其他类型的转换是否有效,我也尝试使用投影转换:

# see result in the fourth image below
tf = ProjectiveTransform()
tf.estimate(src, dst)
result = transform.warp(image, inverse_map=tf.inverse)
imshow(result)

原始图像,模板,相似变换和投影变换的图像分别为:

original image template similarity projection

正如您所看到的,相似变换存在问题,但我不知道它是什么。投影变换似乎工作正常,眼睛,嘴和鼻子与模板中的点对齐。

发生了什么?我没得到什么?

1 个答案:

答案 0 :(得分:0)

我通过使用包含68个标志而不是4个标记的更好模板解决了我的问题。另外,我使用img_as_ubyte来帮助将数组显示为使用imshow的图像。     来自skimage导入转换     来自scipy.misc导入imshow     来自skimage import img_as_ubyte

# points match with the template below
template_landmarks = (68, 2) array with landmarks
# I use dlib to get detect landmarks from my image
detected_landmarks = (68, 2) array with landmarks

tf = transform.estimate_transform('similarity', detected_landmarks, template_landmarks)
result = img_as_ubyte(transform.warp(image, inverse_map=tf.inverse, output_shape=(198, 198, 3)))

# overlay template landmarks on result in green
for p in template_landmarks:
    x, y = p
    result[y, x] = [0, 255, 0]
imshow(result)

从左到右:原始图像,模板,结果与模板重叠。

显示对齐的另一个结果是videoclip

enter image description hereenter image description hereenter image description here