【问题标题】:Fake-rivalry stimulus虚假竞争刺激
【发布时间】:2016-03-23 21:41:57
【问题描述】:

对于使用颜色斑点(使用 GratingStim 使用高斯蒙版创建)的双目竞争实验,我需要绘制一个虚假的竞争刺激。也就是说,我需要一个圆形颜色的斑点,例如顶部有一种颜色(颜色斑点的 25%)和下面的另一种颜色(颜色斑点的 75%)。此外,我希望双色假竞争斑点具有高斯面具,就像我真正的竞争刺激一样。此外,在虚假的竞争刺激中具有模糊的颜色过渡也会很好。我希望我的意思很清楚。

我想到的一个解决方案是绘制两个边缘模糊的矩形,然后在它们上面放置一个高斯 alpha 蒙版。为了获得正确的颜色比例,我只需要移动蒙版后面的两个矩形。有没有办法在整个窗口上放置一个 alpha-maks?

另一个解决方案是使用 ShapeStim,正如这篇解释如何绘制半圆的帖子中所建议的那样:https://groups.google.com/forum/#!msg/psychopy-users/L9TYIrf9eJk/m0zIj0N23bMJ 我将不得不使用顶点,但我认为它应该可以工作。这里唯一让我担心的是 ShapeStim 没有遮罩属性来模糊边缘。

你能想出办法吗? 非常感谢!

莉拉

系统规格: 在 iOS 10.11.1 上运行的 Psychopy v1.83.01

【问题讨论】:

    标签: psychopy


    【解决方案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()
    

    【讨论】:

      【解决方案2】:

      这行得通吗?然后,您可以找到所需的 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()
      

      【讨论】:

      • 亲爱的 Jonas,谢谢你的想法,如果我不能让它与 pygame 一起工作,我想我会去的。根据您的建议,我认为我没有很好地描述我的想法:与其上方的两个斑点相比,我更喜欢上面 25% 左右为绿色而其余部分为红色的斑点,如 Pearson、Clifford 和 Tong 2008(补充数据):sciencedirect.com/science/article/pii/S0960982208007239。你对此有什么想法吗?感谢您的帮助!
      • 亲爱的 Jonas,我有另一个想法:我可以在两个刺激物上方用一个定制的面具(即一个数组)来绘制它们。那么,面具是否必须具有相关刺激的尺寸?谢谢您的帮助!莉拉
      【解决方案3】:

      更新我的问题:以下示例代码解决了问题:

      # -*- 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()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-23
        • 1970-01-01
        • 2017-04-28
        • 2023-01-01
        • 2023-01-30
        • 2012-07-24
        • 2018-10-08
        • 1970-01-01
        相关资源
        最近更新 更多