Page 1 of 1

Separate channel gives the CMY channels instead of RGB ones.

Posted: 2014-01-05T04:49:00-07:00
by sonerdemiray
Hi all,

I have a PNG image that I want to separate into its RGB channel using the instruction below:

convert 009.png -set colorspace RGB -separate 009.png

Here is the imput image:
Image

And the output images:
Image
Image
Image


The problem is that the output images are in fact the CMY channels instead of RGB.

What could be the problem?

Thanks in advance to everybody replying.

Soner

Re: Separate channel gives the CMY channels instead of RGB o

Posted: 2014-01-05T05:19:40-07:00
by snibgo
IM reports an error, which doesn't help:

Code: Select all

identify.exe: iCCP: known incorrect sRGB profile `009.png' @ warning/png.c/MagickPNGWarningHandler/1830.
However, I don't understand your comment abot CMY. The first result shows the red channel. Where the input is green or blue the red channel shows black. Where the input is red or white the red channel shows white.

Similarly for the green and blue channels.

Re: Separate channel gives the CMY channels instead of RGB o

Posted: 2014-01-05T11:03:31-07:00
by sonerdemiray
Thanks for the reply.

I think I misunderstand the function of "separate". What I want to do is to copy the RED pixels from the source image to the destination. (Also the GREEN and the BLUE ones as separate images). I mean, I want to obtain 3 grayscale images representing the RED, GREEN and BLUE channels of the source image.

But as I understand, "separate" eliminates the given channel from the source image.

I also tried the function compositeImage with the COMPOSITE_COPYRED parameter but the result was the same with the separate function.

Thanks in advance for your further comments.

Soner

Re: Separate channel gives the CMY channels instead of RGB o

Posted: 2014-01-05T11:15:41-07:00
by snibgo
"-separate" gives you the value that was in the red (etc) channel. The colour "red" has a value in just the red channel. The colour "white" has values in all three channels. What you want is black instead of white. Or rather, as your white is transparent, to flatten against black.

Code: Select all

convert  009.png -strip -background black -flatten -separate 009.png
The first result has white where the pixel was red and black everywhere else.

Re: Separate channel gives the CMY channels instead of RGB o

Posted: 2014-01-05T12:52:47-07:00
by fmw42
convert 009.png -set colorspace RGB -separate 009.png
PNG does not support CMYK. So the image is sRGB. For other image types, such as jpg, if you want to convert from cmyk to rgb, the proper command is -colorspace sRGB and not -set colorspace RGB. The latter just changes the meta data tag for colorspace without changing the data.

Your input png could be 32-bit color, that is RGBA, so if you use -separate and get 4 output images, the last one may be alpha (transparency).

What do you get from

identify -verbose 009.png

Re: Separate channel gives the CMY channels instead of RGB o

Posted: 2014-01-05T16:26:20-07:00
by sonerdemiray
Hi all,

Setting the background color to "black" and flattening the image before separating the red (or any other) channel fixed the problem.

Transparent pixels of the image are in fact "white pixels with zero opacity" so they are included in every channel if I don't replace them with black ones before separating.

As I forgot that, I misinterpreted the resulting images.

So, it has nothing to do with the color space.

Thanks again to everyone interested. :)

Soner