I would work in HCL (Hue, Chroma, Lightness) colorspace. You want to change hues, without changing chroma or lightness? Yes?
Red is at hue=0 degrees. Purple is at hue=75%. To make all the colour red:
Code: Select all
convert pile_resized.png -colorspace HCL -channel R -evaluate set +channel -colorspace sRGB r.png
Instead, we can make all the colour purple:
Code: Select all
convert pile_resized.png -colorspace HCL -channel R -evaluate set 75% +channel -colorspace sRGB p.png
If we want to change green into red, and blue into purple, we can combine the previous two results with a mask. Notice that you have anti-aliasing where green and blue merge. By inspecting the hue channel, I find that green is about 33% and blue is about 68%. The middle of this is 50.5. 10% on either side is 40.5% to 60.5%. We will create a ramp in this range.
Code: Select all
convert pile_resized.png -colorspace HCL -channel R -separate +channel -level 40.5,60.5% m.png
m.png is a mask, black where we had green (or no colour at all), white where we had blue.
So we combine r.png and p.png with this mask. I also flatten against white and convert to JPG, just for bandwidth speed:
Code: Select all
convert r.png p.png m.png -compose Over -composite -background White -layers Flatten purpred.jpg
All the convert commands can be combined into a single command.
