Specifying gamma when reading pixel data

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
knr
Posts: 8
Joined: 2019-01-21T02:57:04-07:00
Authentication code: 1152

Specifying gamma when reading pixel data

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Specifying gamma when reading pixel data

Post by snibgo »

The "Image" structure has an element "gamma", which you can set.
snibgo's IM pages: im.snibgo.com
knr
Posts: 8
Joined: 2019-01-21T02:57:04-07:00
Authentication code: 1152

Re: Specifying gamma when reading pixel data

Post by knr »

colorImage has a Gamma property, but it is read only
and PixelStorageSettings has no Gamma setting
FYI: myImageData is a byte array
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Specifying gamma when reading pixel data

Post 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.
snibgo's IM pages: im.snibgo.com
knr
Posts: 8
Joined: 2019-01-21T02:57:04-07:00
Authentication code: 1152

Re: Specifying gamma when reading pixel data

Post 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?
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Specifying gamma when reading pixel data

Post 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.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
knr
Posts: 8
Joined: 2019-01-21T02:57:04-07:00
Authentication code: 1152

Re: Specifying gamma when reading pixel data

Post 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.
Post Reply