Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

we have a Python script:

from PIL import Image, ImageOps, ImageFilter
import cv2             
import numpy as np

def remove_trans(image):
    #Replace transparency on image with white background
    image = image.convert('RGBA')
    new_image = Image.new("RGBA", image.size, "WHITE") # Create a white rgba background
    new_image.paste(image, (0, 0), image)              # Paste the image on the background. 
    new_image = new_image.convert('RGB')
    return new_image
img = Image.open('test.png')
img1 = remove_trans(img)
img1.save('NO_ALPHA_PNG.png')
print(img.mode)
img = img.convert('LA')

img = img.convert('1')

img.save('PNG_filter.png')

However we have a bug there. When we load a transparent png image, and then "process" the image with the script, the transparent background is very weird. We found out the reason is the dithering. but we havent found any solution so far. Anybody knows how to get the background transparent, with dithering also?

After process

How it looks when processed

Original

Original File


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
420 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...