Page 1 of 1

Combine greyscale images as the color channels of an RGB ima

Posted: 2009-04-12T05:35:52-07:00
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

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

Posted: 2009-04-12T12:20:49-07:00
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

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

Posted: 2009-04-12T15:05:38-07:00
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!

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

Posted: 2009-04-12T16:23:25-07:00
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

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

Posted: 2009-04-14T00:52:16-07:00
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.

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

Posted: 2009-04-14T05:41:24-07:00
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?

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

Posted: 2009-04-14T20:43:29-07:00
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 ;-)

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

Posted: 2009-04-15T04:49:55-07:00
by daviddoria
ah, sorry, I totally missed the -channel in your last post, that makes much more sense!