Page 1 of 1

Specifying gamma when reading pixel data

Posted: 2019-01-21T04:59:07-07:00
by knr
I have some RGB images with no gamma applied.
When I try to read the images like this

Code: Select all

PixelStorageSettings pixelStorageSettings = new PixelStorageSettings(100, 100, StorageType.Short, PixelMapping.BGR);
var colorImage = new MagickImage(myImageData, pixelStorageSettings);
The resulting colorImage says gamma is 0.4545.

How do I setup the pixel read so the image know it is gamma=1 data.

Re: Specifying gamma when reading pixel data

Posted: 2019-01-21T06:27:59-07:00
by snibgo
The "Image" structure has an element "gamma", which you can set.

Re: Specifying gamma when reading pixel data

Posted: 2019-01-21T07:21:24-07:00
by knr
colorImage has a Gamma property, but it is read only
and PixelStorageSettings has no Gamma setting
FYI: myImageData is a byte array

Re: Specifying gamma when reading pixel data

Posted: 2019-01-21T07:39:14-07:00
by snibgo
I don't think you can set the gamma before reading the image.

At the command line, "-set gamma 1.0" changes the gamma setting after the image has been read. Sorry, I don't know how to do that in Magick.NET.

Re: Specifying gamma when reading pixel data

Posted: 2019-01-25T01:46:45-07:00
by knr
There exists an option to set ColorSpace in ReadSettings as shown below:

Code: Select all

PixelStorageSettings pixelStorageSettings = new PixelStorageSettings(100, 100, StorageType.Short, PixelMapping.RGB);
pixelStorageSettings.ReadSettings.ColorSpace = ColorSpace.RGB;
pixelStorageSettings.ReadSettings.ColorType = ColorType.TrueColor;
var colorImage = new MagickImage(myImageData, pixelStorageSettings);
But the resulting image still has has

Code: Select all

colorImage.ColorSpace == sRGB
and not RGB.
I assume sRGB is RGB with standard gamma and RGB is RGB with no gamma.
Is this a bug or is the ReadSettings not intended to be used for this?

Re: Specifying gamma when reading pixel data

Posted: 2019-01-25T15:37:49-07:00
by dlemstra
Not all read settings can/will be used when reading pixels, the Colorspace is one of them. If you want to do the same thing as "-gamma" you will need to call the GammaCorrect method of the MagickImage after you read it.

Re: Specifying gamma when reading pixel data

Posted: 2019-01-29T06:21:03-07:00
by knr
Ok.

If it is not posible to specifying gamma of the pixel data I read - how do I change colorspace with out ImageMagick first removes the gamma?

From: https://imagemagick.org/script/command-line-options.php
Note, ImageMagick assumes the sRGB colorspace if the image format does not indicate otherwise. For colorspace conversion, the gamma function is first removed to produce linear RGB.
If a change colorspace on my pixeldata that do not have gamme applied I assume I get a wrong colorspace conversion.