Skip to content

Commit

Permalink
Incorporate grating_induction
Browse files Browse the repository at this point in the history
  • Loading branch information
JorisVincent committed Dec 6, 2022
1 parent 4987c4a commit 9b6dfe2
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 100 deletions.
1 change: 0 additions & 1 deletion stimuli/illusions/__init__.py
Expand Up @@ -7,7 +7,6 @@
from .cube import cube_illusion
from .dungeon import dungeon_illusion
from .grating import *
from .grating_induction import *
from .hermann import hermann_grid
from .mondrians import corrugated_mondrians
from .rings import ring_stimulus
Expand Down
80 changes: 80 additions & 0 deletions stimuli/illusions/grating.py
@@ -1,6 +1,7 @@
import itertools

import numpy as np
from scipy.ndimage import gaussian_filter

from stimuli.components import rectangle
from stimuli.components import square_wave as square_wave_component
Expand Down Expand Up @@ -340,6 +341,84 @@ def grating_grating_shifted(
return stim


def grating_induction(
visual_size=(10, 10),
ppd=40,
grating_frequency=0.5,
target_height=0.5,
blur=5,
intensity_bars=(0.0, 1.0),
intensity_target=0.5,
period="ignore",
):
"""
Grating induction illusions
Parameters
----------
visual_size : float or (float, float)
size of the image in degrees visual angle
ppd : int
pixels per degree (visual angle)
grating_frequency : float
frequency of the grid in cycles per degree visual angle
target_height : float
height of the target in degrees visual angle
blur : float
amount of blur to apply
intensity_bars : (float, float)
intensity values of bars
intensity_target : float
intensity value of targets
period : string in ['ignore', 'full', 'half']
specifies if the period of the wave is considered for stimulus dimensions.
'ignore' simply converts degrees to pixels
'full' rounds down to guarantee a full period
'half' adds a half period to the size 'full' would yield.
Default is 'ignore'.
Returns
-------
A stimulus dictionary with the stimulus ['img'] and target mask ['mask']
"""

stim = square_wave(
visual_size=visual_size,
ppd=ppd,
frequency=grating_frequency,
intensity_bars=intensity_bars,
period=period,
)
img = stim["img"]
height, width = stim["shape"]
theight = int(target_height * stim["ppd"].vertical)

tstart = int(height) // 2 - theight // 2
tend = tstart + theight

low = np.minimum(intensity_bars[0], intensity_bars[1])
high = np.maximum(intensity_bars[0], intensity_bars[1])
mask = np.zeros((height, width))
mask[tstart:tend, :] = (img[tstart:tend, :] - low) / (high - low) + 1

img = gaussian_filter(img, blur)
img[tstart:tend, :] = intensity_target

params = {
"shape": img.shape,
"visual_size": np.array(img.shape) / ppd,
"ppd": ppd,
"grating_frequency": grating_frequency,
"intensity_bars": intensity_bars,
"intensity_target": intensity_target,
"target_height": target_height,
"blur": blur,
"period": period,
}

return {"img": img, "mask": mask.astype(int), **params}


if __name__ == "__main__":
import matplotlib.pyplot as plt

Expand Down Expand Up @@ -384,6 +463,7 @@ def grating_grating_shifted(
target_indices=(13, 18),
**large_grating_params,
),
"Grating induction": grating_induction(),
}

plot_stimuli(stims, mask=False)
Expand Down
98 changes: 0 additions & 98 deletions stimuli/illusions/grating_induction.py

This file was deleted.

2 changes: 1 addition & 1 deletion stimuli/papers/RHS2007.py
Expand Up @@ -884,7 +884,7 @@ def grating_induction(ppd=PPD, pad=True):
"period": "ignore",
}

stim = illusions.grating_induction.grating_illusion(
stim = illusions.grating.grating_induction(
visual_size=(height, width),
**params,
)
Expand Down

0 comments on commit 9b6dfe2

Please sign in to comment.