Page 1 of 1

Create Mask for color X ?

Posted: 2016-11-10T06:48:58-07:00
by v1nce
Hi,

I got a 24bits png and I want to get a mask (1bit) for color X (say '#aabbcc')

I want output pixel to be black where input pixel was '#aabbcc'
and output pixel to be white for any other pixel input


I tweaked the exemple at viewtopic.php?t=13602

convert rmgcb.png \
\( -clone 0 \
-transparent '#aabbcc' \
-alpha extract \
-fill white -opaque white \
-transparent black \) \
-compose over -composite \
rmgcb_red_yellow_blue.png

but the outpixel are still colorfull

thank you

Re: Create Mask for color X ?

Posted: 2016-11-10T07:55:37-07:00
by snibgo
You make #aabbcc transparent, then "-alpha extract" makes black where the pixels were #aabbcc, and white otherwise.

That's what you want, isn't it?

Then you do other stuff.

Code: Select all

convert rmgcb.png \
-transparent '#aabbcc' \
-alpha extract \
rmgcb_red_yellow_blue.png

Re: Create Mask for color X ?

Posted: 2016-11-10T11:43:57-07:00
by v1nce
exactly what I needed.
thank you snibgo.

Re: Create Mask for color X ?

Posted: 2018-03-07T04:13:41-07:00
by the21st
snibgo wrote: 2016-11-10T07:55:37-07:00 You make #aabbcc transparent, then "-alpha extract" makes black where the pixels were #aabbcc, and white otherwise.

That's what you want, isn't it?

Then you do other stuff.

Code: Select all

convert rmgcb.png \
-transparent '#aabbcc' \
-alpha extract \
rmgcb_red_yellow_blue.png
In my case, the original image (rmgcb.png) already has some transparency, and that is getting mixed with the color I want to extract the mask for. Is there any way to fix this? I tried turning off the transparency, but than this defaults to a black background, which is a problem in cases when I want to extract the black color to a mask.

Re: Create Mask for color X ?

Posted: 2018-03-07T04:29:05-07:00
by snibgo
What do you want to happen to the pixels that are initially transparent?

Re: Create Mask for color X ?

Posted: 2018-03-09T02:52:39-07:00
by the21st
They shouldn't be included in the mask, i.e. the final mask should be black wherever the original was transparent.