Page 1 of 1

How to copy only the red channel?

Posted: 2007-02-06T13:28:21-07:00
by Greg Coats
I need to create an output image that contains ONLY the Red channel of the input image.
The command below copies from the input image the Red, Green, and Blue channels to the output image.
I want to copy only the Red channel.

convert -channel R imageIn_RGB.tif imageOut_R.tif

Re: How to copy only the red channel?

Posted: 2007-02-06T14:12:49-07:00
by Bonzo
Try this, it was from Anthonys examples.

Code: Select all

exec("/usr/local/bin/convert imageIn_RGB.tif -channel BG -fx 0 imageOut_R.tif");

Re: How to copy only the red channel?

Posted: 2007-02-06T16:33:35-07:00
by Greg Coats
Thanks. I see the logic behind that.
The problem now is that
identify -list format
indicates that the official ImageMagick for Mac OS X that I downloaded today can not read nor write any TIFF images. I must use TIFF, because all of my images are GeoTIFF images, which are TIFF images that includes georeferencing info in the TIFF header record.

I see a message posted Wed 20 Dec 2006 5:40 pm by Site Admin, under the heading
identify: no decode delegate for this image format image.tif
says that ImageMagick deliberately removed the ability to read and write TIFF images from the official ImageMagick Mac OS X binary. Are there any plans to restore support for TIFF to ImageMagick?

$ convert -version
Version: ImageMagick 6.3.2 02/02/07 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2007 ImageMagick Studio LLC

$ convert 18suh240765.tif -channel BG -fx 0 18suh240765_R.tif
convert: no decode delegate for this image format `18suh240765.tif'.
convert: missing an image filename `18suh240765_R.tif'.

Re: How to copy only the red channel?

Posted: 2007-02-06T17:17:38-07:00
by Greg Coats
Using an older version of ImageMagick, ImageMagick 6.2.8 07/07/06 Q8, for Mac OS X that still supports TIFF images I tried the suggested syntax

exec("/usr/local/bin/convert imageIn_RGB.tif -channel BG -fx 0 imageOut_R.tif");

but this syntax creates a three channel RGB image (not the desired one channel image), with the G and B channels having all black pixels.
I need to create a one channel image, representing only the Red channel.
Please suggest another syntax to try.

Re: How to copy only the red channel?

Posted: 2007-02-06T19:58:36-07:00
by Greg Coats
Here is how to create from a three channel RGB input image, a single channel R only output image

convert imageIn_RGB.tif -channel R -separate imageOut_R.tif

Re: How to copy only the red channel?

Posted: 2007-02-07T21:20:45-07:00
by anthony
That last method is also a LOT faster than using the slow -fx method
You can also extract all three channels simultaniously

Code: Select all

convert RGB_image.png  -channel RGB  -separate  channels_%d.png
Of course the images will be numbers 1, 2, 3 for red, green and blue.