Outputting Channel Images in RGB

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
blue-j
Posts: 68
Joined: 2007-06-12T14:03:18-07:00

Outputting Channel Images in RGB

Post by blue-j »

I'd like to output separate channel images in RGB format, but can't seem to get what I need:

Code: Select all

convert input.ext -separate channel_%d.jpg
i've tried putting -colorspace RGB after -separate without luck. I understand the separate argument wisely outputs grayscale images; I want to make them RGB and maintain the source ICC profile (that happens by default it seems, which is good, except it embeds invalid RGB profiles inside grayscale images!) for rendering in a browser. i'm so sorry to ask this, i have tried to find the answer myself, and I know this should be easy for me! But alas, no fruit has dropped from the shaking of the tree.

Thanks in advance! :)
J
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Outputting Channel Images in RGB

Post by snibgo »

Sorry, I don't understand what you want.

Do you want to create three files from one file? What do you want in those three files?

"-separate" puts the red channel in the first file, green in the second, and blue in the third. So each file contains one channel, which is greyscale.

If you want the three files to actually look red, green and blue, then:

Code: Select all

convert channel_0.jpg -channel GB -evaluate set 0 channel_0.jpg
convert channel_1.jpg -channel RB -evaluate set 0 channel_1.jpg
convert channel_2.jpg -channel RG -evaluate set 0 channel_2.jpg
The three files are now colour images, not greyscale.
snibgo's IM pages: im.snibgo.com
blue-j
Posts: 68
Joined: 2007-06-12T14:03:18-07:00

Re: Outputting Channel Images in RGB

Post by blue-j »

hi there, thank you so much for your energy and for sharing your thoughts! i was looking for gray images, one per channel, technically in the RGB colorspace. but i will look at your suggestion and think about my direction further. thanks again!

- J
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Outputting Channel Images in RGB

Post by snibgo »

You want the separated images to encode pixels as RGB (instead of sRGB) colorspace?

Code: Select all

convert in.png -separate -colorspace RGB out.png
PNG files have metadata that says whether the data is RGB or sRGB, and IM sets the metadata as appropriate. But some software ignores the metadata.

As far as I know, JPEG doesn't have that metadata. So programs that read the JPEG will probably think the values are encoded as sRGB.

EDIT: I see you said "i've tried putting -colorspace RGB after -separate without luck."

My example above works for IM v6.8.8-7 under Windows 7. If you are running an old version of IM, it may not work.
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: Outputting Channel Images in RGB

Post by fmw42 »

for jpg, you could add a linear RGB profile to each gray jpg output
blue-j
Posts: 68
Joined: 2007-06-12T14:03:18-07:00

Re: Outputting Channel Images in RGB

Post by blue-j »

i'm running the latest macport, which is 6.8.8-3_1.

to be more precise, my desire is to keep the source profile in the channel images, and retain the source colorspace (i.e., no color conversion, or at least one without visual effects). that way an ICC-savvy rendering of the channel images will be faithful to such a rendering of the composite.

nothing i do can change the output from being untagged grayscale at present. i'll keep working! thanks my friends!

J
blue-j
Posts: 68
Joined: 2007-06-12T14:03:18-07:00

Re: Outputting Channel Images in RGB

Post by blue-j »

i found this post:

http://stackoverflow.com/questions/1144 ... ce-to-gray

and tried the truecolor argument, and it worked in at least gaining RGB output.

Code: Select all

convert input.ext -separate -type truecolor channel_%d.jpg
but my final goal eludes me for now. i may just go with sRGB GIFs and call it a day and live with the slight visual discrepancy in an ICC-savvy viewer.

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

Re: Outputting Channel Images in RGB

Post by fmw42 »

blue-j wrote:i'm running the latest macport, which is 6.8.8-3_1.

to be more precise, my desire is to keep the source profile in the channel images, and retain the source colorspace (i.e., no color conversion, or at least one without visual effects). that way an ICC-savvy rendering of the channel images will be faithful to such a rendering of the composite.

nothing i do can change the output from being untagged grayscale at present. i'll keep working! thanks my friends!

J
You will have to read the verbose information for the image using IM to get the colorspace or profile. Then add the correct or desired profile to the output image if no profile was found in the input image. With IM you can either change profiles or add a profile if none exists.

See -profile
http://www.imagemagick.org/script/comma ... hp#profile
http://www.imagemagick.org/Usage/formats/#profiles
blue-j
Posts: 68
Joined: 2007-06-12T14:03:18-07:00

Re: Outputting Channel Images in RGB

Post by blue-j »

thanks so much fred, i have already tried this without success, which i am measuring right now by visual reconciliation with Photoshop 14.2. i'll continue my work; perhaps Photoshop's rendering is suboptimal.

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

Re: Outputting Channel Images in RGB

Post by fmw42 »

blue-j wrote:thanks so much fred, i have already tried this without success, which i am measuring right now by visual reconciliation with Photoshop 14.2. i'll continue my work; perhaps Photoshop's rendering is suboptimal.

J
Photoshop has the habit of overwriting your profile or assigning one with theirs. Open the color control panel and set it to show when importing images so that you can tell it what profile to use, etc.

Post an example and tell us what you are trying to do. If you have an input image and your PS output and your IM output, post those. Then we can see what might be going on and what the correct IM commands or PS settings are needed.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Outputting Channel Images in RGB

Post by snibgo »

blue-j wrote:to be more precise, my desire is to keep the source profile in the channel images, and retain the source colorspace (i.e., no color conversion, or at least one without visual effects). that way an ICC-savvy rendering of the channel images will be faithful to such a rendering of the composite.
With these commands ...

Code: Select all

convert redBlue.png -separate rb.png
convert redBlue.png -separate rb.jpg
... the ICC profile from redBlue.png is copied to the output files. I can see that from "identify -verbose rb-0.png" etc. The resulting files (3 for each command) contain the pixels values from the red, green and blue channels.

But this is very dodgy practice because the embedded ICC profile no longer describes the meaning of the pixel values.

It may be better to extract the profile...

Code: Select all

convert redBlue.png rb.icc
... then either strip the profile before separating, or convert the image to sRGB.
snibgo's IM pages: im.snibgo.com
Post Reply