Combine greyscale images as the color channels of an RGB ima

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
daviddoria

Combine greyscale images as the color channels of an RGB ima

Post by daviddoria »

I have two greyscale images, G1.jpg and G2.jpg. I would like to treat G1.jpg as the red channel, and G2.jpg as the green channel to produce an output image of combinations of red and green. Is this possible?

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

Re: Combine greyscale images as the color channels of an RGB ima

Post by fmw42 »

Yes, but you also need to define a blue image, but it can be totally black. Use -combine. see

http://www.imagemagick.org/Usage/channels/#combine
daviddoria

Re: Combine greyscale images as the color channels of an RGB ima

Post by daviddoria »

Great - here was my entire script:

Code: Select all

convert -size 250x250 xc:black black.jpg
convert r.jpg g.jpg black.jpg -combine combined.jpg
ImageMagick does it again!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine greyscale images as the color channels of an RGB ima

Post by fmw42 »

you can make it simpler:

convert r.jpg g.jpg \( -size 250x250 xc:black \) -combine combined.jpg

see http://www.imagemagick.org/Usage/basics/#image_seq
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Combine greyscale images as the color channels of an RGB ima

Post by anthony »

Just set background and only combine two channels, undefined channels are set to the background setting (for that channel).

Code: Select all

   convert r.jpg g.jpg -background black -channel RG -combine combined.jpg
WARNING: the order of the channels is not exchangeable, it must be red then green.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
daviddoria

Re: Combine greyscale images as the color channels of an RGB ima

Post by daviddoria »

So since they have to be ordered, if you wanted to combine just G and B, you'd have to use the first method of making a black red channel? Same for R and B? The only one can you can take advantage of the background is R only, or R and G?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Combine greyscale images as the color channels of an RGB ima

Post by anthony »

daviddoria wrote:So since they have to be ordered, if you wanted to combine just G and B, you'd have to use the first method of making a black red channel? Same for R and B? The only one can you can take advantage of the background is R only, or R and G?
No, the order is just that the order. the -channel defines which of the channel images are actually being provided.

So for BG with a R set to zero you would use

Code: Select all

convert g.jpg b.jpg -background black -channel GB -combine combined.jpg
However the order for the images is still green first then blue if you specified channels as BG or 'blue,green'
The channel setting just 'flags' what channel images are being used, it does not specify order. That was what I was getting at.

This is covered in IM Examples, channel, masks, and transparency, combining channel images.
http://www.imagemagick.org/Usage/channels/#combine

Hmmm... Actually it should cover it, looks like an example is needed!

It also goes on to how you would combine non-RGB channel images ;-)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
daviddoria

Re: Combine greyscale images as the color channels of an RGB ima

Post by daviddoria »

ah, sorry, I totally missed the -channel in your last post, that makes much more sense!
Post Reply