0
votes

I'm trying to combine the RGB channels from 3 separate images using ImageMagick. The red channel from image01.png, blue channel from image02.png and the green channel from image03.png

Image01.png, Image02.png, Image03.png

enter image description here enter image description here enter image description here

The resulting image should look like this (left) but I'm getting this (right):

enter image description here enter image description here

This is the command I'm running....

"C:/ImageMagick/magick.exe" convert "C:/images/image01.png" "C:/images/image02.png" "C:/images/image03.png" "-background" "#ff0000" "-channel" "red,green,blue" "-combine" "C:/images/combined.png"

Do I need to somehow save out the various channels of each image separating first and then combine the images?

1
Windows command processor cmd.exe has a different syntax than the Linux shell interpreters. So first replace all ' by " because of ' has no special meaning for cmd.exe in comparison to Linux shell interpreters. Second the directory separator on Windows is \ and not / as on Linux and for that reason replace all / by \ in the command line. CMD interprets , as argument separator and replaces it by a space character, except the comma is inside an argument string enclosed in ". Therefore 'red,green,blue' is something completely different than "red,green,blue".Mofi

1 Answers

1
votes

In ImageMagick, -channel does not work to select channels from multiple images.

Furthermore and more importantly, white contains red, green and blue. So the red channel of the first image will have the red dot as white and the background white as white, leaving black for the green and blue lines. Similarly in the other images. So white needs to be made black in each image. Then the channels are separated and recombined. Then black needs to be made white again.

Unix syntax:

convert \
\( image01.png -fuzz 70% -fill black -opaque white \
-channel r -separate +channel \) \
\( image02.png -fuzz 70% -fill black -opaque white \
-channel g -separate +channel \) \
\( image03.png -fuzz 70% -fill black -opaque white \
-channel b -separate +channel \) \
-set colorspace sRGB -combine \
-fuzz 20% -fill white -opaque black \
result.png

convert.exe ^
( image01.png -fuzz 70% -fill black -opaque white ^
-channel r -separate +channel ) ^
( image02.png -fuzz 70% -fill black -opaque white ^
-channel g -separate +channel ) ^
( image03.png -fuzz 70% -fill black -opaque white ^
-channel b -separate +channel ) ^
-set colorspace sRGB -combine ^
-fuzz 20% -fill white -opaque black ^
result.png

enter image description here

The -fuzz is needed to remove the anti-aliased colors that are near white around the edges of the colored regions.

You would be much better starting with the 3 input images that have a black background rather than white. Then all the fuzz and white to black and black back to white would not be needed.