# Gamma calibration

**URL:** <https://mworks.discourse.group/t/gamma-calibration/597>\
**Category:** Support\
**Created:** [February 7, 2014, 3:32pm UTC](https://mworks.discourse.group/t/gamma-calibration/597 "2014-02-07T15:32:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [February 7, 2014, 3:32pm UTC](https://mworks.discourse.group/t/gamma-calibration/597/1 "2014-02-07T15:32:14Z")

</div>

Hi Chris,

Looking forward to the new releases. We now have two machines running 10.8 and we are hoping to start testing mworks in on our rigs in the next couple of weeks or so.

The most important thing we will need is the ability to gamma calibrate our monitors.  
This is particularly important when we display very faint images and we need to linearize our monitors. Not sure how mworks does it now, most people don’t need except for maybe people who do gratings.

I am cc’ing my colleague Romesh on this, I’d like him to be part of the conversation since he will be able to give you details on how we do it here.

Best  
Najib

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [February 7, 2014, 3:42pm UTC](https://mworks.discourse.group/t/gamma-calibration/597/2 "2014-02-07T15:42:11Z")

</div>

Hi Najib & Romesh,

> We now have two machines running 10.8 and we are hoping to start testing mworks in on our rigs in the next couple of weeks or so.

Great! If you run in to any issues, please let me know.

> The most important thing we will need is the ability to gamma calibrate our monitors.

I had [another inquiry](https://mworks.discourse.group/discussions/questions/410) about gamma corrections recently, so maybe this is a good time to address it. If you can give me the details on what you’re doing now, I’ll figure out how to make it work in MWorks.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [February 10, 2014, 10:45pm UTC](https://mworks.discourse.group/t/gamma-calibration/597/3 "2014-02-10T22:45:06Z")

</div>

The basic manual calibration procedure is as follows:

Present a full-field red screen at one of 8 values (from rgb[0 0 0] to  
rgb[255 0 0]) in linear steps. Each stimulus should stay on the screen  
until a key press. The user will then measure the screen luminance with a  
photometer before advancing to the next stimuli. After all 8 levels have  
been presented, fit the luminance readings to the levels with an  
exponential (y=a\*x^b), where x is the level, y is the luminance and b is  
the gamma value of interest (a is a fudge factor amplitude). Do this for  
blue and green. Using these gamma values for R,B,C, Use the inverse of the  
gamma value to create a linear lookup table, which well then be used to  
translate RGB values into luminance’s.

- Romesh

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [February 12, 2014, 3:25pm UTC](https://mworks.discourse.group/t/gamma-calibration/597/4 "2014-02-12T15:25:51Z")

</div>

Hi Chris,

Below are three websites that might be useful to think about.

The photometer way is the most accurate, but there are some images that help you do an approximate job, that would be good to have for people who don’t care about low contrast stimuli.  
The image based routine is similar to what the mac provides under monitors, the “expert” calibrate option.

Best  
Najib

[http://apps.usd.edu/coglab/psyc770/USDCalibrate.html](http://apps.usd.edu/coglab/psyc770/USDCalibrate.html)

> **[measuring gamma of a display without a photometer (new...](https://www.avsforum.com/threads/measuring-gamma-of-a-display-without-a-photometer-new-study.1495985/)**
>
> New study from Vision Research , similar to an older study , and very similar to the gamma calibration images that we're familiar with .
> 
> 
> The logic is as follows:
> 
> 
> In order to assess the gamma of a display, you need to know the relationship...

[http://www.psychopy.org/general/gamma.html](http://www.psychopy.org/general/gamma.html)

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [February 12, 2014, 9:26pm UTC](https://mworks.discourse.group/t/gamma-calibration/597/5 "2014-02-12T21:26:24Z")

</div>

Hi guys,

Thanks for all the info. Let me think about this stuff for a bit and get back to you.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [February 20, 2014, 4:55pm UTC](https://mworks.discourse.group/t/gamma-calibration/597/6 "2014-02-20T16:55:33Z")

</div>

Hi guys,

I’ve been working on this and will give you a detailed update soon.

In the meantime, it looks like I need to purchase a photometer, as we don’t seem to have one in the lab. Do you have any specific recommendations on what I should get (i.e. manufacturer and model)? What do you use in your lab?

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [February 23, 2014, 2:36am UTC](https://mworks.discourse.group/t/gamma-calibration/597/7 "2014-02-23T02:36:55Z")

</div>

we use photoresearch pr650.

[http://www.photoresearch.com/current/pr650.asp](http://www.photoresearch.com/current/pr650.asp)

but it might be overkill for a simple calibration. it is important for  
calibrating color though. you might want to also try some of the cheaper  
spectrometers, like the “datacolor spyder4express” :

[http://www.bhphotovideo.com/bnh/controller/home?O=&sku=838843&Q=&is=REG&A=details](http://www.bhphotovideo.com/bnh/controller/home?O=&sku=838843&Q=&is=REG&A=details)

but the photodiode in the lab with voltmeter might be sufficient as well.  
it depends on how deep you want to go.

best  
najib

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [February 23, 2014, 5:33am UTC](https://mworks.discourse.group/t/gamma-calibration/597/8 "2014-02-23T05:33:55Z")

</div>

The PR650 was the standard spectrophotometer used in many vision labs. It’s  
now discontinued.

[http://www.photoresearch.com/current/spectroradiometers.asp](http://www.photoresearch.com/current/spectroradiometers.asp)

has a list of high-end photometers. If you can support the PR650/655 that  
would be ideal (maybe see if you can barrow one), as it’s the one many of  
us at NYU use.

- Romesh

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [March 3, 2014, 6:59pm UTC](https://mworks.discourse.group/t/gamma-calibration/597/9 "2014-03-03T18:59:56Z")

</div>

Hi all,

(I’ve added Lindsey Glickfeld to this discussion, as she asked a [related question](https://mworks.discourse.group/discussions/questions/410) not long ago and got a much less detailed response from me.)

After spending a fair amount of time banging my head against the basics of color management and its implementation under OS X, I think I have a good understanding of how MWorks approaches these issues now and how we can improve things in the future.

## What we do now

At present, MWorks does nothing to alter or correct color values provided by the user. More specifically, it performs neither full [color matching](https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/csintro/csintro_conversion/csintro_conversion.html#//apple_ref/doc/uid/TP30001148-CH223-SW1) nor simple gamma correction on input colors. Rather, input colors, whether read from image files or specified directly as RGB values, are implicitly treated as belonging to the color space of the _display_.

This has some unfortunate implications. For one thing, with a typical gamma-2.2 display, the default “medium gray” background (rgb(0.5, 0.5, 0.5)) will produce a luminance significantly less than 50% of maximum. Also, embedded ICC profiles in images are completely ignored, meaning, for example, that MWorks fails its own version of [this test](http://www.color.org/version4html.xalter) quite badly. (On the other hand, sRGB-encoded images should look more or less OK on a typical display, although [color blending may be inaccurate](http://ninedegreesbelow.com/photography/linear-gamma-blur-normal-blend.html).)

On the bright side, MWorks’ inaction means you can use _other_ software to alter the display configuration without MWorks mucking things up. For example, you could use [Gamma Control](http://michelf.ca/projects/gamma-control/) to alter the display’s gamma correction curve on the fly. Alternatively, to accomplish Najib and Romesh’s goal of linearizing the display, you could calibrate your display to gamma 1.0, store the calibration in an ICC profile, and assign the profile to the display in System Preferences.

## What we can/should do in the future

There are a number of ways we could improve MWorks’ handling of color. Some are straightforward, while others require additional thought and discussion.

### Perform color matching on image files

This seems like a no-brainer: Input images should be converted in to the color space of the stimulus display window. The pervasive awareness of color management throughout OS X and its APIs make doing this simple and straightforward.

### Render visual stimuli in a linear color space

As mentioned previously, some operations in OpenGL require linear color to work correctly, so internally MWorks should perform all rendering in a linear color space.

A related but independent issue is the color space of explicitly specified RGB values. I imagine most users would expect rgb(0.5, 0.5, 0.5) to mean “gray at 50% max luminance”, so we should probably treat explicit RGB values as belonging to a linear color space, too. However, this approach has its own potentially negative implications. For example, when you use the standard OS X color picker widget, the RGB values you get out are in the system’s “Generic RGB” color space, which has a gamma of 1.8. If you then feed these values to MWorks, they’ll be interpreted as belonging to a gamma-1.0 color space and will therefore appear brighter than they did in the color picker.

There’s also the question of _which_ linear color space to use. If the user is concerned with matching colors to external standards, then we need a color space with a standardized gamut (probably a “linearized” version of sRGB). On the hand, if it’s more important that the user be able to exercise the full gamut of the display, then we should use a linearized version of the display’s color space (as defined by its ICC profile), with the downside being that the actual colors shown will be device dependent.

### Perform calibration/correction within MWorks

In addition to respecting the system-wide display color profile, MWorks could also provide ways to alter the display’s calibration.

Personally, I don’t think MWorks should be in the business of performing full-fledged display calibration and profiling. Other software packages (some [open source](http://www.argyllcms.com/)) already do that job, and MWorks can (and should) make full use of the ICC profiles they generate.

However, we may want to make it easier for users to make display changes outside the scope of standard calibration and ICC profiles. For example, while MWorks would play no role in _creating_ the custom gamma correction tables Lindsey needs for her use case, it could provide a means of loading them (from a file) at run time. Although the loading step could also be performed external to MWorks, clearly it’s easier on the user for MWorks to do so itself.

## Getting back to the original question

Now that we’ve done a high-level survey of color issues and MWorks, let’s return to the specific question asked by Najib and Romesh: How can you gamma calibrate your monitor in conjunction with MWorks?

At present, MWorks won’t help you, but it won’t get in your way either. You have to calibrate yourself, using the tools of your choice, and apply the resulting calibration via an installed ICC profile or something like [Gamma Control](http://michelf.ca/projects/gamma-control/).

In the future, to make this process a little simpler, we could give MWorks the ability to load predefined gamma curves itself.

Alternatively, if MWorks were updated to (1) respect the ICC profiles embedded in image files and (2) treat explicit RGB color values as belonging to a linear color space, then all that would be required of the user would be to (a) provide appropriately linear input images/colors and (b) ensure that the display is accurately characterized by its assigned ICC profile. In that case, MWorks would ensure that the linear input colors are appropriately converted to the display’s color space.

For maximum flexibility, we should probably implement _both_ of the preceding options.

Thus ends my treatise on color handling in MWorks. Please share your thoughts on the various issues and proposed paths forward.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 11:20pm UTC](https://mworks.discourse.group/t/gamma-calibration/597/10 "2022-07-19T23:20:29Z")

</div>


