change a black image from gray colorspace to rgb colorspace?

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
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

change a black image from gray colorspace to rgb colorspace?

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post 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
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

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

Post by rmagick »

Thanks for your quick reply!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

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

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

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

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