Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RHD2007 stimuli are mostly replicated
- Loading branch information
Showing
9 changed files
with
1,303 additions
and
765 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,47 @@ | ||
import numpy as np | ||
from scipy.ndimage.filters import gaussian_filter | ||
from stimuli.utils import degrees_to_pixels, pad_img | ||
|
||
import stimuli | ||
|
||
################################### | ||
# Grating induction # | ||
################################### | ||
def grating_illusion(n_grid, grating_shape, target_height, blur, padding=(10,10,10,10,)): | ||
# Inputs: | ||
# - n_grid: number of black and white stripes (int, unit: pixels) | ||
# - target_shape: (height, width) of the target in px | ||
# - blur: amount of blur added (float) | ||
def grating_illusion(shape=(10,10), ppd=40, frequency=0.5, target_height=0.5, blur=None, high=1., low=0., target=.5, start='low', period='ignore', padding=(2,2,2,2)): | ||
if blur == None: | ||
blur = shape[0]/2 | ||
|
||
grating_height, grating_width = grating_shape | ||
height_px, width_px = degrees_to_pixels(shape, ppd) | ||
target_height_px = degrees_to_pixels(target_height, ppd) | ||
|
||
# Create grid | ||
grid = np.zeros((1,n_grid), dtype=np.float32) | ||
grid[0, ::2] = 1 | ||
grid[0, 1::2] = 0 | ||
img, pixels_per_cycle = stimuli.illusions.square_wave(shape, ppd, frequency, high, low, period, start) | ||
img = gaussian_filter(img, blur) | ||
mask = np.zeros((height_px, width_px)) | ||
|
||
# Increase the resolution of the grid for blurring it later: | ||
grid = np.repeat(grid, grating_height, axis=0) | ||
grid = np.repeat(grid, grating_width, axis=1) | ||
grid = gaussian_filter(grid, blur) | ||
target_start = height_px//2 - target_height_px//2 | ||
target_end = target_start + target_height_px | ||
img[target_start:target_end, :] = target | ||
mask[target_start:target_end, :] = True | ||
|
||
# Place target on blurred grid | ||
target_start_y = (grating_height-target_height)//2 | ||
grid[target_start_y : target_start_y + target_height, :] = 0.5 | ||
return grid | ||
img = pad_img(img, padding, ppd, target) | ||
mask = pad_img(mask, padding, ppd, 0) | ||
|
||
return (img, mask) | ||
|
||
def RHS2007_grating_induction(): | ||
n_grid = 8 | ||
phase_width = 2 | ||
res_factor = 20 | ||
target_height, target_width = phase_width * res_factor * 6, phase_width * res_factor | ||
return grating_induction(n_grid=8, grating_shape=(target_height, target_width), | ||
target_height=phase_width * res_factor // 2, blur=5) | ||
total_height, total_width, ppd = (32,)*3 | ||
n_cycles = 4 | ||
height, width = 12, 16 | ||
frequency = n_cycles / width | ||
padding_horizontal = (total_width - width) / 2 | ||
padding_vertical = (total_height - height) / 2 | ||
padding = (padding_vertical, padding_vertical, padding_horizontal, padding_horizontal) | ||
img = stimuli.illusions.grating_induction.grating_illusion(shape=(height, width), ppd=ppd, frequency=frequency, target_height=1, blur=10, start='high', padding=padding) | ||
return img | ||
|
||
|
||
if __name__ == '__main__': | ||
import matplotlib.pyplot as plt | ||
img, mask = grating_illusion() | ||
plt.imshow(img, cmap='gray') | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.