【问题标题】:Skimage similaritytransform does not workSkimage相似度变换不起作用
【发布时间】:2018-01-10 22:13:01
【问题描述】:

我正在尝试应用相似变换来对齐人脸:

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)

原图、模板、相似变换、投影变换的图像:

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

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

【问题讨论】:

    标签: python alignment similarity scikit-image face


    【解决方案1】:

    我通过使用具有 68 个地标而不是 4 个地标的更好模板解决了我的问题。我还使用了img_as_ubyte,它有助于使用imshow 将数组显示为图像。 从 skimage 导入转换 从 scipy.misc 导入 imshow 从 skimage 导入 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 中显示对齐结果的另一个结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-10
      • 1970-01-01
      相关资源
      最近更新 更多