Page 1 of 1

MagickExportImagePixels for BiLevel image

Posted: 2014-04-11T02:54:23-07:00
by sthustfo
Greeting.

I have a PNG image that I have quantized to BievelType. Now I would like to get access to this raw image. so I use MagickExportImagePixels() api to get access to this raw image. However, I am not sure what should be the map and the storage type? If I use "I" for map (grayscale) and storage as PixelChar, the api crashes because it expects the allocated memory to be (width * height) bytes whereas I am providing (width * height)/8 bytes.

Any suhhestions on how to use MagickExportImagePixels() api to extract Bilevel image?

Re: MagickExportImagePixels for BiLevel image

Posted: 2014-04-11T13:25:37-07:00
by SlasherZet

Code: Select all

typedef enum
{
  UndefinedPixel,
  CharPixel,
  DoublePixel,
  FloatPixel,
  IntegerPixel,
  LongPixel,
  QuantumPixel,
  ShortPixel
} StorageType;
You can provide one of those for the storage. Consider the size of the pixels with each storage type.
The formula should be (number of channels)*(StorageType size). So if you want only intensity (or "I" as you say), that means (number of channels)=1.
For the storage type, going from smallest to biggest, the sizes should be following:
CharPixel = 1 byte for each channel.
ShortPixel = 2 bytes for each channel.
IntegerPixel = FloatPixel = 4 bytes for each channel.
LongPixel = DoublePixel = 8 bytes for each channel.
QuantumPixel varies and should be equal to your image magick compilation specs. So if you compiled with quantum depth 16, it will be 2 bytes. If you compiled with quantum depth 8, it will be 1 byte.

This means that if you want to export the "I" intensity of (width * height) pixels in CharPixels, you need to allocate (width * height * number of channels * StorageType size) = (width * height * 1 * 1) bytes of memory, not (width * height)/8!

If you're trying to get 1 pixel on 1 bit, I do not think that is possible, ImageMagick will scale the pixels to fit on the specified StorageType, the smallest amount of memory is 1 byte for CharPixel with bit 0 being 0 and bit 1 being 255.

Re: MagickExportImagePixels for BiLevel image

Posted: 2014-04-13T22:35:32-07:00
by sthustfo
If am trying to get 1 bit per 1 pixel (basically monochrome bilevel) image. And since there was no StorageType for Bilevel, I tried to use PixelChar.

If i set the image type to BilevelType using MagickSetImageType() and then call MagickWriteImage(), then Bilevel image is generated. Any reason why a StorageType for 1 bit (bilevel) is not specified? Is there any other way to get access to Bilevel data now?

Thanks.

Re: MagickExportImagePixels for BiLevel image

Posted: 2014-04-14T11:24:28-07:00
by SlasherZet
Afaik you can't extract 1 bit pixel data from the image with ImageMagick, it will always be scaled the the quantum format you choose. There are other libraries that can do that, like LibPNG.
Someone correct me if I'm wrong.

Re: MagickExportImagePixels for BiLevel image

Posted: 2014-04-17T20:28:43-07:00
by sthustfo
@SlasherZet Thanks for the clarification. So I suppose, adding a new bilevel type to the StorageType is required support for which is not available now.