Blur Edges of Oval

Hi all,

I am trying to blur the edges of an oval. I usually use the "filloval" function when drawing my stimuli. Does anyone have any suggestions as to how I could do this?

Best,
Hrag
As suggested in a recent thread (http://tech.groups.yahoo.com/group/psychtoolbox/message/12017), you can use PsychDrawSprites2D to easily draw some texture at different locations.
What you can do then (following Peter):
- create a matrix with a single dot.
- blur it by convolution with a Gaussian
- upload to gfx card, 'maketexture'
- use PsychDrawSprites2D to draw this dot in many locations. To get the blending right, you'll need to make sure your texture also has the blurred alpha layer (approaching 0 at the edges) and set up the blend function correctly (GL_ONE< GL_ONE looked good for me when I played with such things.
Read the whole post I linked above, Mario gave some good hints there.
But, of course, the way of the shader is very cool, and far more flexible as you can blur anything on the screen, and you'll not be stuck with this single dot that you pregenerated. So getting to grips with that will be a worthy future investment.
Best,
Dee

On Fri, Apr 8, 2011 at 04:08, IanA <iandol@...> wrote:

I suspect that the techniques used in FastFilteredNoiseDemo.m may be modifiable. That constructs a kernel using fspecial, then makes an OpenGL operator with it, then uses TransformTexture before presentation. In your case you need to apply the convolution to the OpenGL buffer itself, I'm not sure what the optimal way or how to apply this to the buffer itself as I've never tried. Read through http://docs.psychtoolbox.org/PsychGLImageProcessing and http://docs.psychtoolbox.org/PsychImaging for more pointers.

Ian



--- In psychtoolbox@yahoogroups.com, Lisandro Kaunitz <luckyluke1979@...> wrote:
>
> Hi all,
>
> I have a similar question with regards to blurring dots. I need to blur many
> dots that are presented on the screen.
>
>
> The problem with the approach of using a texture is that I need to draw many
> moving dots (I need to redraw the dots on every frame to adjust their
> positions), blur each one of them with a Gaussian, create a texture and then
> present them on the screen. In this way I cannot make use of 'drawDots', as
> 'drawDots' works directly on the video buffer.
>
> Is there an alternative approach to blurring dots than creating the texture? Am
> I missing some psychtoolbox function that can do this directly on the video
> buffer?
>
> Thank you
>
> Lisandro Kaunitz
>
> University of Trento
> Center for Mind/Brain Sciences (CIMeC)
> Via delle Regole 101
> 38060 Mattarello (TN)
> Italy
> Phone: +39 0461 882753
> E-mail: lisandro.kaunitz@...
>
>
>
>
>
>
> ________________________________
> De: peter.scarfe <peterscarfe@...>

> Para: psychtoolbox@yahoogroups.com
> Enviado: jueves, 7 de abril, 2011 15:22:50
> Asunto: [psychtoolbox] Re: Blur Edges of Oval
>
>
> A simple way would be to create an oval image as a texture.
>
> (1) Make a binary image matrix with an oval in it.
> (2) Convolve it with a Gaussian to blur the edges.
> (3) Convert to a PTB texture.
>
> Then just draw to screen as normal.
>
> Peter
>
> --- In psychtoolbox@yahoogroups.com, "hrag.pailian" <hrag.pailian@> wrote:
> >
> > Hi all,
> >
> > I am trying to blur the edges of an oval. I usually use the "filloval"
> >function when drawing my stimuli. Does anyone have any suggestions as to how I
> >could do this?
> >
> > Best,
> > Hrag
> >
>


Yep, Diederick's proposal is the most efficient if you just need to draw lots of blurred dots.
If the dots need to interact with each other instead of just overdrawing each other, then combine with the blending and framebuffer setup approach in GarboriumDemo.

Image processing - convolving the whole image with a low pass filter - as in FastFilteredNoiseDemo or ConvolutionKernelTest makes sense for complex stimuli. The most simple way at the moment would be to create a offscreen window, draw into it, then use the 'TransformTexture' command as in those demos to convolve it, then 'DrawTexture' it into the onscreen window.

DrawManuallyAntiAliasedTextDemo shows another application which does "manual" anti-aliasing of text via low pass filtering and downsampling without 'TransformTexture' but can only apply single pass operations like simple convolution with small kernels.

-mario

--- In psychtoolbox@yahoogroups.com, "Diederick C. Niehorster" <dcnieho@...> wrote:
>
> As suggested in a recent thread (
> http://tech.groups.yahoo.com/group/psychtoolbox/message/12017), you can use
> PsychDrawSprites2D to easily draw some texture at different locations.
>
> What you can do then (following Peter):
> - create a matrix with a single dot.
> - blur it by convolution with a Gaussian
> - upload to gfx card, 'maketexture'
> - use PsychDrawSprites2D to draw this dot in many locations. To get the
> blending right, you'll need to make sure your texture also has the blurred
> alpha layer (approaching 0 at the edges) and set up the blend function
> correctly (GL_ONE< GL_ONE looked good for me when I played with such things.
>
> Read the whole post I linked above, Mario gave some good hints there.
>
> But, of course, the way of the shader is very cool, and far more flexible as
> you can blur anything on the screen, and you'll not be stuck with this
> single dot that you pregenerated. So getting to grips with that will be a
> worthy future investment.
>
> Best,
> Dee
>
> On Fri, Apr 8, 2011 at 04:08, IanA <iandol@...> wrote:
>
> >
> >
> > I suspect that the techniques used in FastFilteredNoiseDemo.m may be
> > modifiable. That constructs a kernel using fspecial, then makes an OpenGL
> > operator with it, then uses TransformTexture before presentation. In your
> > case you need to apply the convolution to the OpenGL buffer itself, I'm not
> > sure what the optimal way or how to apply this to the buffer itself as I've
> > never tried. Read through
> > http://docs.psychtoolbox.org/PsychGLImageProcessing and
> > http://docs.psychtoolbox.org/PsychImaging for more pointers.
> >
> > Ian
> >
> >
> > --- In psychtoolbox@yahoogroups.com, Lisandro Kaunitz <luckyluke1979@>
> > wrote:
> > >
> > > Hi all,
> > >
> > > I have a similar question with regards to blurring dots. I need to blur
> > many
> > > dots that are presented on the screen.
> > >
> > >
> > > The problem with the approach of using a texture is that I need to draw
> > many
> > > moving dots (I need to redraw the dots on every frame to adjust their
> > > positions), blur each one of them with a Gaussian, create a texture and
> > then
> > > present them on the screen. In this way I cannot make use of 'drawDots',
> > as
> > > 'drawDots' works directly on the video buffer.
> > >
> > > Is there an alternative approach to blurring dots than creating the
> > texture? Am
> > > I missing some psychtoolbox function that can do this directly on the
> > video
> > > buffer?
> > >
> > > Thank you
> > >
> > > Lisandro Kaunitz
> > >
> > > University of Trento
> > > Center for Mind/Brain Sciences (CIMeC)
> > > Via delle Regole 101
> > > 38060 Mattarello (TN)
> > > Italy
> > > Phone: +39 0461 882753
> > > E-mail: lisandro.kaunitz@
> > >
> > >
> > >
> > >
> > >
> > >
> > > ________________________________
> > > De: peter.scarfe <peterscarfe@>
> >
> > > Para: psychtoolbox@yahoogroups.com
> > > Enviado: jueves, 7 de abril, 2011 15:22:50
> > > Asunto: [psychtoolbox] Re: Blur Edges of Oval
> > >
> > >
> > > A simple way would be to create an oval image as a texture.
> > >
> > > (1) Make a binary image matrix with an oval in it.
> > > (2) Convolve it with a Gaussian to blur the edges.
> > > (3) Convert to a PTB texture.
> > >
> > > Then just draw to screen as normal.
> > >
> > > Peter
> > >
> > > --- In psychtoolbox@yahoogroups.com, "hrag.pailian" <hrag.pailian@>
> > wrote:
> > > >
> > > > Hi all,
> > > >
> > > > I am trying to blur the edges of an oval. I usually use the "filloval"
> > > >function when drawing my stimuli. Does anyone have any suggestions as to
> > how I
> > > >could do this?
> > > >
> > > > Best,
> > > > Hrag
> > > >
> > >
> >
> >
> >
>
--- In psychtoolbox@yahoogroups.com, "peter.scarfe" <peterscarfe@...> wrote:
>
> A simple way would be to create an oval image as a texture.
>
> (1) Make a binary image matrix with an oval in it.
> (2) Convolve it with a Gaussian to blur the edges.
> (3) Convert to a PTB texture.
>
> Then just draw to screen as normal.
>
> Peter
>

Yes. If you need to draw many ovals of different size and shape, you could use the image processing methods suggested in msg 12058 to do this on the gpu which will be much faster. You'll also need to setup proper alpha blending and alpha values if overlapping ovals should combine properly.

If you just need to get anti-aliased smooth looking ovals, no "strong" blurring, you can also enable multi sampling by setting the 'multisample' parameter of Screen('OpenWindow', ...) to a non-zero value. The value defines the number of samples to use: Larger number --> slower drawing, but higher quality.

-mario


>
> --- In psychtoolbox@yahoogroups.com, "hrag.pailian" <hrag.pailian@> wrote:
> >
> > Hi all,
> >
> > I am trying to blur the edges of an oval. I usually use the "filloval" function when drawing my stimuli. Does anyone have any suggestions as to how I could do this?
> >
> > Best,
> > Hrag
> >
>