Apply Gaussian blur to 'DrawOval'?

Hi, I am drawing ellipses to a display monitor. Currently I am using Screen('DrawOval'...) to accomplish this.


That part works fine, but I'd like to apply a Gaussian blur to the ellipses, so that they are displayed with soft, rather than hard, edges.  Code is below, and can be run to display a hard-edged oval. All I need is to soften the dang edges, ideally with a Gaussian blur!


Any ideas? Thank you!


%% Prep Screen

gray = [171, 171, 171];

screens=Screen('Screens');

whichScreen=max(Screen('Screens'));

Screen('Preference', 'SkipSyncTests', 0);

[theWindow,theRect]=Screen('OpenWindow',whichScreen, gray, [0 0 800 600]);

 

%% Screen Locations

wid = 120;

heit = 120;

halfwid = .5*wid;

halfheit = .5*heit;

[XC, YC] = RectCenter(theRect);

Loc1 = [XC-halfwid, YC - halfheit, XC + halfwid, YC + halfheit];

 

%% Display Shape

Screen('FrameOval', theWindow, [130 130 130], [Loc1], 10); % This is the shape I want to have soft edges

Screen('Flip', theWindow);

 

 

WaitSecs(3);

close 'all';

sca


I'm using Screen('DrawOval'...) to show ellipses on a display monitor.

But, I'd like to apply a Gaussian blur to the edges of the ellipse, so that the edges are soft, rather than hard. I have posted code below that give the idea for how I'm drawing ellipses to the display monitor. All I need now is to soften the dang edges of the ellipse, ideally with a Gaussian blur!

Any ideas? Thank you! Also note that I'm open to something other than Screen('DrawOval'..), if that would work better.


%% Prep Screen

gray = [171, 171, 171];

screens=Screen('Screens');

whichScreen=max(Screen('Screens'));

Screen('Preference', 'SkipSyncTests', 0);

[theWindow,theRect]=Screen('OpenWindow',whichScreen, gray, [0 0 800 600]);


%% Screen Locations

wid = 120;

heit = 120;

halfwid = .5*wid;

halfheit = .5*heit;

[XC, YC] = RectCenter(theRect);

Loc1 = [XC-halfwid, YC - halfheit, XC + halfwid, YC + halfheit];

%% Display Shape

Screen('FrameOval', theWindow, [130 130 130], [Loc1], 10); % This is the ellipse I want to give soft edges to

Screen('Flip', theWindow);

WaitSecs(3);

close 'all';

sca


This is not exactly Gaussian blur (too narrow), but some kind of smoothing edge. You can play the numbers to create mask to make the edge you like. -Xiangrui

outerRad = wid/2-10;
innerRad = outerRad - 20;
[x, y] = ndgrid((1:wid)-halfwid, (1:heit)-halfheit);
r = sqrt(x.^2 + y.^2);
mask = exp(-((r-(outerRad+innerRad)/2)/(outerRad-innerRad)*2).^2); % 0 to 1
img = mask * (130-gray(1)) + gray(1); % take care of range and background
tex = Screen('MakeTexture', theWindow, img);
Screen('DrawTexture', theWindow, tex);

I contributed procedural smoothed discs to PTB recently, check out ProceduralSmoothedDiscsDemo.m and  ProceduralSmoothedDiscMaskDemo.m -- they utilise smoothing generated on the GPU, and alpha channel so they blend to the background. The mask demo demonstrates you can "invert" them to create circular masks.
You said: "If you need full control over filter
applied you can draw your oval into a offscreen window, then use our
image processing functions to apply a convolution kernel of your
choice, e.g., gaussian to that offscreen window before drawing it to
the actual onscreen window." Can you tell me how to do this? Speak to me like I was a child :)
Minified demo:

PsychDefaultSetup(2);
screenid = max(Screen('Screens'));
PsychImaging('PrepareConfiguration');
[win, winRect] = PsychImaging('OpenWindow', screenid, 0.5);
Screen('BlendFunction', win, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
vsize = 500;
radius = vsize / 2;
sigma = 85;
colour = [0.3 0 0 1];
disctexture = CreateProceduralSmoothedDisc(win, vsize,...
    vsize, [], radius, sigma, true, 1);
while ~KbCheck
    Screen('DrawTextures', win, disctexture, [], [], [], [], [], colour);
    Screen('Flip', win);
end
sca;
You're the best. Thank you.