OpenEXR to ImageMagick color problem

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
Stalkerx777
Posts: 2
Joined: 2015-03-30T00:37:58-07:00
Authentication code: 6789

OpenEXR to ImageMagick color problem

Post by Stalkerx777 » 2015-03-30T02:40:12-07:00

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

snibgo
Posts: 12437
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: OpenEXR to ImageMagick color problem

Post by snibgo » 2015-03-30T03:17:38-07:00

Can't you do it at the command line? See http://www.imagemagick.org/Usage/formats/#rgb
snibgo's IM pages: im.snibgo.com

User avatar
dlemstra
Posts: 1588
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: OpenEXR to ImageMagick color problem

Post by dlemstra » 2015-03-30T03:58:10-07:00

How are you reading the OpenEXR image and can you share that image? And are you using an ImageMagick build that has HDRI enabled?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

Stalkerx777
Posts: 2
Joined: 2015-03-30T00:37:58-07:00
Authentication code: 6789

Re: OpenEXR to ImageMagick color problem

Post by Stalkerx777 » 2015-03-30T06:13:25-07:00

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);
	}
}

Post Reply