Re: [psychopy-users] creating a drifting plaid patch, windowed by a gaussian

287 views
Skip to first unread message

Jonathan Peirce

unread,
Apr 12, 2013, 11:47:57 AM4/12/13
to psychop...@googlegroups.com
Hi Sarah,

This is an interesting little riddle, and I'm not honestly sure why the
'obvious' solution didnt work.

The best way to fix it will be to implement some new methods of
combining pixels from textures to the frame buffer (including the option
to 'add' rather than 'average'). But that will take some hardish coding
at my end.

In the meantime, the ugly hack is this: draw the two gratings as you are
doing but with no masks, and then afterwards draw a stimulus with no
texture but an inverse of a gaussian mask (ie, transparent centre and
opaque at sides).

Hope that works! Apols for the ugliness of the hack. ;-)
Jon

#INITIALISE SOME STIMULI
grating1 = visual.GratingStim(myWin,mask=None,
color=[1.0,1.0,1.0],opacity=0.3,
size=(1.0,1.0), sf=(4,0), ori = 45,
autoLog=False)#this stim changes too much for autologging to be useful
grating2 = visual.GratingStim(myWin,mask=None,
color=[1.0,1.0,1.0],opacity=0.3,
size=(1.0,1.0), sf=(4,0), ori = 135,
autoLog=False)#this stim changes too much for autologging to be useful
#overlay an inverse gaussian mask (grey outside, transparent inside)
gaussTexture = filters.makeMask(128, shape='gauss') #has -1 for transp,
+1 for opaque
invGaussTexture = -gaussTexture #make opaq->transp and vice versa
gaussMask = visual.GratingStim(myWin,mask=invGaussTexture,tex=None,
contrast=0, ori = grating2.ori, size=(1,1))

trialClock = core.Clock()
t = 0
while t<20:#quits after 20 secs

t=trialClock.getTime()

grating1.setPhase(1*t) #drift at 1Hz
grating1.draw() #redraw it

grating2.setPhase(2*t) #drift at 2Hz
grating2.draw() #redraw it
gaussMask.draw()

myWin.flip() #update the screen

On 12/04/2013 15:58, Sarah Harrison wrote:
> Hi all,
>
> The problem is as in the title, and has come to light because I want
> the two plaid components to be of different contrast.
>
> The intuitive solution is to create two gratings windowed by
> gaussians, then draw them both with their new phase (one after the
> other, with the second having reduced opacity), on each frame.
> However, drawing the gratings like this, when they have each already
> been masked by a gaussian, doesn't 'add' them correctly - this problem
> can be seen because the result depends on which grating is drawn
> first, which it shouldn't.
>
> I can create the correct stationary plaids by adding two arrays (for
> instance using visual.filters.makeGrating), making a mask (using
> visual.filters.makeMask), and then multiplying the two arrays. The
> problem here is that the array then has to be used as a 'image' in
> visual.ImageStim or a 'tex' in visual.GratingStim to make an object
> that has the attribute 'draw'. Once the object has been created in
> this way, I can't access the phase of the (two) gratings to make them
> appear to drift, without creating a new object on each frame.
>
> In fact, even once the two grating arrays are combined to make a plaid
> array, I can't see a simple way to alter the plaid component phases...
> but even if I could, this wouldn't solve the problem.
>
> Any new ideas welcome!
>
> Thanks.
>
> Sarah
> --
> You received this message because you are subscribed to the Google
> Groups "psychopy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to psychopy-user...@googlegroups.com.
> To post to this group, send email to psychop...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/psychopy-users/-/62vZvkwWrpsJ.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk/

Sarah Harrison

unread,
Apr 13, 2013, 8:48:53 AM4/13/13
to psychop...@googlegroups.com
Hi Jon,

Great, thanks - working as it should now.

I had completely forgotten about this approach.

Sarah

Sarah Harrison

unread,
Apr 16, 2013, 12:21:08 PM4/16/13
to psychop...@googlegroups.com
Jon,
Just one further question for clarification:
In your example, why did you set the opacity to 0.3 for both gratings, rather than to 1.0 for the first and to 0.5 for the second, as we discussed before?  (And more to the point, why does this seem to work, without the averaging-type problem of before?)

Thanks.

Sarah

Jonathan Peirce

unread,
Apr 18, 2013, 1:52:07 PM4/18/13
to psychop...@googlegroups.com
> Jon,
> Just one further question for clarification:
> In your example, why did you set the opacity to 0.3 for both gratings,
> rather than to 1.0 for the first and to 0.5 for the second, as we
> discussed before? (And more to the point, why does this seem to work,
> without the averaging-type problem of before?)
>
> Thanks.
>
> Sarah

Hmm, the opacity=0.3 was a mistake caused by me playing around. It
should still be 1.0 and 0.5

But I genuinely can't work out what's going on and why it looks wrong.
Am still trying to understand it myself!

Jon
Reply all
Reply to author
Forward
0 new messages