Page 1 of 1

greyscale EXR writing, Magick++

Posted: 2015-11-26T07:27:41-07:00
by greenmuzz
I've got data captured from a machine vision camera in memory, which is easiest stored as a float image and ideally saved in a suitable HDR format such as EXR. The data is greyscale however, and I'm finding that when I save the image with Magick++ it gets saved as RGB. Any help would be appreciated to force this to save as single channel exr file.

This is a very basic code sample that produces the behaviour:

Code: Select all

#include <Magick++.h>
#include <vector>

int main(void)
{
        // fake image for testing. Equivalent to my data - float array with known width/height
        unsigned w,h;
        w = 240;
        h = 240;

        std::vector<float> i;
        i.assign( 240*240, 0.5 );

        // float array directly into magick image
        Magick::Image mimg(w, h, "I", Magick::FloatPixel, &i[0]); // 'I' for single channel intensity data, right?
        mimg.type( Magick::GrayscaleType );     // didn't seem to help at all.
        mimg.write("test.exr");
}
And this shows identify as run on the output file:


person@machine:~/src$ identify test.exr
test.exr EXR 240x240 240x240+0+0 16-bit RGB 350KB 0.000u 0:00.000

Re: greyscale EXR writing, Magick++

Posted: 2015-11-26T07:31:08-07:00
by magick
Use defineValue() and set "exr:color-type" to "G".

Re: greyscale EXR writing, Magick++

Posted: 2015-11-26T08:09:55-07:00
by greenmuzz
Thanks, that seems to have almost done the trick. The file size is 1/3 what it was, although the output of identify still says RGB, and once loaded the Image reports as a TrueColorType image. I'm beginning to suspect that this might be because of either OpenEXR, or the way Magick uses OpenEXR. Oh, and I used 'Y' instead of 'G' after your suggestion lead me through a few more links.