Separating key color and everything else preserving alpha
Posted: 2014-06-05T10:40:16-07:00
I have a tricky problem I've been struggling with for a few days, hope those who are pros in Image Magick might be able to help me...
I have an RGBA .PNG image consisting of regular image artwork (eg. a sword) and action lines (eg. a swipe) that needs to be separated out as two images. The action lines are always 100% red (1.0,0.0,0.0), but can have any per-pixel alpha value. The source artwork is everything else, and can also have any RGBA value (except the red of course). (Note - we'll probably need to be able pass in which RGB indicate the action lines in future, eg. purple). To be clear, this isn't about separating a color channel (such as R,G,B) but being able to separate a key color into one image, and everything else into a separate image whilst preserving alpha for both.
Here is an example of an image with the red action lines --
https://drive.google.com/file/d/0B9Gh1o ... sp=sharing
The two separate images I'm trying to derive from the source image are --
1. Keep action lines only (100% red, any alpha) - preserve the alpha component of those pixels, and replacing all other colors for transparent white background. Would also be useful to be able to change the red to any other color (preserving the per-pixel alpha) in the process, but that's a secondary concern.
Example (mock-up) output - https://drive.google.com/file/d/0B9Gh1o ... sp=sharing
2. Keep non-action lines only preserving the alpha component of those pixels, and replace the action line (100% red) pixels for transparent white.
Example (mock-up) output - https://drive.google.com/file/d/0B9Gh1o ... sp=sharing
I've tried all manner of -transparent, +transparent, -compose, -alpha on, -alpha off, etc. But really struggling on this one. Would very much appreciate any advice folks can give.
Many thanks,
-- Brian.
Indie developer
I have an RGBA .PNG image consisting of regular image artwork (eg. a sword) and action lines (eg. a swipe) that needs to be separated out as two images. The action lines are always 100% red (1.0,0.0,0.0), but can have any per-pixel alpha value. The source artwork is everything else, and can also have any RGBA value (except the red of course). (Note - we'll probably need to be able pass in which RGB indicate the action lines in future, eg. purple). To be clear, this isn't about separating a color channel (such as R,G,B) but being able to separate a key color into one image, and everything else into a separate image whilst preserving alpha for both.
Here is an example of an image with the red action lines --
https://drive.google.com/file/d/0B9Gh1o ... sp=sharing
The two separate images I'm trying to derive from the source image are --
1. Keep action lines only (100% red, any alpha) - preserve the alpha component of those pixels, and replacing all other colors for transparent white background. Would also be useful to be able to change the red to any other color (preserving the per-pixel alpha) in the process, but that's a secondary concern.
Example (mock-up) output - https://drive.google.com/file/d/0B9Gh1o ... sp=sharing
2. Keep non-action lines only preserving the alpha component of those pixels, and replace the action line (100% red) pixels for transparent white.
Example (mock-up) output - https://drive.google.com/file/d/0B9Gh1o ... sp=sharing
I've tried all manner of -transparent, +transparent, -compose, -alpha on, -alpha off, etc. But really struggling on this one. Would very much appreciate any advice folks can give.
Many thanks,
-- Brian.
Indie developer