On 12/04/2011 10:15, Sebastiaan Mathot wrote:
> Hi Jon,
>
> As you know, I've been playing around with PsychoPy to create a back-
> end for OpenSesame. I encountered a few issues, which you may be able
> to shed some light on (although I suspect some of them may be a
> property of OpenGL rather than PsychoPy).
>
> THE GOAL
>
> Basically, what I'm doing is creating a canvas class, which offers the
> usual drawing primitives (rect(), line(), ellipse(), etc.) and uses
> PsychoPy to handle the actual drawing. It kind of works, but the goal
> is to make the behavior identical to that of the regular canvas
> backend (which uses PyGame), and this isn't the case yet.
>
> THE PROBLEMS
>
> - I use the ShapeStim() to draw lines and rectangles, but the line
> thickness is being funny. Using a line thickness of 1 results in
> invisible lines, but only when they are horizontal or vertical.
>
I don't get invisible lines when I do this on my mac. :-/
For me it looks exactly 1 pixel wide. Try turning interpolation on/off
for the stimulus?
> - I use the PatchStim() to draw ellipses, but I have the same problem
> here. Basically, I draw a smaller patch inside a bigger patch to get
> an unfilled ellipse, but the resulting line thickness is somewhat
> erratic.
I imagine any erratic behaviour is a matter of anti/aliasing? If not,
could you elaborate on 'erratic'? An elliptical patch 2 pixels wider
than another should give a pretty reasonable circle. Take a look at the
script below showing a bunch of ways to draw a circle/ellipse. I've no
idea what pygame uses to draw its built-in circles.
> Also, I have a hard time getting the color right, but this is
> probably because I have to look into the colorspace method that is
> used for the PatchStim. Am I correct in assuming that colornames
> (e.g., "red") don't work in this case?
No, color names should work fine (see below). But yes, it would be worth
reading up on color spaces:
http://www.psychopy.org/general/colours.html
> - Finally, the pygame and pyglet winTypes do not appear to be
> interchangeable. Specifically, when using pygame and pix units,
> coordinates seem to be misinterpreted and all stimuli are so small
> that they are basically a dot in the center of the monitor. Using the
> same code with pyglet works as expected.
this is a bug, that I'll get to very soon.
cheers,
Jon
#-------circles------
from psychopy import visual, event, filters
import numpy as np
win = visual.Window([800,600], units='pix')
#circle as shape
rad = 100#pix
thetas=np.linspace(0,2*np.pi,num=100)
x,y= rad*np.sin(thetas), rad*np.cos(thetas)
xys = list(np.array([x,y]).transpose()) # yuck - this needs improving ;-)
circle2 = visual.ShapeStim(win, vertices=xys, interpolate=False,
lineWidth=1, lineColor='Aquamarine', pos=[0,0])
circle2.draw()
#circle of two patches
outer = visual.PatchStim(win, size=[100,50],mask='circle',
units='pix', color='red', tex=None)
inner = visual.PatchStim(win, size=[98,48],mask='circle',
units='pix', color=0, tex=None)#NB the screen has color=[0,0,0]
outer.draw()
inner.draw()
#circle as mask
aspect=0.75
outer=filters.makeMask(128, #use power of two
shape='circle',radius=[1,aspect])
inner=filters.makeMask(128, #use power of two
shape='circle',radius=[0.9, 0.9*aspect])#thickness is 10% of radius
#masks have -1 for transparent, +1 for opaque
mask=((outer/2+0.5)-(inner/2+0.5))*2-1
print outer.max(), outer.min()
circle3 = visual.PatchStim(win, size=100,mask=mask,interpolate=True,
units='pix', color=1, tex='sin', pos=[-100,200])
circle3.draw()
circle3.setSize(30) #NB line width will scale size of stim
circle3.draw()
win.flip()
event.waitKeys()
But, on the whole, I would recommend you don't use SimpleImage. Patch is
faster in most cases and can handle more than simple images (rotation,
masking etc)
Jon
--
Dr. Jonathan Peirce
Nottingham Visual Neuroscience
On 13/04/2011 11:20, Sebastiaan Mathot wrote:
> Thanks for the code!
>
> I resolved one of the issues: The funky colors using the PatchStim
> were due to not setting "tex = None". However, the line thickness and
> image scaling issues remain. As you can see in the screenshot, tilted
> lines of 1px are fine, but straight ones are invisible. Similarly,
> ellipses with a line thickness of 1 (made by drawing an inner and an
> outer patch) show gaps. I guess these issues are actually one and the
> same:
> http://files.cogsci.nl/tmp/example.png
OK, I think the issue is a sampling issue - you're trying to draw a very
thin line in between two pixel locations without any antialiasing.
Opengl is doing the best it can to cope with that. Turning interpolation
on for the stimulus will make the line appear, albeit a little blurred,
but I would avoid trying to draw such thin lines unless you put them at
locations centred exactly on a pixel.
> The image that doesn't scale is here:
> http://files.cogsci.nl/software/opensesame/tutorial2/gaze_neutral.png
>
> I read in the doc that, as you said, PatchStim() is recommended over
> SimpleImageStim(). However, the power-of-2 restriction makes the
> PatchStim() unsuitable in this case, because the OpenSesame canvas is
> general purpose and should be able to draw any kind of image. Perhaps
> I'll have the canvas autodetect the dimensions and use PatchStim()
> when possible, but it seems there's no getting around using
> SimpleImageStim() for the moment.
PatchStim sliently resamples an image to be pow2 if it isn't. So you
won't see any difference. If you absolutely want no interpolation done
with your image (never resize, never rotate), then SimpleImage is OK,
but its draw-time is marginally slower because it has to be sent to the
graphics card on each draw.
> I am running Ubuntu 10.10 (which I should have mentioned before, I
> suppose) and I also noted a few issues that may be specific to Linux.
> First, the window frequently fails to intialize (about 75% of the
> time). When you turn Compiz (i.e., the desktop effects) off it works
> fine, but Compiz is on by default on most modern Linux distributions.
> Second, when window.close() is called I get the error below
> (experiment.window is the PsychoPy window). This only happens when the
> application closes as well, not if the window is closed, but the
> application (i.e., the OpenSesame GUI) keeps running. It could be
> something weird in OpenSesame too (or a combination), I'm not really
> sure.
looks like a linux-specific bug in pyglet. But I don't know enough about
the pyglet low-level code (or linux) to be able to fix that.
Jon
This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.
This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.
The reason that you aren't getting shadersdespite asking politely, is
that they aren't currently supported under pygame (and under
pre-opengl2.0 graphics cards on pyglet). Because I wasn't really using
the pygame backend I let that drop. But I have it on my list to
reinstate pygame shader support since quite a few users do seem to be
using it.
Jon