对于使用彩色斑点的双目竞争实验(使用高斯蒙版用GratingStim创建),我需要绘制一个假的竞争刺激。也就是说,我需要一个圆形的颜色斑点,例如在顶部有一种颜色(颜色斑点的25%)和下面的另一种颜色(颜色斑点的75%)。另外,我希望这个双色的假对手blob有一个高斯面具作为我真正的竞争刺激。在假对抗刺激中进行模糊的颜色转换也是一件好事。我希望我的意思很清楚。
我想到的一个解决方案是绘制两个边缘模糊的矩形,然后在它们上面放置一个高斯alpha蒙版。为了获得正确的颜色比例,我只需要移动掩模后面的两个矩形。有没有办法将alpha-maks放在整个窗口上?
另一种解决方案是使用ShapeStim,如本文中建议的那样,解释如何绘制半圆:https://groups.google.com/forum/#!msg/psychopy-users/L9TYIrf9eJk/m0zIj0N23bMJ我必须使用顶点,但我认为它应该有效。这里唯一让我担心的是ShapeStim没有模糊边缘的蒙版属性。
你能想到办法吗? 非常感谢你!
里拉
系统规格: 在iOS 10.11.1上运行的Psychopy v1.83.01
答案 0 :(得分:1)
第二次更新,甚至更好的结果:
# Set up stimuli
from psychopy import visual, event
import numpy as np
from scipy.stats import gaussian_kde
win = visual.Window([500,500])
win2 = visual.Window([500,500])
#magic numpy stuff /scipy stuff, adapted from http://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.stats.gaussian_kde.html
mean1 = [0, 0]
#the smaller the value, the bigger the visible blob
cov1 = [[0.03, 0], [0, 0.09]] #in this mask, it should be 50/50
cov2 = [[0.05,0],[0,0.4]] #in this mask, the color with this mask is the smaller one
m1, m2 = np.random.multivariate_normal(mean1, cov1, 2000).T# * np.random.multivariate_normal(mean2, cov2, 5000).T
for i in xrange(len(m2)):
if m2[i] >= 0:
m2[i] = m2[i]* 0.5#np.random.multivariate_normal(mean2, cov2,1).T[0]
values = np.vstack([m1, m2])
kernel = gaussian_kde(values)
xmin = m1.min()
xmax = m1.max()
ymin = m2.min()
ymax = m2.max()
X, Y = np.mgrid[xmin:xmax:128j, ymin:ymax:128j]
positions = np.vstack([X.ravel(), Y.ravel()])
values = np.vstack([m1, m2])
kernel = gaussian_kde(values)
Z = np.reshape(kernel(positions).T, X.shape) #this array will be the mask
Z = Z - 1
for i in xrange(128):
for j in xrange(128): #it will neverbe smaller than -1
if Z[i][j] > 1:
Z[i][j] = 1
# Draw them on top of each other
perc75 = visual.GratingStim(win, sf=0, size=250, color='green',pos=(0.0, 0.0), mask =Z)
perc25 = visual.GratingStim(win, sf=0, size=250, color='red',pos=(0.0, 0.0), mask = 'raisedCos', maskParams={'fringeWidth':0.8})
perc25.setAutoDraw(True)
perc75.setAutoDraw(True)
win.flip()
event.waitKeys()
答案 1 :(得分:0)
这会有用吗?然后,您可以找到所需的blob,例如一只眼睛。无需做全窗口的事情。
# Set up stimuli
from psychopy import visual, event
win = visual.Window([500,500])
blob_large = visual.GratingStim(win, sf=0, mask='gauss', size=1, color='red')
blob_small = visual.GratingStim(win, sf=0, mask='gauss', size=0.5, color='green', maskParams={'sd':6})
# Draw them on top of each other
blob_large.draw()
blob_small.draw()
win.flip()
# Wait for keyboard before quitting.
event.waitKeys()
答案 2 :(得分:0)
更新我的问题:以下示例代码解决了问题:
# -*- coding: utf-8 -*-
# adapted from https://groups.google.com/forum/#!msg/psychopy-users/69p-aAWiDGI/e4iT43cHDeEJ
from psychopy import visual, event
win = visual.Window([500,500])
#stimuli
perc25 = visual.GratingStim(win, sf=0, size=1, color='RED',pos=(0.0, 0.0), mask = 'raisedCos', maskParams={'fringeWidth':0.8})
perc75 = visual.GratingStim(win, sf=0, size=0.8, color='green',pos=(0.0, -0.15), mask = 'raisedCos', maskParams={'fringeWidth':0.6})
#prepare for the screenshot
Stimlist = [perc25, perc75]
delta = .5# larger is bigger, slower
dx = delta * win.size[1]/win.size[0]
dy = delta
rect = (-dx, +dy, +dx, -dy)#size of the screenshot
screenshot = visual.BufferImageStim(win, stim=Stimlist,rect = rect, mask = 'gauss', pos=(0.0, 0.0)) # mask can also be 'raisedCos' with a smaller delta, for exmple .2
screenshot.draw()
win.flip()
event.waitKeys()