Page 1 of 1

Extract solid color as alpha

Posted: 2014-11-24T07:16:47-07:00
by vincent_Westimages
Hi,

How can i extract all solid colors from a picture (7 or 8 colors max) and export each color as a separate image with transparency on non-color parts?
I've searched the forum but i'm really new with image magick.
A picture is worth a thousand words, so.. Image

Regards,
Vincent

Re: Extract solid color as alpha

Posted: 2014-11-24T07:28:38-07:00
by snibgo
I would do it in a script. First, extract the unique-colours as text. Loop through these colours, making all pixels except the chosen colour transparent.

Something like this pseudo-code:

Code: Select all

convert in.png -unique-colors txt:colours.lis

for each colour in colours.lis
  convert in.png +transparent this_colour out_this_colour.png
end_for
For an extra bonus, you could do all the transparencies in one convert command.

Re: Extract solid color as alpha

Posted: 2014-11-25T01:41:15-07:00
by vincent_Westimages
Thanks a lot for this clarification,
I can now generate the colour.list and apply the transparency.
But once the colours.list is created , how can i loop in the .list to extract each color?
I mean , instead of entering each hexacode to extract the color , is it possible to use directly the .list?

Regards,
Vincent

Re: Extract solid color as alpha

Posted: 2014-11-25T02:21:42-07:00
by snibgo
vincent_Westimages wrote:how can i loop in the .list to extract each color?
Your script would do this. Script languages include bash and Windows BAT.