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 »

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: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create Mask for color X ?

Post 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
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 »

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 »

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: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create Mask for color X ?

Post by snibgo »

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 »

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