Fill image with other colors

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
Szmycu
Posts: 2
Joined: 2018-12-18T17:24:46-07:00
Authentication code: 1152

Fill image with other colors

Post by Szmycu » 2018-12-18T17:26:25-07:00

hello Im wondering if it is possible to process image in autoit like this

1. firstly there is colorfull wallpaper

2. Fill all colors (exception rose color) - with white

3. Fill rose color with black color

https://imgur.com/a/lFdY26g

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

Re: Fill image with other colors

Post by snibgo » 2018-12-18T17:48:04-07:00

Is this a question about ImageMagick? If it is, what version of IM, on what platform? Please link to an image that is relevant to your question.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 24336
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fill image with other colors

Post by fmw42 » 2018-12-18T18:15:10-07:00

try

Code: Select all

convert balloon.jpg -channel rgba -fuzz 20% -fill none -opaque "rgba(225,0,66,1)" -fill "rgba(255,255,255,1)" +opaque none -alpha off result result.png
Since your image is JPG and JPG is lossy compressed, we need to use a fuzz value to allow for variations in your image colors. Also since you have both black and white in your image, we need to use an intermediate color that is not in your image. So here I use none, which means fully transparent (black), reba(0,0,0,0).

So I first change your red color to "none" (transparent black), then change all colors other than "none" to white. Then I turn off the alpha channel leaving black where you had red.

I enabled all the channels including the alpha channel at the beginning since I was going to use "none" as a color. Thus all colors thereafter need to include the alpha channel even if it is opaque (represented by 1).

See
https://imagemagick.org/Usage/color_basics/#replace
https://imagemagick.org/script/color.php

Szmycu
Posts: 2
Joined: 2018-12-18T17:24:46-07:00
Authentication code: 1152

Re: Fill image with other colors

Post by Szmycu » 2019-01-11T10:23:08-07:00

I got errors why?
I have to use convert or magick function?

https://imgur.com/a/jsmVYxt

User avatar
fmw42
Posts: 24336
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fill image with other colors

Post by fmw42 » 2019-01-11T10:50:45-07:00

If using IM 6, use convert. If using IM 7, use magick. Do not use magick convert for IM 7.

My command has a typo. I put an extra "result" in it. Take that out so that

convert balloon.jpg -channel rgba -fuzz 20% -fill none -opaque "rgba(225,0,66,1)" -fill "rgba(255,255,255,1)" +opaque none -alpha off result result.png

becomes

convert balloon.jpg -channel rgba -fuzz 20% -fill none -opaque "rgba(225,0,66,1)" -fill "rgba(255,255,255,1)" +opaque none -alpha off result.png

Post Reply