Page 1 of 1

Convert to PSD forcing RGB to grayscale

Posted: 2014-09-24T16:59:09-07:00
by petitbas
I'm trying to convert an all black frame with data only in the alpha channel. When I try this command:

Code: Select all

convert tmpkb1Es2.png temp.psd
The resulting file ends up with grayscale data in the R channel, no data in the G or B channel and a proper alpha channel. Running identify gives me this:

Code: Select all

identify temp.psd 
temp.psd[0] PSD 2940x1302 2940x1302+0+0 8-bit Grayscale Gray 256c 15.31MB 0.000u 0:00.009
temp.psd[1] PSD 2940x1302 2940x1302+0+0 8-bit Grayscale Gray 256c 15.31MB 0.000u 0:00.000
I've tried -type TrueColorMatte, -def psd:color-type=6, nothing seems to help in generating a true RGB image with data in R G and B channels. Any ideas?

My sample file is here:
https://www.dropbox.com/s/xzn670oxmdo2t ... 2.png?dl=0

This is using ImageMagick 6.8.9-7

Re: Convert to PSD forcing RGB to grayscale

Posted: 2014-09-24T18:39:17-07:00
by fmw42
I do not think you ca make a grayscale image into RGB in IM unless the data is different in each channel. IM and other tools will recognize that the data is the same in each channel and set the colorspace to gray, if that format supports gray.

I tried

Code: Select all

convert tmpkb1Es2.png -type truecoloralpha tmpkb1Es2d.psd
but that did not work. I also tried to assign an sRGB profile, but PS would not accept it and says it is invalid (for a grayscale image)

You will have to open the png or psd file in PS (or perhaps GIMP) and change the colorspace there.

Perhaps someone else knows a way that I do not.

Re: Convert to PSD forcing RGB to grayscale

Posted: 2014-09-24T19:19:12-07:00
by glennrp
fmw42 wrote:I do not think you can make a grayscale image into RGB in IM unless the data is different in each channel. IM and other tools will recognize that the data is the same in each channel and set the colorspace to gray, if that format supports gray.
Perhaps someone else knows a way that I do not.
Adding a non-gray background color causes the PNG encoder to write an otherwise all-gray image as RGB. I don't know if that works for other output formats though.

Re: Convert to PSD forcing RGB to grayscale

Posted: 2014-09-24T19:25:50-07:00
by petitbas
glennrp wrote:
fmw42 wrote:I do not think you can make a grayscale image into RGB in IM unless the data is different in each channel. IM and other tools will recognize that the data is the same in each channel and set the colorspace to gray, if that format supports gray.
Perhaps someone else knows a way that I do not.
Adding a non-gray background color causes the PNG encoder to write an otherwise all-gray image as RGB. I don't know if that works for other output formats though.
How do you add a non-gray background?

Re: Convert to PSD forcing RGB to grayscale

Posted: 2014-09-24T21:06:00-07:00
by glennrp
petitbas wrote:How do you add a non-gray background?

Code: Select all

convert input.png -background "#112233" output.png

Re: Convert to PSD forcing RGB to grayscale

Posted: 2014-09-24T22:01:00-07:00
by petitbas
glennrp wrote:
petitbas wrote:How do you add a non-gray background?

Code: Select all

convert input.png -background "#112233" output.png
Hmmm, given that command and an all black "input.png" save for its alpha channel, the result is a grayscale image.

Same thing when I try something like:

Code: Select all

convert bg.png shadow.png fg.png final.psd
bg.png and fg.png are both RGBA images with data in all channels.
shadow.png is completely black in the RGB channels, only has data in alpha channel.

The result is a psd with multiple layers that have RGBA data in them, except for the "shadow.png" layer, that one only data in the R and A channels, nothing in G or B channels. Is there a way to force copy of channel data to other channels if they're empty?

Re: Convert to PSD forcing RGB to grayscale

Posted: 2014-09-25T06:14:00-07:00
by glennrp
Try this:

Code: Select all

convert tmpkb1Es2png -channel A -negate -separate gray.psd
Tested with IM-6.8.9-8 on Ubuntu.

Re: Convert to PSD forcing RGB to grayscale

Posted: 2014-09-25T09:54:06-07:00
by petitbas
glennrp wrote:Try this:

Code: Select all

convert tmpkb1Es2png -channel A -negate -separate gray.psd
Tested with IM-6.8.9-8 on Ubuntu.
Sorry, I just reread the subject of this thread and it's misleading. It should have read "Convert to PSD is forcing RGB to grayscale, how can I avoid this?".

Your command works great, but it's converting to RGB to grayscale. I'm actually trying to force all channels to be exported as black RGB while keeping the alpha from the image and save that as a .PSD.

Re: Convert to PSD forcing RGB to grayscale

Posted: 2014-09-25T19:13:51-07:00
by fmw42
You did not post an RGB PSD image. It was simply grayscale PNG.

Re: Convert to PSD forcing RGB to grayscale

Posted: 2014-09-26T09:16:43-07:00
by petitbas
fmw42 wrote:You did not post an RGB PSD image. It was simply grayscale PNG.
Actually, when I run:

Code: Select all

identify tmpkb1Es2.png
I get this result:

Code: Select all

/Users/chris/Dropbox/tmpkb1Es2.png PNG 2940x1302 2940x1302+0+0 8-bit sRGB 218KB 0.010u 0:00.000
So I believe ImageMagick thinks it's an RGB file (admittedly with the same data in all three channels). I know IM will convert that image down to grayscale for memory efficiency but when the file is written out as a PSD and I open it in Photoshop, the file is now a grayscale image that doesn't display properly with an alpha channel.

So the question is, even if IM determines the most efficient way of handling the image is as a grayscale, how can I force it to write RGB channels to a PSD file.

Re: Convert to PSD forcing RGB to grayscale

Posted: 2014-09-26T09:28:59-07:00
by fmw42
I am not sure why identify says it is sRGB. If you use identify -verbose you will see it is grayscale

Code: Select all

Image: tmpkb1Es2.png
  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: DirectClass
  Geometry: 2940x1302+0+0
  Units: Undefined
  Type: Bilevel
  Base type: Bilevel
  Endianess: Undefined
  Colorspace: Gray
  Depth: 8-bit
  Channel depth:
    gray: 1-bit
    alpha: 8-bit
IM will not convert a grayscale image to RGB unless you change at least one pixel in the image to color or unless the output format does not support grayscale. You will have to change the colorspace in Photoshop.