Skip to content

Commit

Permalink
Use pad_to_visual_size where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
JorisVincent committed Nov 6, 2022
1 parent f929ce9 commit 0ab7cc7
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 112 deletions.
18 changes: 11 additions & 7 deletions stimuli/illusions/circular.py
@@ -1,7 +1,7 @@
import numpy as np

from stimuli.components import disc_and_rings
from stimuli.utils import degrees_to_pixels, pad_to_shape, resize_array
from stimuli.utils import degrees_to_pixels, pad_to_visual_size, resize_array


def circular_white(
Expand Down Expand Up @@ -66,8 +66,8 @@ def circular_white(
frequency_used = 1.0 / cycle_width_px * ppd
freqs = (frequency, frequency_used)
print(
"Warning: Circular White frequency changed from %f to %f ensure an even-numbered cycle width!"
% freqs
"Warning: Circular White frequency changed from %f to %f ensure an even-numbered cycle"
" width!" % freqs
)
if n_discs < 1:
raise ValueError("No circle fits in requested shape! Increase frequency or shape")
Expand All @@ -93,8 +93,10 @@ def circular_white(
mask = disc_and_rings(ppd, radii, 0, vdics_mask, ssf)

# Pad to desired size
img = pad_to_shape(img, np.array(visual_size) * ppd, intensity_background)
mask = pad_to_shape(mask, np.array(visual_size) * ppd, 0)
img = pad_to_visual_size(
img=img, visual_size=visual_size, ppd=ppd, pad_value=intensity_background
)
mask = pad_to_visual_size(img=mask, visual_size=visual_size, ppd=ppd, pad_value=0)

# Target masks should only cover areas where target intensity is exactly vtarget
cond = (img != intensity_target) & (mask != 0)
Expand Down Expand Up @@ -275,8 +277,10 @@ def radial_white(
mask = np.dot(sampler, np.dot(mask, sampler.T)) / ssf**2

# Pad to desired size
img = pad_to_shape(img, np.array(visual_size) * ppd, intensity_background)
mask = pad_to_shape(mask, np.array(visual_size) * ppd, 0)
img = pad_to_visual_size(
img=img, visual_size=visual_size, ppd=ppd, pad_value=intensity_background
)
mask = pad_to_visual_size(img=mask, visual_size=visual_size, ppd=ppd, pad_value=0)

# Target masks should only cover areas where target intensity is exactly vtarget
cond = (img != intensity_target) & (mask != 0)
Expand Down
8 changes: 4 additions & 4 deletions stimuli/illusions/grating.py
@@ -1,7 +1,7 @@
import numpy as np

from stimuli.components import square_wave_grating
from stimuli.utils import degrees_to_pixels, pad_to_shape
from stimuli.utils import degrees_to_pixels, pad_to_visual_size


def grating_illusion(
Expand Down Expand Up @@ -90,9 +90,9 @@ def grating_uniform(
mask[img == intensity_target] = 1

# Padding
im_size_px = degrees_to_pixels(im_size, ppd)
img = pad_to_shape(img, im_size_px, intensity_background)
mask = pad_to_shape(mask, im_size_px, 0)
img = pad_to_visual_size(img=img, visual_size=im_size, ppd=ppd, pad_value=intensity_background)
img = pad_to_visual_size(img=mask, visual_size=im_size, ppd=ppd, pad_value=0)

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


Expand Down
4 changes: 2 additions & 2 deletions stimuli/illusions/todorovic.py
@@ -1,7 +1,7 @@
import numpy as np

from stimuli.components import cross, rectangle
from stimuli.utils import degrees_to_pixels, pad_to_shape
from stimuli.utils import degrees_to_pixels, pad_to_visual_size


def todorovic_rectangle_generalized(
Expand Down Expand Up @@ -217,7 +217,7 @@ def todorovic_cross_generalized(
img = cross(ppd, target_arms_size, target_thickness, intensity_background, intensity_target)
if img.shape[0] > visual_size[0] * ppd or img.shape[1] > visual_size[1] * ppd:
raise ValueError("your cross does not fit in requested stimulus size")
img = pad_to_shape(img, np.array(visual_size) * ppd, pad_value=intensity_background)
img = pad_to_visual_size(img, visual_size=visual_size, ppd=ppd, pad_value=intensity_background)

cheight, cwidth = degrees_to_pixels(covers_size, ppd)
cposx = degrees_to_pixels(covers_posx, ppd)
Expand Down

0 comments on commit 0ab7cc7

Please sign in to comment.