GratingStim.opacity same as Michelson contrast?

Hi all,

I’m using

GratingStim

for the creation of Gabor patches. To manipulate the visibility I use the opacity attribute. I’m interested in the equation behind this. Is opacity the same as Michelson contrast, which is defined as (I_max - I_min)/(I_max + I_min), where l_max and l_min refers to the maximum and minimum luminance (according to the Wikipedia link below)?

Thanks - rbr

Using the contrast parameter for the grating instead of its opacity parameter would make that a lot easier.

Why are you trying to set Michelson contrast using the opacity parameter?

If there is some reason that you need to use the opacity parameter, then you could find the Michelson contrast buy substituting the result of the opacity calculation into the Michelson equation.

- Allen

1 Like

Dear Allen,

Thank you for the quick reply.

I had no particular reason to use the “opacity” instead of “contrast” parameter. According to the Psychopy website “contrast” and “opacity” can both be used to control contrast and “opacity” seemed easier to control for me:

Set the contrast of the stimulus, i.e. scales how far the stimulus deviates from the middle grey. You can also use the stimulus opacity to control contrast, but that cannot be negative.

I guess I should clarify why I’m asking my question. I’m not particularly interested in Michelson contrast as such. I’m currently writing a paper about my experiment and would like to indicate what we did exactly to manipulate our Gabor patches. I thought that Michelson contrast and opacity may be the same.

Do you think there is a more straightforward way of expressing (using an equation) what opacity does exactly? I’d be happy to substitute opacity into the Michelson equation. Which parameters of the GratingStim would be required for that?

Thanks - rbr

@rbr,

Were you able to solve your question ? I too would like to know.

Thanks,
D

Hello,

I would also like to know the answer to this question! (i.e., how to convert between the stimOpacity parameter and contrast).

many thanks,

R

In most cases, yes, you can treat opacity as a way to set Michelson contrast but two caveats:

  • it’s really a multiplier: the contrast of your stimulus is ultimately governed by a multiplication of the color, the contrast value, the opacity and the inherent contrast of the texture (although if you’re using the built-in sin texture then that is 1)
  • opacity (unlike the contrast parameter itself) is making a weighted average of the stimulus and whatever is behind it. If you set opacity = 0.2 then each pixel will be 0.2xStimulus and 0.8xbackground color. So the contrast also now depends on what is behind the stimulus. That’s assuming your window has blend mode = ‘avg’
  • if you need to combine multiple gratings then understanding the weighted average for the pixels gets especially complicated, so then I’d really recommend you use a blend mode = ‘add’

I hope that helps

1 Like

Dear Jon,

This helps tremendously–thank you!

I have a (possibly naive) follow up question:
–To what extend does the magnitude of the impact of the opacity setting on the image contrast depend on the specific monitor?

The reason I ask is because my original plan was to compute the obtained contrast using the formula you mentioned above (in RGB values, prior to computing RMS contrast).

But a colleague raised the concern that the “obtained” contrast with an opacity parameter might not be the same across different monitors (so an alternative way would be to first convert everything to luminance values, and then proceed as above).

Thank you so much again!

R.