RGB to Greyscale?

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
Maxwell

Re: RGB to Greyscale?

Post by Maxwell »

Hello Philippe,

I downloaded the PNG linked from
The best I'm able to achieve is 32-bit RGB PNG that looks like a grayscale image.
and It was identified as 8-bit.

Code: Select all

> identify greyscale.png 
greyscale.png PNG 128x128 128x128+0+0 DirectClass 8-bit 16.8613kb
What makes you say it is still 32bit?

(pause)

I went to your test page and my browser (Opera) thinks the Actual is 24-bit and the expected is 8-bit. So I downloaded the Actual and identify says it is 8-bit--same results as above. So then I downloaded the Expected and checked it

Code: Select all

> identify greyscale_expected.png
greyscale_expected.png PNG 128x128 128x128+0+0 PseudoClass 256c 8-bit 10.9004kb 
The differene is DirectClass and PseudoClass 256c 8-bit and now I'm lost...

Hope some of this helps,
Max
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: RGB to Greyscale?

Post by anthony »

DirectClass means colors are defined directly in the array. You can thus have a different color for each individual pixel. for Grayscale each color is 8bit, and is quite economical.

PsuedoColor, means instead of an array of colors, it uses an array of color indexes into a table of colors. for 8 bit that means the image is limited to 256 colors! with eaith index also being 8bit, though the colors themselfs can be a 8 bit grayscale or a 24 bit RGB color. This is how GIF format works.

A 8 bit greyscale image may as well be DirectColor, for all the optimization savings a PsuedoColor indexed table of colors provides!

In IM you can set -type PsuedoColor (if this works depend of the output coder) or use PNG8:image.png, to use the special "PNG in a GIF-like format" coder.

Alternatively you can use external PNG specific programs to optimize the format without loss of quality ("optipng"), or quantize the colors into a 8bit color table ("pngng").
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply