Skip to content

Commit

Permalink
put checkerboards in one script and removed padding+doubling from fun…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
LynnSchmittwilken committed Jun 30, 2022
1 parent 938faaf commit 042dae1
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 193 deletions.
9 changes: 3 additions & 6 deletions stimuli/illusions/__init__.py
@@ -1,15 +1,12 @@
from .benary_cross import benarys_cross
from .bullseye import bullseye_stimulus
from .checkerboard_contrast_contrast import (
checkerboard_contrast_contrast_effect,
)
from .checkerboard_sbc import checkerboard_contrast
from .checkerboards import *
from .cornsweet import cornsweet
from .cube import cube_illusion
from .disc_and_ring import disc_and_ring
from .dungeon import dungeon_illusion
from .grating import grating_illusion
from .grating_induction import grating_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
105 changes: 0 additions & 105 deletions stimuli/illusions/checkerboard_contrast_contrast.py

This file was deleted.

82 changes: 0 additions & 82 deletions stimuli/illusions/checkerboard_sbc.py

This file was deleted.

126 changes: 126 additions & 0 deletions stimuli/illusions/checkerboards.py
@@ -0,0 +1,126 @@
import numpy as np
from stimuli.utils import degrees_to_pixels
from stimuli.components import checkerboard


def contrast(
ppd=30,
board_shape=(8, 8),
check_size=1.0,
target_indices=((3, 2), (5, 5)),
extend_targets=False,
vcheck1=0.0,
vcheck2=1.0,
vtarget=0.5,
):
"""
Checkerboard Contrast
Parameters
----------
ppd : int
pixels per degree (visual angle)
board shape : (int, int)
number of checks per board in y, x direction
check_size : float
size of a check in degrees visual angle
targets_indices : tuple of (int, int)
tuple with check-indices (row, col)
extend_targets : bool
cross targets instead of single-check targets
vcheck1 : float
first check value
vcheck2 : float
other check value
vtarget: float
target value
Returns
-------
A stimulus dictionary with the stimulus ['img'] and target mask ['mask']
"""

check_size_px = degrees_to_pixels(check_size, ppd)
nchecks_height, nchecks_width = board_shape

img = checkerboard(ppd, board_shape, check_size, vcheck1, vcheck2)
mask = np.zeros(img.shape)

for i, coords in enumerate(target_indices):
ypos = int(coords[0]*check_size_px)
xpos = int(coords[1]*check_size_px)
img[ypos:ypos+check_size_px, xpos:xpos+check_size_px] = vtarget
mask[ypos:ypos+check_size_px, xpos:xpos+check_size_px] = i + 1

if extend_targets:
for i, coords in enumerate(target_indices):
for idx in [(-1, 0), (0, 1), (1, 0), (0, -1)]:
ypos = int(coords[0]*check_size_px + idx[0]*check_size_px)
xpos = int(coords[1]*check_size_px + idx[1]*check_size_px)
img[ypos:ypos+check_size_px, xpos:xpos+check_size_px] = vtarget
mask[ypos:ypos+check_size_px, xpos:xpos+check_size_px] = i + 1
return {"img": img, "mask": mask}


def contrast_contrast(
ppd=10,
board_shape=(4, 6),
check_size=1.0,
target_shape=(2, 3),
vcheck1=0.0,
vcheck2=1.0,
tau=0.5,
alpha=0.2,
):
"""
Contrast-contrast effect on checkerboard with square transparency layer.
Parameters
----------
ppd : int
pixels per degree (visual angle)
board shape : (int, int)
number of checks in y, x direction
check_size : float
size of a check in degrees visual angle
targets_shape : (int, int)
number of checks with transparecny in y, x direction
vcheck1 : float
first check value
vcheck2 : float
other check value
tau : float
tau of transparency (i.e. value of transparent medium)
alpha : float
alpha of transparency (i.e. how transparant the medium is)
Returns
-------
A stimulus dictionary with the stimulus ['img'] and target mask ['mask']
"""

check_size_px = degrees_to_pixels(check_size, ppd)
nchecks_height, nchecks_width = board_shape

img = checkerboard(ppd, board_shape, check_size, vcheck1, vcheck2)
mask = np.zeros(img.shape)

idx = np.zeros(img.shape, dtype=bool)
tposy = (img.shape[0] - target_shape[0]*check_size_px) // 2
tposx = (img.shape[1] - target_shape[1]*check_size_px) // 2
idx[tposy:tposy+target_shape[0]*check_size_px, tposx:tposx+target_shape[1]*check_size_px] = True
img[idx] = alpha * img[idx] + (1 - alpha) * tau
mask[idx] = 1
return {"img": img, "mask": mask}


if __name__ == "__main__":
import matplotlib.pyplot as plt
from stimuli.utils import plot_stimuli

stims = {
"Checkerboard contrast": contrast(),
"Checkerboard contrast contrast": contrast_contrast(),
}
ax = plot_stimuli(stims, mask=False)
plt.show()

0 comments on commit 042dae1

Please sign in to comment.