ZHKKKe / MODNet

A Trimap-Free Portrait Matting Solution in Real Time [AAAI 2022]
Apache License 2.0
3.84k stars 636 forks source link

Web edition output in png format but with white background #37

Closed Ennorath closed 3 years ago

Ennorath commented 3 years ago

I'm talking about this website - https://gradio.app/g/modnet It would be much better, if users will be able to download png file without background at all. Is it possible in future? Will you update it later?

ZHKKKe commented 3 years ago

Hi, thanks for your attention!

Since the server is hold by the Gradio team. I will try to contact with them for supporting this function. Maybe you can use our Colab demo to download the predicted alpha matte.

aliabd commented 3 years ago

Hey @Ennorath, I developed the gradio link. I'm a bit confused, you can already download the png by right clicking on the image. See GIF:

modnet-save-image

Is this what is being requested?

ZHKKKe commented 3 years ago

@aliabd Hi. Thanks for your help! I think @Ennorath want a foreground PNG image with a transparent background. To achieve this, for the PNG image (with four channels) shown in MATTE_IMAGE, we need to save the original image to the first three channels and save the alpha matte to the last channel. I have modified and tested the code locally. In your fork demo.py, please change (L67-L68):

    matte_mask = np.repeat(matte[:, :, None], 3, axis=2)
    foreground = im_np * matte_mask + (1 - matte_mask) * 255

to

    # matte_mask = np.repeat(matte[:, :, None], 3, axis=2)
    # foreground = im_np * matte_mask + (1 - matte_mask) * 255
    foreground = np.concatenate((im_np, matte[:, :, None] * 255), axis=2)

I agree that it makes more sense to show a transparent background rather than a colorful one.

Ennorath commented 3 years ago

@aliabd Hi. Thanks for your help! I think @Ennorath want a foreground PNG image with a transparent background. To achieve this, for the PNG image (with four channels) shown in MATTE_IMAGE, we need to save the original image to the first three channels and save the alpha matte to the last channel. I have modified and tested the code locally. In your fork demo.py, please change (L67-L68):

    matte_mask = np.repeat(matte[:, :, None], 3, axis=2)
    foreground = im_np * matte_mask + (1 - matte_mask) * 255

to

    # matte_mask = np.repeat(matte[:, :, None], 3, axis=2)
    # foreground = im_np * matte_mask + (1 - matte_mask) * 255
    foreground = np.concatenate((im_np, matte[:, :, None] * 255), axis=2)

I agree that it makes more sense to show a transparent background than a colorful one.

Thanks, yeah, sorry for my English. It's exactly what I meant. Thank you! Hope Gradio Team will allow to add feature to download picture with transparent background, it would be fantastic! :) Waiting for the updates! And Thanks for the project! It really useful

ZHKKKe commented 3 years ago

@Ennorath I will @ you when this feature is supported.

aliabd commented 3 years ago

Hey @Ennorath, @ZHKKKe

I understood what you meant and have updated the demo link: https://gradio.app/g/modnet

modnet-transparent

Thanks, let me know if this is what you requested.

Ennorath commented 3 years ago

Hey @Ennorath, @ZHKKKe

I understood what you meant and have updated the demo link: https://gradio.app/g/modnet

modnet-transparent

Thanks, let me know if this is what you requested.

Hey! Thanks!!! It's Awesome!