Open shuZro opened 2 weeks ago
Try to remove the transparency in the image via something like Photoshop and see if the transparent areas are actually have different colors. The palette is calculated using all pixels, and transparent areas are usually all black with transparency, but that is not always the case.
I was using https://github.com/danielgatis/rembg to remove the background of an image. Then was passing it to pyxelate. Here is some of my code `def process_image(image, size, colours, remove_bg=False) -> Image:
if remove_bg:
image = remove(image)
image.save("removed.png")
sk_img = np.array(image)
pyx = Pyx(factor=512 / size, palette=colours)
pyx.fit(sk_img)
new_image = pyx.transform(sk_img)
image = Image.fromarray(new_image)
image.save("pixel.png")
return image`
Here is the source image, transparent image and the pixelated image. See the colours.
I used the trex example on a another png file with transparent background. But when I run it the colours are much more reduced. If I use the same image with non transparent background the output is fine. Any ideas?