Can I convert white to alpha?

I would like to convert a grayscale image to a smooth transparent image.(opacity depends on blackness)
but, I have no idea about filter names. (I searched alpha, transparent, convert but I can’t find)
which filter can achieve this effect?

image

Is it with the plug-in or with the command line tool ?

thank you for reply.
I use command prompt this time.
I would like to make my daily routine to .gmic custom code.
so, filters combination is also ok.

Perhaps:

gmic run '256,256,1,1,255*x/(w-1) +fill iM-i append c display0'

The useful bit is +fill iM-i append c That is, make an alpha channel from the inverse of the given grayscale; such is then appended to the given grayscale along the spectral (channel) axis. display0 just confirms if the scheme works, and 256,256,1,1,255*x/(w-1) makes a black-to-white ramp as a test grayscale image.

1 Like

With a single channel image. You can do foreach { +negate 255 append c } to do it for every single-channel grayscale image. In general, built-in processing commands are much faster than JIT commands.

2 Likes

Thank you all! I can convert the gray image to smooth alpha😃

But, I found one odd behavior.
When I run below script, output is fine, but “display” command show me this another preview in G’MIC-Qt stand-alone interface.
Is it only my environment?

foreach {

to_rgb
fx_blackandwhite 0.299,0,0.587,0,0.114,0,0,0,0,0,0,0,0,0,2,0,0,0,16,4,0,0,0,50,50
to_gray
+negate 255

append c
display

}

To properly interpret a grayscale image with alpha, use display0 instead of display;

1 Like

Thank you! I can see right preview now.

May I ask what is the difference between negate and negate 255 ?

Negate by itself automatically use the maximum value instead of 255. That’s the main difference.

1 Like