Skip to content

Commit

Permalink
fixed some bugs in whites generation and added padding_val param
Browse files Browse the repository at this point in the history
  • Loading branch information
matko031 committed Sep 28, 2021
1 parent cdbda26 commit 519992c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions stimuli/illusions/square_wave.py
Expand Up @@ -45,9 +45,9 @@ def square_wave(shape=(10,10), ppd=10, frequency=1, high=1.0, low=0.0, period='i
pixels_per_cycle = degrees_to_pixels(1. / (frequency*2) , ppd) * 2

if period is 'full':
width = (shape_pixels // pixels_per_cycle) * pixels_per_cycle
width = (width // pixels_per_cycle) * pixels_per_cycle
elif period is 'half':
width = (shape_pixels // pixels_per_cycle) * pixels_per_cycle + pixels_per_cycle / 2
width = (height // pixels_per_cycle) * pixels_per_cycle + pixels_per_cycle / 2

stim = np.ones((height, width)) * (low if start is 'high' else high)

Expand Down
18 changes: 14 additions & 4 deletions stimuli/illusions/whites.py
@@ -1,12 +1,14 @@
import numpy as np
import matplotlib.pyplot as plt
import math

import stimuli
from stimuli.utils import degrees_to_pixels, pad_img, get_annulus_mask
from stimuli.Stimulus import Stimulus
from stimuli import illusions

def white(shape=(10,10), ppd=50, frequency=0.4, high=1.0, low=0.0, target=0.5, period='ignore', start='low', target_indices=(2,5),
target_height=None, targets_offset=0, orientation = 'horizontal', padding=(2,2,2,2)):
target_height=None, targets_offset=0, orientation = 'horizontal', padding=(2,2,2,2), padding_val=0.5):

"""
Whites's illusion
Expand Down Expand Up @@ -61,7 +63,15 @@ def white(shape=(10,10), ppd=50, frequency=0.4, high=1.0, low=0.0, target=0.5, p
y_end = y_start + target_height_px

for i, index in enumerate(target_indices):
x_start = index*phase_width
if index >= 0:
x_start = index*phase_width
else:
cycles = frequency * shape[1]
phases = int(cycles)*2
dec = cycles % 1
if dec != 0:
phases = phases + 2 if dec > 0.5 else phases + 1
x_start = int((phases + index)*phase_width)
x_end = x_start+phase_width
img[y_start:y_end, x_start:x_end] = target
mask[y_start:y_end, x_start:x_end] = i+1
Expand All @@ -70,7 +80,7 @@ def white(shape=(10,10), ppd=50, frequency=0.4, high=1.0, low=0.0, target=0.5, p
img = np.rot90(img, 3)
mask = np.rot90(mask, 3)

img = pad_img(img, padding, ppd, target)
img = pad_img(img, padding, ppd, padding_val)
mask = pad_img(mask, padding, ppd, 0)

stim = Stimulus()
Expand Down Expand Up @@ -522,7 +532,7 @@ def domijan2015_white():


if __name__ == '__main__':
stim = white()
stim = stimuli.illusions.whites.white()
plt.subplot(4,2,1)
plt.imshow(stim.img, cmap='gray')
plt.subplot(4,2,2)
Expand Down

0 comments on commit 519992c

Please sign in to comment.