# How to specify the brightness of stimuli

**URL:** <https://psychtoolbox.discourse.group/t/how-to-specify-the-brightness-of-stimuli/3517>\
**Category:** Programming Help\
**Created:** [November 16, 2020, 6:28pm UTC](https://psychtoolbox.discourse.group/t/how-to-specify-the-brightness-of-stimuli/3517 "2020-11-16T18:28:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cai](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@Cai](https://psychtoolbox.discourse.group/u/Cai)\
**Post date:** [November 16, 2020, 6:28pm UTC](https://psychtoolbox.discourse.group/t/how-to-specify-the-brightness-of-stimuli/3517/1 "2020-11-16T18:28:57Z")

</div>

Hi, I am using MATLAB R2020a on a MacOS. I am currently coding a task that involves a change in brightness of 3 simultaneously presented ‘spots’ on the screen whereby I can specify the brightness of the stimuli based on input from a Gaussian distribution. That is, a number is drawn from a Guassian distribution and a particular stimulus brightness is presented based on that. However, I am yet to find any functions/ code that can do this. Any help would be greatly appreciated

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [November 16, 2020, 7:38pm UTC](https://psychtoolbox.discourse.group/t/how-to-specify-the-brightness-of-stimuli/3517/2 "2020-11-16T19:38:02Z")

</div>

From your question, I suggest you start with some tutorials to learn  
the basic of PTB, then you’ll see how to draw stimuli at different RGB  
values, to create different brightnesses. Peter Scarfe’s tutorials are  
probably a good start

---

<div class="post-metadata">

**Author:** ![Cai](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@Cai](https://psychtoolbox.discourse.group/u/Cai)\
**Post date:** [November 16, 2020, 11:16pm UTC](https://psychtoolbox.discourse.group/t/how-to-specify-the-brightness-of-stimuli/3517/3 "2020-11-16T23:16:16Z")

</div>

Hi, thank you for your suggestion. I have referred to Peter Scarfe’s tutorials before and coded a whole experiment with them. While I understand how to specify different RGB values to generate different coloured stimuli, I am yet to find anything that can alter brightness via a graded scale. Is there any tutorial in particular that illustrates this?

---

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [November 17, 2020, 12:47am UTC](https://psychtoolbox.discourse.group/t/how-to-specify-the-brightness-of-stimuli/3517/4 "2020-11-17T00:47:52Z")

</div>

Brightness is a subjective value, and therefore you need to use some sort of psychophysical measurement to guide what physical RGB values you need. If you look at papers that study “Brightness” they often use simultaneous contrast, where the brightness of a patch of consistent luminance (e.g. 20cd/m²) is varied using a surround of varying luminances (e.g. papers by Paradiso or Shapley and colleagues as an example).

You should have linearised your monitor first using a [spectro]photometer so you should have your minimum and maximum luminance for each of your three colour channels, you can use this to work out what the physical luminance is for any value, and then it really depends what you are trying to achieve by varying “brightness”.

---

<div class="post-metadata">

**Author:** ![Cai](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@Cai](https://psychtoolbox.discourse.group/u/Cai)\
**Post date:** [November 24, 2020, 10:56pm UTC](https://psychtoolbox.discourse.group/t/how-to-specify-the-brightness-of-stimuli/3517/5 "2020-11-24T22:56:09Z")

</div>

Hi, thank you for your suggestion. Apoplogies, but I think I worded my questio incorrectly. What I meant was that I would like to vary the grayscale in a graded manner to produce images of different grayscale values which are easily distinguishable from one another. For instance, is there a way of doing this using colour vector values? Thanks

---

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [November 25, 2020, 3:12am UTC](https://psychtoolbox.discourse.group/t/how-to-specify-the-brightness-of-stimuli/3517/6 "2020-11-25T03:12:32Z")

</div>

You first need to ensure that you have used a photometer to linearise your display, and also that your display is using a normal whitepoint and color setting (i.e. standard monitor calibration). A simple linearisation only linearises from [0 0 0]RGB to [1 1 1]RGB, but you may also want to separately linearise the R, G and B channels. You **_must_** do this, otherwise the gamma curve of your display will distort the values you add or subtract to make lighter or darker stimuli.

Use `PsychDefaultSetup(2)` at the start of your script, so that you operate in a 0 - 1 floating point RGB mode. You may see legacy code using integer 0 - 255 which assumes an 8-bit display, but it is not recommended to use this as any internal computations that PTB performs will be limited.

Grey is defined as equal values for R, G and B. so in PTB if you want to make a mid-grey square you specify this as `[0.5 0.5 0.5]`. To make it “brighter” add the same amount to R, G, & B, i.e. `[0.6 0.6 0.6]`.
