# Reduce contrast towards the centre of grating stimulus

Hi everyone,

I am trying to create an annulus stimulus (a gabor with a blank circle in the middle), where the contrast reduces at both the outer and inner edges of the annulus.

Currently I am using a gratingstim with a gauss mask, which works to reduce the contrast at the outer edges, and a circle (shapestim) in the centre, drawn on top of the grating, to make it an annulus. However, I would also like to be able to reduce the contrast towards the centre of the gratingstim, so that there isn’t such a prominent edge transitioning from the grating to the centre of the annulus.

Ideally, I would also be able to choose the point at which the contrast starts decreasing (e.g., grating contrast decreases linearly to 0 over the outer and inner 0.5° radius of the annulus).

Any suggestions would be greatly appreciated!

I tried the following approach. I created a grid with values that represent the distance to the center of the grid (`center_x` and `center_y`). Using those distances, I then computed a gaussian function with a peak at `d_0`. The width can be configured using the `c` parameter. Note that everything is defined here in pixels. Hope this provides some inspiration, I think the main idea is to have a grid with distance values, and you then compute some kind of function based on those distances

``````# Stimulus parameters
width = 200
height = 200

center_x = 100
center_y = 100

d_0 = 50
c = 20

# Create a grid to calculate distances
x,y  = np.meshgrid(np.arange(0, height), np.arange(0, width))
d = ((x - center_x)**2 + (y - center_y)**2)**0.5

# Calculate the Gaussian function
fx = np.exp(- ((d - d_0)**2)/c**2 )

# Normalize between -1 and 1
fx_final = (2 * fx) - 1
``````

This produces the following mask: To display the grating, set the mask property as follows:

``````myGrat = visual.GratingStim(win, sf=0.01, tex='sin', mask=fx_final, size = [width, height])  # circular grating
``````
1 Like

Thank you so much!!