Page 1 of 1

Can't convert Grayscale to RGB

Posted: 2013-06-09T14:59:58-07:00
by tony.whittam
I have an image in a .PNG file that I am trying to convert from being stored in Grayscale + Alpha space to being stored in RGB + Alpha space. I need to do this because some of the devices I use the image on don't seem to be able to handle Grayscale + Alpha in the .PNG file.

I am trying to use
convert worldwhite3-512.png -type TrueColorMatte -define png:color-type=6 out.png
but the output is still stored as grayscale + alpha.

Perhaps I am misunderstanding something about what this command should do. I want it to write the same image unmodified but stored in RGB + Alpha space. Can anyone advise me whether this is the command is correct? If so then what could be stopping the conversion? I've put more detail below.

I'm using Version: ImageMagick 6.8.5-7 2013-05-19 Q16 running on Windows 7 64-bit.

Identify -verbose on my original file gives

Image: worldwhite3-512.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 512x512+0+0
Resolution: 118.11x118.11
Print size: 4.33494x4.33494
Units: PixelsPerCentimeter
Type: GrayscaleAlpha
Endianess: Undefined
Colorspace: Gray
Depth: 8-bit
Channel depth:
gray: 8-bit
alpha: 8-bit
...

After I try this
convert worldwhite3-512.png -type TrueColorMatte -define png:color-type=6 out.png
identify -verbose on the output file gives.

Image: out.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 512x512+0+0
Resolution: 118.11x118.11
Print size: 4.33494x4.33494
Units: PixelsPerCentimeter
Type: GrayscaleAlpha
Endianess: Undefined
Colorspace: Gray
Depth: 8-bit
Channel depth:
gray: 8-bit
alpha: 8-bit
...

For anyone that might be interested I've put the original image at https://dl.dropboxusercontent.com/u/893 ... e3-512.png

Re: Can't convert Grayscale to RGB

Posted: 2013-06-09T15:09:52-07:00
by fmw42
I do not think you can convert a grayscale image to RGB without modifying its values. In IM6 all grayscale images are 3 channels with the R=G=B. But IM knows that all 3 channels are the same and thus labels it as grayscale. If you change say one fully transparent pixel to some color (under the transparency), then it should consider the image as color rather than grayscale.

Re: Can't convert Grayscale to RGB

Posted: 2013-06-09T17:12:56-07:00
by snibgo
tony.whittam wrote:Identify -verbose on my original file gives ...
You misunderstand "identify". This gives details of the image as it is stored in memory, not as it was in the file.

The file worldwhite3-512.png has three 8-bit channels, plus alpha. I verified this with Gimp and a utility program. When IM reads it, it recognizes all the tones are grey, and reports that.

Your convert command ...

Code: Select all

convert worldwhite3-512.png -type TrueColorMatte -define png:color-type=6 out.png
... results (in IM 6.8.5-8) in three 8-bit channels, plus alpha.

Re: Can't convert Grayscale to RGB

Posted: 2013-06-09T17:19:47-07:00
by fmw42
snibgo wrote:convert worldwhite3-512.png -type TrueColorMatte -define png:color-type=6 out.png
Nevertheless, IM still labels it as type=grayscalealpha.

I am not sure why other tools cannot handle that, since it is still 3 channels. Perhaps they get confused by the 3 channels but labeled grayscale.

Re: Can't convert Grayscale to RGB

Posted: 2013-06-09T17:25:36-07:00
by fmw42
Find perfectly transparent pixel:
511,511: ( 0, 0, 0, 0) #00000000 none

convert WorldWhite3-512.png -size 1x1 -fill "rgba(0%,1%,2%,0)" -draw "color 511,511 point" out2.png
identify -verbose out2.png
Image: out2.png
Class: DirectClass
Colorspace: sRGB
Type: PaletteAlpha
Depth: 8-bit
Alpha: True
Channels: srgba
Rendering intent: Perceptual
Gamma: 0.45455