Open andreafalzetti opened 2 years ago
Linked issue:
@woctezuma do you have any idea if this is even possible?
I have not checked the source code, but this should be possible a priori: in the worst case, it should be a matter of keeping a mask of the transparent area in the input, and using it in the output.
References to other repositories (with commits) and documentation:
@woctezuma i tried looking at the code but it's not easy to understand without much context and experience in this field - I'm looking for someone with knowledge of the code base to provide some support either explaining to me how to implement this or to be paid to implement it. Would you be available for a chat?
either explaining to me how to implement this
My suggestion would be to look for solutions with the keywords "transparency", "mask" and "merge", similar to:
What you want to do is merge a part of the output (improved faces) into the input (original image with transparent background).
or to be paid to implement it
Sorry, this could require too much time, as I am not familiar with the code base to be able to quickly help on this matter. The solution could be very simple, or involve a bit of debugging (and thus take more time). I cannot judge the task a priori.
For info, I have only contributed in a minor way to this project by replacing a function with a call to a built-in function. https://github.com/xinntao/facexlib/commit/efeacb3c01d654ce0fe25237ea1b2abfcbcf343f
Thank's to chat-gpt. you can restore bg from original image. i think this should be added to the Model args
`from PIL import Image def apply_transparency(source_image_path, target_image_path):
source_img = Image.open(source_image_path)
# Load the target image
target_img = Image.open(target_image_path).convert("RGBA")
# Get the pixel values as a 2D array for both images
source_pixels = source_img.load()
target_pixels = target_img.load()
# Loop through all the pixels in the source image
for x in range(source_img.width):
for y in range(source_img.height):
# Get the pixel value from the source image
source_pixel = source_pixels[x, y]
# Check if the pixel is transparent
if len(source_pixel) == 4 and source_pixel[3] == 0:
# The pixel is transparent, apply the transparency to the target image
target_pixels[x, y] = (0, 0, 0, 0)
# Save the modified target image
target_img.save('output.png')
apply_transparency("./org.png", "./res.png")`
In this example, the apply_transparency() function takes two arguments - the path to the source image file that contains the transparency data, and the path to the target image file that you want to apply the transparency to. The function loads both images using the Image.open() method, and gets the pixel values as 2D arrays using the load() method.
Then, the function loops through all the pixels in the source image, checks if each pixel is transparent, and if it is, applies the transparency to the corresponding pixel in the target image by setting its RGBA value to (0, 0, 0, 0) - i.e., fully transparent.
Finally, the function saves the modified target image to a new file named 'output.png'. You can modify this code to suit your specific needs - for example, you can pass the output filename as an argument to the function, or modify the transparency value to make it less opaque, etc.
change inference_gfpgan.py line 131:
input_img = cv2.imread(img_path, cv2.IMREAD_COLOR)
to
input_img = cv2.imread(img_path, cv2.IMREAD_UNCHANGED)
I am using this image in https://github.com/TencentARC/GFPGAN and the background turns black after calling
paste_faces_to_input_image
. Is there a way to implement support for PNG transparent background?Thanks