Page 1 of 1

Reading as GrayScale

Posted: 2011-01-01T20:46:55-07:00
by 3DTOPO
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!

Re: Reading as GrayScale

Posted: 2011-01-02T10:20:37-07:00
by magick
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.