-
Notifications
You must be signed in to change notification settings - Fork 62
-
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:
- https://drive.google.com/file/d/1SeYIbaawN5zaR4K3gsoHZyjcb-oy5gri/view?usp=sharing
- https://drive.google.com/file/d/1AMa-1Q8hlfwevHSM1nXHSLZ6l4Dc_rth/view?usp=sharing
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.
All reactions
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:
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 :(
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, 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:
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.
All reactions
-
Woah, 4 channel eyedropper! Is it available on macOS though?
Thank you for the prompt response and making me see the problem.
I believe I saw the mention of the "default background" somewhere in https://en.wikipedia.org/wiki/Alpha_compositing when I was solving the issue with that image few weeks ago, can't find it now.
That is interesting because on canvas the default color is white I guess (while as you showed it stores the color as black at least in the export by document.getElementsByTagName('canvas')[0].toDataURL()
). Also it's white in macOS preview. It's white in Telegram. But black in Skype (when you click/zoom it).
Beta Was this translation helpful? Give feedback.
All reactions
-
You'd need to compile from source I guess :( Though I've not tried.
Beta Was this translation helpful? Give feedback.