-
I again appear to be dumber that I suppose when I deal with images and my laziness or lameness plays with me. So I still can't figure out the alpha channel thing. I want to just properly convert 4 channels to 3 channels. The issue is... see these two images:
If I do image = image.has_alpha? ? image.flatten : image one image becomes just black. If I do: image = (image.has_alpha? ? image.flatten.composite2(image.bandsplit[3], :screen) : image) another one becomes just white. I guess I totally misunderstand the thing. UPD: Note: one image is downloaded from tg stickers, another one is a html5 base64 exported from p5js canvas after using the text and geometry primitives. I.e. none is made by me band by band so I suppose the images aren't "corrupted" in any way. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @Nakilon, Your first image has RGB all zero, and only has non zero values in the alpha channel. I find vipsdisp useful for looking at images like this: it will show you exactly what's in every pixel in the image: By default, image = image.flatten(background: 255) if image.has_alpha? That should work for your second image too. Maybe the black default for flatten wasn't a great idea :( |
Beta Was this translation helpful? Give feedback.
Hey @Nakilon,
Your first image has RGB all zero, and only has non zero values in the alpha channel. I find vipsdisp useful for looking at images like this: it will show you exactly what's in every pixel in the image:
By default,
vips_flatten()
will flatten against black (ie. 0), so the output is a black image on a black background :( If you flatten against 255 instead, you'll be able to see the alpha:That should work for your second image too.
Maybe the black default for flatten wasn't a great idea :(