Skip to content

Commit

Permalink
changed functions to create target masks with two target values by de…
Browse files Browse the repository at this point in the history
…fault
  • Loading branch information
LynnSchmittwilken committed Sep 29, 2021
1 parent a527c7d commit a067ae6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 23 deletions.
2 changes: 2 additions & 0 deletions stimuli/illusions/bullseye.py
Expand Up @@ -39,6 +39,8 @@ def bullseye_illusion(ppd=10, n_rings=8, ring_width=.5, target_pos_l=0, target_p
back=back, rings=rings, target=target, invert_rings=True, double=False)

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

stim = Stimulus()
Expand Down
17 changes: 10 additions & 7 deletions stimuli/illusions/checkerboard_contrast_contrast.py
Expand Up @@ -13,6 +13,7 @@ def checkerboard_contrast_contrast_effect(
check2=2.0,
tau=0.5,
alpha=0.5,
limit_mask_vals=True
):
"""
Contrast-contrast effect on checkerboard with square transparency layer.
Expand Down Expand Up @@ -51,23 +52,24 @@ def checkerboard_contrast_contrast_effect(

mask_arr1 = np.zeros((n_checks, n_checks))


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
arr1[idx] = alpha * arr1[idx] + (1 - alpha) * tau
mask_counter = 1
mask_id = 0
for i, _ in enumerate(idx):
for j, el in enumerate(_):
if el:
mask_arr1[i,j] = mask_counter
mask_counter += 1

if limit_mask_vals:
mask_id = 1
else:
mask_id += 1
mask_arr1[i, j] = mask_id

arr2 = arr1.copy()
arr2[~idx] = tau

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 = pad_img(img1, padding, ppd, tau)
Expand All @@ -80,7 +82,8 @@ def checkerboard_contrast_contrast_effect(
mask2 = pad_img(mask2, padding, ppd, 0)

img = np.hstack([img1, img2])
mask = np.hstack([mask1, mask2])
# Increase target mask values to differentiate from single-stimulus targets:
mask = np.hstack([mask1, mask2])
stim = Stimulus()
stim.img = img
stim.target_mask = mask
Expand Down
6 changes: 2 additions & 4 deletions stimuli/illusions/checkerboard_sbc.py
Expand Up @@ -83,8 +83,7 @@ def domijan2015():
ppd=10,
board_shape=(8, 8),
check_size=1.0,
target1_coords=(3, 2),
target2_coords=(5, 5),
targets_coords=((3, 2), (5, 5)),
extend_targets=False,
check1=1.0,
check2=9.0,
Expand All @@ -104,8 +103,7 @@ def domijan2015_extended():
ppd=10,
board_shape=(8, 8),
check_size=1.0,
target1_coords=(3, 2),
target2_coords=(5, 5),
targets_coords=((3, 2), (5, 5)),
extend_targets=True,
check1=1.0,
check2=9.0,
Expand Down
31 changes: 19 additions & 12 deletions stimuli/illusions/cube.py
Expand Up @@ -18,6 +18,7 @@ def cube_illusion(
grid=1.0,
target=0.5,
double=True,
limit_mask_vals=True
):

"""
Expand Down Expand Up @@ -53,6 +54,8 @@ def cube_illusion(
value for target
double : bool
whether to return the full illusion with two grids side-by-side (inverting back and grid values)
limit_mask_vals : bool
whether to differentiate only two targets (left/right) or individiual targets
Returns
-------
Expand Down Expand Up @@ -80,59 +83,61 @@ def cube_illusion(

img = np.ones((height_px, width_px)) * back
mask = np.zeros((height_px, width_px))
mask_counter = 0
mask_id = 0

for i, val in np.ndenumerate(arr):
target_cell = val==target
if target_cell:
mask_counter += 1
if target_cell and not limit_mask_vals:
mask_id += 1
elif target_cell and limit_mask_vals:
mask_id = 1

if i[0] in range(1, n_cells-1) and i[1] in range(1, n_cells-1):
continue # skip centre cells for efficiency
elif i == (0,0): # top left corner cell
img[:corner_cell_height_px, :corner_cell_width_px] = val
if target_cell:
mask[:corner_cell_height_px, :corner_cell_width_px] = mask_counter
mask[:corner_cell_height_px, :corner_cell_width_px] = mask_id

elif i == (0, n_cells-1): # top right corner cell
img[:corner_cell_height_px, -corner_cell_width_px:] = val
if target_cell:
mask[:corner_cell_height_px, -corner_cell_width_px:] = mask_counter
mask[:corner_cell_height_px, -corner_cell_width_px:] = mask_id

elif i == (n_cells-1, 0): # bottom left corner cell
img[-corner_cell_height_px:, :corner_cell_width_px] = val
if target_cell:
mask[-corner_cell_height_px:, :corner_cell_width_px] = mask_counter
mask[-corner_cell_height_px:, :corner_cell_width_px] = mask_id

elif i == (n_cells - 1, n_cells-1): # bottom right corner cell
img[-corner_cell_height_px:, -corner_cell_width_px:] = val
if target_cell:
mask[-corner_cell_height_px:, -corner_cell_width_px:] = mask_counter
mask[-corner_cell_height_px:, -corner_cell_width_px:] = mask_id

else:
if i[0] == 0 or i[0] == n_cells -1: # top/bottom side
x = corner_cell_width_px + cell_spacing_px + (i[1] - 1) * (cell_long_px + cell_spacing_px)
if i[0] == 0: # top side
img[:cell_short_px, x:x + cell_long_px] = val
if target_cell:
mask[:cell_short_px, x:x + cell_long_px] = mask_counter
mask[:cell_short_px, x:x + cell_long_px] = mask_id
else: # bottom side
img[-cell_short_px:, x:x + cell_long_px] = val
if target_cell:
mask[-cell_short_px:, x:x + cell_long_px] = mask_counter
mask[-cell_short_px:, x:x + cell_long_px] = mask_id

else: # left/right side
y = corner_cell_width_px + cell_spacing_px + (i[0] - 1) * (cell_long_px + cell_spacing_px)

if i[1] == 0: # left side
img[y:y + cell_long_px, :cell_short_px] = val
if target_cell:
mask[y:y + cell_long_px, :cell_short_px] = mask_counter
mask[y:y + cell_long_px, :cell_short_px] = mask_id

else: # right side
img[y:y + cell_long_px, -cell_short_px:] = val
if target_cell:
mask[y:y + cell_long_px, -cell_short_px:] = mask_counter

mask[y:y + cell_long_px, -cell_short_px:] = mask_id


# add occlusion
Expand Down Expand Up @@ -169,6 +174,8 @@ def cube_illusion(
double=False,
)
img = np.hstack([img, stim2.img])
# Increase target mask values to differentiate from single-stimulus targets:
stim2.target_mask[stim2.target_mask != 0] += mask_id
mask = np.hstack([mask, stim2.target_mask])

stim = Stimulus()
Expand Down
3 changes: 3 additions & 0 deletions stimuli/illusions/grating.py
Expand Up @@ -73,6 +73,7 @@ def grating_illusion(
img = pad_img(img, padding, ppd, back)
mask = pad_img(mask, padding, ppd, 0)

# Repeat stimulus and add to single-stimulus:
if double:
stim2 = grating_illusion(
ppd=ppd,
Expand All @@ -87,6 +88,8 @@ def grating_illusion(
double=False,
)
img = np.hstack([img, stim2.img])
# Increase target mask values to differentiate from single-stimulus targets:
stim2.target_mask[stim2.target_mask != 0] += 1
mask = np.hstack([mask, stim2.target_mask])

stim = Stimulus()
Expand Down
2 changes: 2 additions & 0 deletions stimuli/illusions/rings.py
Expand Up @@ -107,6 +107,8 @@ def ring_pattern(
double=False,
)
img = np.hstack([img, stim2.img])
# Increase target mask values to differentiate from single-stimulus targets:
stim2.target_mask[stim2.target_mask != 0] += 1
mask = np.hstack([mask, stim2.target_mask])

stim = Stimulus()
Expand Down

0 comments on commit a067ae6

Please sign in to comment.