Page 1 of 1

[Magick++/ImageCore] Get colorspace attribute from file

Posted: 2011-02-23T17:14:07-07:00
by laurenthnd
Hello,

I would like to get some information about an image stored in a file using Magick++ or ImageCore interfaces.
If I do something like:

Code: Select all

Image image("myimage.pgm");
I can get the dimensions using:

Code: Select all

image.rows();
image.height();
However, the colorspace is set by default to RGB, whereas pgm images are always grayscale.

Therefore, my question is: How can I retrieve from the file:
- colorspace
- bit depth
Using Magick++ or ImageCore.

For instance, in the case of a pgm image, it should returns:
- colorspace: GRAYSCALE
- bit depth: A VALUE IN [1,16]

Many thanks in advance.


P.S.:
I know that I can do that using the identify tool in the command line. But how can I make use of the ImageMagick API for this purpose (avoiding the high-level ImageWand interface). I've tried to use the ImageInfo structure of ImageCore without success:

Code: Select all

ExceptionInfo *exception;
Image *image;
ImageInfo *image_info;
// Initialize the image info structure and read an image.
MagickCoreGenesis(*argv,MagickTrue);
exception=AcquireExceptionInfo();
image_info=AcquireImageInfo();
(void) strcpy(image_info->filename,"myimage.pgm");
image=ReadImage(image_info,exception);
// HERE: the image_info structure does not contain the colorspace "corresponding" to the content of the file

Re: [Magick++/ImageCore] Get colorspace attribute from file

Posted: 2011-02-23T18:22:14-07:00
by magick
Try image.type().

Re: [Magick++/ImageCore] Get colorspace attribute from file

Posted: 2011-02-24T08:40:05-07:00
by laurenthnd
Thanks, this indeed works as the depth() function does.
However, I consider that this is a bit weird. In a certain way, imageType is used for loading while colorSpace is used for saving. Do you know why different enumerations are considered for loading and saving?
Thanks and cheers