Create Mask for color X ?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
v1nce
Posts: 2
Joined: 2016-11-10T06:38:19-07:00
Authentication code: 1151

Create Mask for color X ?

Post by v1nce » 2016-11-10T06:48:58-07:00

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

snibgo
Posts: 10956
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create Mask for color X ?

Post by snibgo » 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
snibgo's IM pages: im.snibgo.com

v1nce
Posts: 2
Joined: 2016-11-10T06:38:19-07:00
Authentication code: 1151

Re: Create Mask for color X ?

Post by v1nce » 2016-11-10T11:43:57-07:00

exactly what I needed.
thank you snibgo.

the21st
Posts: 2
Joined: 2018-03-07T04:10:35-07:00
Authentication code: 1152

Re: Create Mask for color X ?

Post by the21st » 2018-03-07T04:13:41-07:00

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.

snibgo
Posts: 10956
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create Mask for color X ?

Post by snibgo » 2018-03-07T04:29:05-07:00

What do you want to happen to the pixels that are initially transparent?
snibgo's IM pages: im.snibgo.com

the21st
Posts: 2
Joined: 2018-03-07T04:10:35-07:00
Authentication code: 1152

Re: Create Mask for color X ?

Post by the21st » 2018-03-09T02:52:39-07:00

They shouldn't be included in the mask, i.e. the final mask should be black wherever the original was transparent.

Post Reply