Page 1 of 1

Copying image into a new image's RGB channels

Posted: 2014-05-09T14:01:59-07:00
by MGM
Hello, I do something specific in Photoshop that I'd like to try doing in ImageMagick.

Basically, I take an image (with RGB channels), copy the full image, and paste it into a new image's R channel. Then I do the same for the B and G channels.

What would be the equivalent of this in ImageMagick so that it comes out looking exactly the same? I'm particularly afraid of trying to imitate how Photoshop grayscales the image when pasting it into the R, G, or B channel.

Re: Copying image into a new image's RGB channels

Posted: 2014-05-09T14:15:23-07:00
by snibgo
Windows syntax, assuming the inputs are the same size:

Code: Select all

%IM%convert ^
  ( in1.png -grayscale RMS ) ^
  ( in2.png -grayscale RMS ) ^
  ( in3.png -grayscale RMS ) ^
  -combine ^
  out.png
Instead of RMS, use any of: Average Brightness Lightness MS Rec601Luma Rec601Luminance Rec709Luma Rec709Luminance RMS. You can use different methods for each channel.

EDIT: If you want another grayscaling process, see my page "Making an image grayscale (monochrome)".

Re: Copying image into a new image's RGB channels

Posted: 2014-05-12T07:46:36-07:00
by MGM
I tried your process and tried every intensity method available but none of them match. Here are the results:

Starting Image
Grayscaled through Photoshop using method I outlined in my first post

Rec601Luma
Rec601Luminance
Rec709Luma
Rec709Luminance
Brightness
Lightness
Average
MS
RMS

As you can see, none of the provided intensity levels match the output provided by Photoshop. Is there a reason why? I haven't looked at your page for alternative options, do you have anything in particular that might help?

Re: Copying image into a new image's RGB channels

Posted: 2014-05-12T08:26:06-07:00
by snibgo
I don't understand what you are doing. It seems to be an over-complicated way of making an image grayscale. Why make it this complex? ImageMagick has simple commands for doing this. Doubtless Photoshop also has. Copying the same data into three channels is pointless.

Re: Copying image into a new image's RGB channels

Posted: 2014-05-12T08:40:11-07:00
by MGM
The reason is this: I work for a video game developer and I'm writing a DDS file manager for our artists that allows them to take an image's data and "paste" it into channels they specify in a DDS file. For example, they can take image 1's G channel and put it in the DDS file's R channel, or they can take image 2's B channel and put in the DDS file's B channel.

However, our current use case also has them take a full image in Photoshop and paste it into a channel in the DDS file. I need to recreate this programmatically and I was hoping IM would allow me to do that, but so far it hasn't been able to recreate the results from Photoshop.

Does that make sense?

Re: Copying image into a new image's RGB channels

Posted: 2014-05-12T09:12:24-07:00
by snibgo
So you want IM to populate DDS channels in the same way as Photoshop.

I don't have Photoshop and know nothing about DDS files. Sorry, I can't help further.

Re: Copying image into a new image's RGB channels

Posted: 2014-05-13T14:22:54-07:00
by MGM
Thanks for the help either way :)

Is anyone else capable of helping? I'm starting to think this has something to do with color profiles. If I change Photoshop's color profile to Gamma 2.2 (from Dot Gain 20%), the colors match much more closely with the output from IM. It still isn't exact, however, and I'd like for this change to happen on the IM side instead of the PS side.

Re: Copying image into a new image's RGB channels

Posted: 2014-05-13T14:29:01-07:00
by dlemstra
ImageMagick has the -gamma option. Have you tried to see if that would help you to get the colors closer?

Can you post a link to your images?

Re: Copying image into a new image's RGB channels

Posted: 2014-05-13T14:35:22-07:00
by MGM
I have messed with the Gamma option substantially. Usually, applying -Gamma 2.2 gets it closer to where it should be, but not close enough. Here is a zip file containing three Photoshop PSDs. Test.dds is the source file I'm working with, photoshop_output.dds is what I get when I do the method in my first post, and imagemagick_output.dds is what I get when running the command below in IM:

convert test.dds test.dds test.dds -channel RGB -combine -define dds:compression=none ouput.dds

Any help is very much appreciated :)

Re: Copying image into a new image's RGB channels

Posted: 2014-05-14T15:33:23-07:00
by MGM
I was able to resolve it. It seems that Photoshop defaults to a particular color profile, Dot Gain 20%, that ImageMagick can't recreate. Changing the color profile to Gray Gamma 2.2 got IM much closer to Photoshop's results.

You can change the color settings in Photoshop by clicking Edit -> Color Settings, then changing the dropdown next to Gray to "Gray Gamma 2.2".

I should note that the results still aren't 100% perfect, but they're pretty much as close as I could get them using the IM command below:

convert ( test.dds -colorspace Gray ) ( test.dds -colorspace Gray ) ( test.dds -colorspace Gray ) -combine -gamma 2.2 output.dds

Re: Copying image into a new image's RGB channels

Posted: 2014-05-15T10:52:02-07:00
by fmw42
Did you try

Code: Select all

convert ( test.dds -colorspace Gray ) ( test.dds -colorspace Gray ) ( test.dds -colorspace Gray ) -combine -colorspace sRGB output.dds
sRGB has a similar gamma but not exactly the same as 2.2.

Re: Copying image into a new image's RGB channels

Posted: 2014-05-15T12:36:16-07:00
by MGM
I did try that. Do you mean before or after changing Photoshop's color profile to Gamma 2.2?

Re: Copying image into a new image's RGB channels

Posted: 2014-05-15T12:38:56-07:00
by fmw42
MGM wrote:I did try that. Do you mean before or after changing Photoshop's color profile to Gamma 2.2?
After

Re: Copying image into a new image's RGB channels

Posted: 2014-05-15T12:47:24-07:00
by fmw42
several possible other issues:

1) what do you have for the RGB working colorspace? That could be a profile issue if you are not using the same profile in IM

2) IM does not have any ability to us dot gain for gray or spot, that I know. You seem to be able to replace gray dot gain with -gamma 2.2 in PS, but I know of no way to disable spot dot gain in PS.

3) Do you have the advanced controls on or off in the Color Settings window?

I am by no means an expert in PS.