Re: Replace color but only in some regions
Posted: 2018-10-19T15:10:58-07:00
I don't know what you are doing with connected components. I would create a mask like this (Windows BAT syntax):
You didn't say what you want to happen at the antialised border, so I've just done a fuzz.
Then we can use the mask to composite purple or any colour only where the mask is white:
This can be combined into a single command, of course.
Code: Select all
convert ^
inGreen.png ^
-fuzz 20%% ^
-transparent #4CFE00 ^
-alpha extract -negate ^
-threshold 50%% ^
( +clone ^
-define morphology:compose=Lighten ^
-morphology HMT 2x3+0+1:0,0,1,-,0,0 ^
-morphology HMT 2x3+1+1:0,0,-,1,0,0 ^
-negate ^
) ^
-compose Darken -composite ^
mask.png
Then we can use the mask to composite purple or any colour only where the mask is white:
Code: Select all
convert ^
inGreen.png ^
( +clone ^
-fill Purple -colorize 100 ^
) ^
mask.png ^
-compose Over -composite ^
out.png