Copying image into a new image's RGB channels

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
MGM
Posts: 10
Joined: 2014-05-07T12:32:17-07:00
Authentication code: 6789

Copying image into a new image's RGB channels

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

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

Post 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)".
snibgo's IM pages: im.snibgo.com
MGM
Posts: 10
Joined: 2014-05-07T12:32:17-07:00
Authentication code: 6789

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

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

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

Post 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.
snibgo's IM pages: im.snibgo.com
MGM
Posts: 10
Joined: 2014-05-07T12:32:17-07:00
Authentication code: 6789

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

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

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

Post 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.
snibgo's IM pages: im.snibgo.com
MGM
Posts: 10
Joined: 2014-05-07T12:32:17-07:00
Authentication code: 6789

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

Post 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.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

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

Post 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?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
MGM
Posts: 10
Joined: 2014-05-07T12:32:17-07:00
Authentication code: 6789

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

Post 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 :)
MGM
Posts: 10
Joined: 2014-05-07T12:32:17-07:00
Authentication code: 6789

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

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
MGM
Posts: 10
Joined: 2014-05-07T12:32:17-07:00
Authentication code: 6789

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

Post by MGM »

I did try that. Do you mean before or after changing Photoshop's color profile to Gamma 2.2?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

MGM wrote:I did try that. Do you mean before or after changing Photoshop's color profile to Gamma 2.2?
After
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

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