Separate channel gives the CMY channels instead of RGB ones.

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
sonerdemiray
Posts: 3
Joined: 2014-01-05T04:28:20-07:00
Authentication code: 6789

Separate channel gives the CMY channels instead of RGB ones.

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
sonerdemiray
Posts: 3
Joined: 2014-01-05T04:28:20-07:00
Authentication code: 6789

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

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
sonerdemiray
Posts: 3
Joined: 2014-01-05T04:28:20-07:00
Authentication code: 6789

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

Post 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
Post Reply