Page 1 of 1

OpenEXR to ImageMagick color problem

Posted: 2015-03-30T02:40:12-07:00
by Stalkerx777
Hi,

I have a pointer to RGBA data, which i've read from openEXR file.

Code: Select all

// Rgba is a struct of halfs(openexr float type) r,g,b,a. (i.e sizeof(half) == sizeof(float))
Array2D<Rgba> pixels;
Magick::Image im(/*size*/);
im.magick("RGBA");
Magick::Blob blob(&pixels[0][0], (width * height) * sizeof(Rgba));
im.read(blob);
im.magick("JPEG");
im.write("outfile.jpeg");


Everything is ok, but the colors are grayed out and not properly clumped. OpenEXR data is float dynamic range values. ImageMagick - 16 bit.
My first approach was iterating through pixels array, remap values to 0 - 1 and using image.pixelColor() method to set modified values. It gives me proper pixel values, but is very slow, so i'm trying with Blob data.

Could you please tell me how can i remap values within ImageMagick. I see image.level() method, but it looks like after image.read(blob) all pixels values are already clumped.
This is what i get. I don't know why this is so washed out. It should be colored.
Image

Re: OpenEXR to ImageMagick color problem

Posted: 2015-03-30T03:17:38-07:00
by snibgo
Can't you do it at the command line? See http://www.imagemagick.org/Usage/formats/#rgb

Re: OpenEXR to ImageMagick color problem

Posted: 2015-03-30T03:58:10-07:00
by dlemstra
How are you reading the OpenEXR image and can you share that image? And are you using an ImageMagick build that has HDRI enabled?

Re: OpenEXR to ImageMagick color problem

Posted: 2015-03-30T06:13:25-07:00
by Stalkerx777
snibgo wrote:Can't you do it at the command line? See http://www.imagemagick.org/Usage/formats/#rgb
No, i can't use convert command, i need to do some image processing in c++
dlemstra wrote:How are you reading the OpenEXR image and can you share that image?
This is openEXR converted to JPEG with "3rd party tool":
Image
And are you using an ImageMagick build that has HDRI enabled?
I'm using ImageMagick-6.9.0-Q16.
I have compiled openEXR library from source:

Code: Select all

RgbaInputFile file(filepath.c_str());
Array2D<Rgba> pixels(height, width);
pixels.resizeErase(height, width);
file.setFrameBuffer(&pixels[0][0], 1, width);
file.readPixels(dw.value().min.y, dw.value().max.y);
Now pixels contains Rgba structs with floating point values > 1 and < 1. I can loop through an array and clamp them. But when ImageMagick read this data as a Magick::Blob, colors got lost.

But if do something like this, everything is fine, except this is very slow:

Code: Select all

Magick::Image blank_image(Magick::Geometry(width, height), Magick::Color("black"));
auto color = Magick::ColorRGB();
for (int i = 0; i < height; i++){
	for (int j = 0; j < width; j++){
		float rvalue = clamp(float(pixels[i][j].r), 0.0f, 1.0f);
		float gvalue = clamp(float(pixels[i][j].g), 0.0f, 1.0f);
		float bvalue = clamp(float(pixels[i][j].b), 0.0f, 1.0f);

		color.red(rvalue);
		color.green(gvalue);
		color.blue(bvalue);
		blank_image.pixelColor(j, i, color);
	}
}