Page 1 of 1

Convert grayscale part of image to color

Posted: 2016-01-06T06:51:48-07:00
by anodyne
Sorry if this has been covered before. I'm using modulatecolor2 to change specific colors of an icon to another one and it's working great.

What I still need to do though is change the remaining grayscale portion to another color (e.g. blue). Is something like this possible?

Here's an example of one of these images.

http://s1.postimg.org/h5cywqq8b/color_swap.png

Re: Convert grayscale part of image to color

Posted: 2016-01-06T10:52:54-07:00
by fmw42
Best I can suggest is to follow with

Code: Select all

convert color_swap.png.jpeg.png -alpha off -fuzz 20% -fill blue +opaque "#80C145" -alpha on result.png

Re: Convert grayscale part of image to color

Posted: 2016-01-08T12:36:49-07:00
by anodyne
Thanks for your response Fred. That worked, but is there a way to throw transparency on that fill? When I try something like below, I get the intended fill color, but there's no transparency and the fill ends up filling in both the white and gray. Any ideas?

Code: Select all

convert color-swap.png -alpha off -fuzz 20% -fill 'rgba(0, 0, 255, 0.8)' +opaque "#80C145" -alpha on result.png

Re: Convert grayscale part of image to color

Posted: 2016-01-08T13:14:23-07:00
by fmw42
This is a bit more tricky. You have to save the original alpha channel. Then do your processing. Then extract the new alpha channel and multiply it by the old alpha channel. Then delete the temp files and put the product alpha channel into the processed image.

Code: Select all

convert color_swap.png \
\( -clone 0 -alpha extract \) \
\( -clone 0 -alpha off -channel rgba -fuzz 20% \
-fill "rgba(0,0,255,0.8)" +opaque "#80C145" \) \
\( -clone 2 -alpha extract \) \
\( -clone 1 -clone 2 -compose multiply -composite \) \
-delete 0,1,3 \
-alpha off -compose over -compose copy_opacity -composite result.png

Re: Convert grayscale part of image to color

Posted: 2016-01-08T14:07:16-07:00
by fmw42
It may be better to change the gray directly to transparent blue. I am not sure if what I gave you above is what you want or not. It may be reducing the alpha value too much (too transparent). So try this:

Code: Select all

convert color_swap.png -alpha on -channel rgba -fuzz 15% -fill "rgba(0,0,255,0.8)" -opaque "#D6D6D6" result.png

Re: Convert grayscale part of image to color

Posted: 2016-01-11T06:38:10-07:00
by anodyne
Nice, looks like this last snippet should get me there. Thanks so much for your help!