Skip to content

Commit

Permalink
Autoformat
Browse files Browse the repository at this point in the history
  • Loading branch information
JorisVincent committed Jun 14, 2022
1 parent 8e49d99 commit f1b0e05
Show file tree
Hide file tree
Showing 14 changed files with 309 additions and 190 deletions.
23 changes: 15 additions & 8 deletions stimuli/illusions/benary_cross.py
Expand Up @@ -40,8 +40,12 @@ def benarys_cross(
A stimulus object
"""


cross_top_px, cross_bottom_px, cross_left_px, cross_right_px = degrees_to_pixels(cross_size,ppd)
(
cross_top_px,
cross_bottom_px,
cross_left_px,
cross_right_px,
) = degrees_to_pixels(cross_size, ppd)
cross_thickness_px = degrees_to_pixels(cross_thickness, ppd)
target_size_px = degrees_to_pixels(target_size, ppd)

Expand All @@ -56,25 +60,28 @@ def benarys_cross(
img[:, x_edge_left:x_edge_right] = cross
img[y_edge_top:y_edge_bottom, :] = cross


tpos1y = y_edge_top - target_size_px
tpos1x = x_edge_left - target_size_px
tpos2y = y_edge_top
tpos2x = -target_size_px
img[tpos1y:tpos1y + target_size_px, tpos1x:tpos1x + target_size_px] = target
img[tpos2y:tpos2y + target_size_px, tpos2x:] = target
img[
tpos1y : tpos1y + target_size_px, tpos1x : tpos1x + target_size_px
] = target
img[tpos2y : tpos2y + target_size_px, tpos2x:] = target

mask[tpos1y:tpos1y + target_size_px, tpos1x:tpos1x + target_size_px] = 1
mask[tpos2y:tpos2y + target_size_px, tpos2x:] = 2
mask[
tpos1y : tpos1y + target_size_px, tpos1x : tpos1x + target_size_px
] = 1
mask[tpos2y : tpos2y + target_size_px, tpos2x:] = 2

img = pad_img(img, padding, ppd, back)
mask = pad_img(mask, padding, ppd, 0)


return {"img": img, "mask": mask}


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

stim = benarys_cross()
plot_stim(stim, mask=True)
51 changes: 40 additions & 11 deletions stimuli/illusions/bullseye.py
@@ -1,9 +1,19 @@
import numpy as np
from stimuli.illusions.rings import ring_pattern
from stimuli.utils import degrees_to_pixels, pad_img
from stimuli.Stimulus import Stimulus

def bullseye_illusion(ppd=10, n_rings=8, ring_width=.5, target_pos_l=0, target_pos_r=0, padding=(1.0,1.0,1.0,1.0), back=0., rings=1., target=.5):

def bullseye_illusion(
ppd=10,
n_rings=8,
ring_width=0.5,
target_pos_l=0,
target_pos_r=0,
padding=(1.0, 1.0, 1.0, 1.0),
back=0.0,
rings=1.0,
target=0.5,
):
"""
Bullseye Illusion.
Two ring patterns (see ring_pattern func), with target in centre and one ring pattern inverted.
Expand Down Expand Up @@ -33,15 +43,33 @@ def bullseye_illusion(ppd=10, n_rings=8, ring_width=.5, target_pos_l=0, target_p
-------
A stimulus object
"""
stim1 = ring_pattern(n_rings=n_rings, target_pos_l=target_pos_l, ring_width=ring_width, padding=padding,
back=back, rings=rings, target=target, invert_rings=False, double=False)
stim2 = ring_pattern(n_rings=n_rings, target_pos_l=target_pos_r, ring_width=ring_width, padding=padding,
back=back, rings=rings, target=target, invert_rings=True, double=False)
stim1 = ring_pattern(
n_rings=n_rings,
target_pos_l=target_pos_l,
ring_width=ring_width,
padding=padding,
back=back,
rings=rings,
target=target,
invert_rings=False,
double=False,
)
stim2 = ring_pattern(
n_rings=n_rings,
target_pos_l=target_pos_r,
ring_width=ring_width,
padding=padding,
back=back,
rings=rings,
target=target,
invert_rings=True,
double=False,
)

img = np.hstack((stim1['img'], stim2['img']))
img = np.hstack((stim1["img"], stim2["img"]))
# Increase target mask values to differentiate from single-stimulus targets:
stim2['mask'][stim2['mask'] != 0] += 1
mask = np.hstack((stim1['mask'], stim2['mask']))
stim2["mask"][stim2["mask"] != 0] += 1
mask = np.hstack((stim1["mask"], stim2["mask"]))

return {"img": img, "mask": mask}

Expand Down Expand Up @@ -75,8 +103,9 @@ def RHS2007_bullseye_thick():
)


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

stim = bullseye_illusion()
plt.imshow(stim.img, cmap='gray')
plt.imshow(stim.img, cmap="gray")
plt.show()
21 changes: 15 additions & 6 deletions stimuli/illusions/checkerboard_contrast_contrast.py
Expand Up @@ -13,7 +13,7 @@ def checkerboard_contrast_contrast_effect(
check2=2.0,
tau=0.5,
alpha=0.5,
limit_mask_vals=True
limit_mask_vals=True,
):
"""
Contrast-contrast effect on checkerboard with square transparency layer.
Expand Down Expand Up @@ -54,7 +54,7 @@ def checkerboard_contrast_contrast_effect(

idx = np.zeros((n_checks, n_checks), dtype=bool)
tpos = (n_checks - target_length) // 2
idx[tpos:tpos + target_length, tpos:tpos + target_length] = True
idx[tpos : tpos + target_length, tpos : tpos + target_length] = True
arr1[idx] = alpha * arr1[idx] + (1 - alpha) * tau
mask_id = 0
for i, _ in enumerate(idx):
Expand All @@ -71,14 +71,22 @@ def checkerboard_contrast_contrast_effect(
mask_arr2 = mask_arr1.copy()
mask_arr2[mask_arr2 != 0] += mask_id

img1 = np.repeat(np.repeat(arr1, check_size_px, axis=0), check_size_px, axis=1)
img1 = np.repeat(
np.repeat(arr1, check_size_px, axis=0), check_size_px, axis=1
)
img1 = pad_img(img1, padding, ppd, tau)
img2 = np.repeat(np.repeat(arr2, check_size_px, axis=0), check_size_px, axis=1)
img2 = np.repeat(
np.repeat(arr2, check_size_px, axis=0), check_size_px, axis=1
)
img2 = pad_img(img2, padding, ppd, tau)

mask1 = np.repeat(np.repeat(mask_arr1, check_size_px, axis=0), check_size_px, axis=1)
mask1 = np.repeat(
np.repeat(mask_arr1, check_size_px, axis=0), check_size_px, axis=1
)
mask1 = pad_img(mask1, padding, ppd, 0)
mask2 = np.repeat(np.repeat(mask_arr2, check_size_px, axis=0), check_size_px, axis=1)
mask2 = np.repeat(
np.repeat(mask_arr2, check_size_px, axis=0), check_size_px, axis=1
)
mask2 = pad_img(mask2, padding, ppd, 0)

img = np.hstack([img1, img2])
Expand All @@ -90,5 +98,6 @@ def checkerboard_contrast_contrast_effect(

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

stim = checkerboard_contrast_contrast_effect()
plot_stim(stim, mask=True)
37 changes: 20 additions & 17 deletions stimuli/illusions/checkerboard_sbc.py
@@ -1,15 +1,18 @@
import numpy as np
from stimuli.utils import (
degrees_to_pixels,
pad_img,
pad_img_to_shape,
plot_stim,
)
from stimuli.utils import degrees_to_pixels, pad_img_to_shape, plot_stim
from stimuli.Stimulus import Stimulus
import matplotlib.pyplot as plt

def checkerboard_contrast(ppd=10, board_shape=(8,8), check_size=1.0, targets_coords=((3, 2), (5, 5)), extend_targets=False,
check1=0., check2=1., target=.5):

def checkerboard_contrast(
ppd=10,
board_shape=(8, 8),
check_size=1.0,
targets_coords=((3, 2), (5, 5)),
extend_targets=False,
check1=0.0,
check2=1.0,
target=0.5,
):
# TODO: targets_coords used to be coord1 and coords2, now multiple targets are allowed. This should be changed in all places calling this function
"""
Checkerboard Contrast
Expand Down Expand Up @@ -53,13 +56,13 @@ def checkerboard_contrast(ppd=10, board_shape=(8,8), check_size=1.0, targets_coo

for i, coords in enumerate(targets_coords):
arr[coords] = target
mask[coords] = i+1
mask[coords] = i + 1

if extend_targets:
for i, coords in enumerate(targets_coords):
for idx in [(-1, 0), (0, 1), (1, 0), (0, -1)]:
arr[coords[0] + idx[0], coords[1] + idx[1]] = target
mask[coords[0] + idx[0], coords[1] + idx[1]] = i+1
mask[coords[0] + idx[0], coords[1] + idx[1]] = i + 1

img = np.repeat(
np.repeat(arr, check_size_px, axis=0), check_size_px, axis=1
Expand Down Expand Up @@ -93,8 +96,8 @@ def RHS2007_Checkerboard016():
target=target,
)

img = pad_img_to_shape(stim['img'], (1024, 1024), val=target)
mask = pad_img_to_shape(stim['mask'], (1024, 1024), val=0)
img = pad_img_to_shape(stim["img"], (1024, 1024), val=target)
mask = pad_img_to_shape(stim["mask"], (1024, 1024), val=0)

return {"img": img, "mask": mask}

Expand All @@ -120,8 +123,8 @@ def RHS2007_Checkerboard0938():
check2=check2,
target=target,
)
img = pad_img_to_shape(stim['img'], (1024, 1024), val=target)
mask = pad_img_to_shape(stim['mask'], (1024, 1024), val=0)
img = pad_img_to_shape(stim["img"], (1024, 1024), val=target)
mask = pad_img_to_shape(stim["mask"], (1024, 1024), val=0)

return {"img": img, "mask": mask}

Expand All @@ -147,8 +150,8 @@ def RHS2007_Checkerboard209():
check2=check2,
target=target,
)
img = pad_img_to_shape(stim['img'], (1024, 1024), val=target)
mask = pad_img_to_shape(stim['mask'], (1024, 1024), val=0)
img = pad_img_to_shape(stim["img"], (1024, 1024), val=target)
mask = pad_img_to_shape(stim["mask"], (1024, 1024), val=0)

return {"img": img, "mask": mask}

Expand Down
31 changes: 19 additions & 12 deletions stimuli/illusions/cornsweet.py
Expand Up @@ -2,9 +2,15 @@
from stimuli.Stimulus import Stimulus


def cornsweet(size=(10,10), ppd=10, contrast=0.5, ramp_width=2, exponent=2.75,
mean_lum=.5):
#TODO: the parameters aren't analogous to the other stimuli
def cornsweet(
size=(10, 10),
ppd=10,
contrast=0.5,
ramp_width=2,
exponent=2.75,
mean_lum=0.5,
):
# TODO: the parameters aren't analogous to the other stimuli
"""
Create a matrix containing a rectangular Cornsweet edge stimulus.
The 2D luminance profile of the stimulus is defined as
Expand Down Expand Up @@ -43,20 +49,21 @@ def cornsweet(size=(10,10), ppd=10, contrast=0.5, ramp_width=2, exponent=2.75,
S.O., Kersten, D. (2007). Responses to Lightness Variations in Early Human
Visual Cortex. Current Biology 17, 989-993.
"""
size = [int(size[0]*ppd), int(size[1]*ppd)]
size = [int(size[0] * ppd), int(size[1] * ppd)]
img = np.ones(size) * mean_lum
dist = np.arange(size[1] / 2.)
dist = dist / (ramp_width*ppd)
dist[dist > 1.] = 1.
profile = (1. - dist) ** exponent * mean_lum * contrast
img[:, :int(np.ceil(size[1]/2.))] += profile[::-1]
img[:, size[1] // 2:] -= profile
dist = np.arange(size[1] / 2.0)
dist = dist / (ramp_width * ppd)
dist[dist > 1.0] = 1.0
profile = (1.0 - dist) ** exponent * mean_lum * contrast
img[:, : int(np.ceil(size[1] / 2.0))] += profile[::-1]
img[:, size[1] // 2 :] -= profile
mask = None
return {"img": img, "mask": mask}


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

stim = cornsweet()
plt.imshow(stim, cmap='gray')
plt.imshow(stim, cmap="gray")
plt.show()

0 comments on commit f1b0e05

Please sign in to comment.