Page 1 of 1

change a black image from gray colorspace to rgb colorspace?

Posted: 2008-09-02T07:58:42-07:00
by rmagick
A question from an RMagick user.

I have an entirely black opaque PNG image. I'd like to make a copy in JPEG format and change the colorspace to RGB. I've tried this simple command but the colorspace remains Gray according to identify.

Code: Select all

convert input.png -colorspace RGB output.jpg
If it helps, here's what identify says about the input image:

Code: Select all

Image: input.png
  Format: PNG (Portable Network Graphics)
  Class: DirectClass
  Geometry: 128x128+0+0
  Resolution: 28.35x28.35
  Print size: 4.51499x4.51499
  Units: PixelsPerCentimeter
  Type: Bilevel
  Endianess: Undefined
  Colorspace: Gray
  Depth: 8/1-bit
  Channel depth:
    gray: 1-bit
    alpha: 1-bit
  Channel statistics:
    gray:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: -0 (-0)
    opacity:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: -0 (-0)
  Histogram:
     16384: (  0,  0,  0,  0) #000000 black
  Rendering intent: Undefined
  Chromaticity:
    red primary: (0.63999,0.33001)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.05999)
    white point: (0.31269,0.32899)
  Interlace: None
  Background color: white
  Border color: rgb(223,223,223)
  Matte color: grey74
  Transparent color: none
  Page geometry: 128x128+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Properties:
    create-date: 2008-09-01T16:20:08-04:00
    modify-date: 2008-09-01T16:20:07-04:00
    signature: 49f6ff9b24c008dc281f9b5e78644c12d9398ed5af3a3160620a88edbb117b00
  Profiles:
    Profile-icc: 3144 bytes
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 2.94531kb
  Number pixels: 16kb
  Version: ImageMagick 6.4.1 05/12/08 Q8 http://www.imagemagick.org

Re: change a black image from gray colorspace to rgb colorspace?

Posted: 2008-09-02T09:10:07-07:00
by magick
IdentifyImage() checks to see if the image is grayscale and reports a gray colorspace if it is-- even if the assigned colorspace is RGB. We will add a patch to the ImageMagick subversion trunk to fix this problem

Re: change a black image from gray colorspace to rgb colorspace?

Posted: 2008-09-02T11:28:19-07:00
by rmagick
Thanks for your quick reply!

Re: change a black image from gray colorspace to rgb colorspace?

Posted: 2008-09-02T22:11:13-07:00
by anthony
I believe a patch is not nessary!!!!

the output colorspace is only hinted at by the internal colorspace of the image in memory. the actual output
colorspace is controlled by -type and not by -colorspace

Re: change a black image from gray colorspace to rgb colorspace?

Posted: 2008-09-03T07:06:51-07:00
by rmagick
-type looks like the right approach, especially given the example shown for the option. I tried

Code: Select all

convert input.png -type TrueColor test.jpg
Identify reports the type as Bilevel and the colorspace as Gray. Keeping in mind that identify may not be accurately representing the actual colorspace, I inspected the image using RMagick (which doesn't call IdentifyImage), which reports the colorspace as RGB and the type as Bilevel.

Does this look like the correct result?

The ImageMagick on my PowerBook is a bit back-dated. I'm using 6.4.1.

Re: change a black image from gray colorspace to rgb colorspace?

Posted: 2008-09-03T16:09:54-07:00
by anthony
I recommend you check using some type of JPEG specific tool to see what is really in the resulting JPEG. Then report any differences with what IM reports.

Re: change a black image from gray colorspace to rgb colorspace?

Posted: 2008-09-04T11:25:27-07:00
by rmagick
Thanks for your advice Anthony. I've suggested to the RMagick user that there is no bug and gave him a simple RMagick script to examine. I am awaiting his reply.