Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styling a Transparent Image #484

Open
spot92 opened this issue Dec 1, 2019 · 1 comment
Open

Styling a Transparent Image #484

spot92 opened this issue Dec 1, 2019 · 1 comment

Comments

@spot92
Copy link

spot92 commented Dec 1, 2019

Is anyone familiar with a way to style a transparent image? I've tried passing the .png content and doing a .png output, but the transparent background gets styled.

@hikmet-demir
Copy link

hikmet-demir commented May 27, 2020

@spot92

There is a easy solution for it @spot92 , I don't think you can prevent transparent places of images to get styled but you can make them re-transparent again.

Every image colorful image have 3 or 4 image channel ( RGB and A) A is the alpha channel and determines opacity of the pixels. What you need to is before feeding style image to network you save the Alpha channel of the image in a numpy array and after image being style you added back to image.

Example code that I use for some other implementation

 t_data = np.array(target)
 target_alpha = t_data[:,:,3:]

#deeplearning
#deeplearning

out_img_nparr = np.array(out_img)
final_hopefully = np.concatenate((out_img_nparr, target_alpha), axis=2)
image2 = Image.fromarray(final_hopefully)
image2.save(output_image_path)

I'm basically extracting the alpha channel and adding it back to image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants