Reading as GrayScale

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
3DTOPO
Posts: 28
Joined: 2010-07-05T16:13:53-07:00
Authentication code: 8675308

Reading as GrayScale

Post by 3DTOPO » 2011-01-01T20:46:55-07:00

Greetings,

I am reading in a grayscale image, but it seems like somehow the wand is reading it as an RGB image.

The reason I suspect this is because if I run this:

Code: Select all

MagickLevelImageChannel(magick_wand2, GrayChannel, (0.5f * QuantumRange), 0.6666f, (0.8f * QuantumRange));
It apparently is only doing the levels on a single channel of the image that looks different than if I run it on AllChannels. Also, it seems like the memory it is using is consistent with a 'RGB' not a 'I' map.

I have tried reading the image two ways, as a PNG:

Code: Select all

status = MagickReadImageBlob(origWand, [dataObject bytes], [dataObject length]);
And as raw pixels:

Code: Select all

status = MagickConstituteImage(origWand, width, height, "I", CharPixel, [dataObject bytes]);
Is there anyway to confirm that the image is being loaded as a grayscale image? Or can someone recommend the correct way to read a grayscale image in? I have set these as well:

Code: Select all

MagickSetImageType(origWand, GrayscaleType);
MagickSetImageColorspace(origWand, GRAYColorspace);
Are these supposed to be set before or after the image is read?

Note that if I write the wand out and open the file, it is in fact a grayscale, single channel image:

Code: Select all

status = MagickWriteImage(origWand, "out.png");
Any suggestions would be greatly appreciated!

User avatar
magick
Site Admin
Posts: 11077
Joined: 2003-05-31T11:32:55-07:00

Re: Reading as GrayScale

Post by magick » 2011-01-02T10:20:37-07:00

Internally, grayscale images are stored as RGB with the RGB channels all equal. GrayChannel is an alias for RedChannel but it only meaningful if the pixel values in RedChannel are the same as GreenChannel and BlueChannel.

Post Reply