pkhungurn / talking-head-anime-demo

Demo for the "Talking Head Anime from a Single Image."
MIT License
1.99k stars 286 forks source link

Alignment #1

Closed BaldrLector closed 4 years ago

BaldrLector commented 4 years ago

Hi, Great job! Thanks for your sharing.

The method works well in given examples, however, I get a worse result when using the picture generated by waifulabs.com.

The pic is from waifulabs.com, and I convert it to RGBA format with Photoshop. I alignment the face to 128x128 center box and resize the pic to 256x256 image

the results look like this: image

I believe it should be something wrong at the alignment, so could you please share the alignment code?

Here my code of alignment:


from PIL import Image
import numpy as np
import cv2

def alinment_image_lowhigh(image, high, low, save_path=None):
    '''
    :param image: image path
    :param high: the bigger hight cordinate
    :param low:  the smaller hight cordinate
    :param save_path:
    :return:
    '''
    image = np.array(Image.open(image))
    size = np.array(image.shape[:2])

    # adjust face scale to 128
    h = high - low
    scale = 128 / h
    high, low = high * scale, low * scale
    hc = (high + low) / 2
    image = np.array(Image.fromarray(image).resize((int(size[0] * scale), int(size[1] * scale))))

    # move face to center
    size = np.array(image.shape[:2])
    delta = size[0] / 2 - hc
    M = np.float32([[1, 0, 0], [0, 1, delta]])
    image = cv2.warpAffine(image, M, (size[1], size[0]), borderValue=(255, 255, 255))
    image = Image.fromarray(image)
    image = image.resize(256, 256)
    if save_path is not None: image.save(save_path)
    image.show()

Thanks, your reply will be appreciated.

pkhungurn commented 4 years ago

Please check the RGB channels of the PNG file you exported from Photoshop. One of the condition for the input is that if A = 0, then RGB should be (0,0,0). When you remove the background using Photoshop, it is most likely the case that it just sets the alpha channel to 0, leaving the RGB channel as white. Please clear the RGB channels.

HelixNGC7293 commented 4 years ago

Hi, Great job! Thanks for your sharing.

The method works well in given examples, however, I get a worse result when using the picture generated by waifulabs.com.

The pic is from waifulabs.com, and I convert it to RGBA format with Photoshop. I alignment the face to 128x128 center box and resize the pic to 256x256 image

the results look like this: image

I believe it should be something wrong at the alignment, so could you please share the alignment code?

Here my code of alignment:


from PIL import Image
import numpy as np
import cv2

def alinment_image_lowhigh(image, high, low, save_path=None):
    '''
    :param image: image path
    :param high: the bigger hight cordinate
    :param low:  the smaller hight cordinate
    :param save_path:
    :return:
    '''
    image = np.array(Image.open(image))
    size = np.array(image.shape[:2])

    # adjust face scale to 128
    h = high - low
    scale = 128 / h
    high, low = high * scale, low * scale
    hc = (high + low) / 2
    image = np.array(Image.fromarray(image).resize((int(size[0] * scale), int(size[1] * scale))))

    # move face to center
    size = np.array(image.shape[:2])
    delta = size[0] / 2 - hc
    M = np.float32([[1, 0, 0], [0, 1, delta]])
    image = cv2.warpAffine(image, M, (size[1], size[0]), borderValue=(255, 255, 255))
    image = Image.fromarray(image)
    image = image.resize(256, 256)
    if save_path is not None: image.save(save_path)
    image.show()

Thanks, your reply will be appreciated.

Hello BaldrLector~ You can use Gimp to export your PNG file (uncheck 'saving color value from trans pixs' when saving) It should work!

BaldrLector commented 4 years ago

Please check the RGB channels of the PNG file you exported from Photoshop. One of the condition for the input is that if A = 0, then RGB should be (0,0,0). When you remove the background using Photoshop, it is most likely the case that it just sets the alpha channel to 0, leaving the RGB channel as white. Please clear the RGB channels.

You are right, after clear the RGB channels, the method work well. Thanks!