File: Create2DGaussianBlurShader.m

package info (click to toggle)
psychtoolbox-3 3.0.14.20170103%2Bgit6-g605ff5c.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 103,044 kB
  • ctags: 69,483
  • sloc: ansic: 167,371; cpp: 11,232; objc: 4,708; sh: 1,875; python: 383; php: 344; makefile: 207; java: 113
file content (56 lines) | stat: -rw-r--r-- 1,877 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function blurshader = Create2DGaussianBlurShader(stddev, width)
% blurshader = Create2DGaussianBlurShader(stddev, width)
% EXPERIMENTAL - THIS FEATURE IS IN BETA-STAGE AND MAY CHANGE
% IN THE FUTURE OR NOT WORK AT ALL IN THE PRESENT!
%
% Create a GLSL shader which uses a 2D gaussian filter kernel to
% apply gaussian blur onto a texture. Returns the handle 'blurshader',
% which can be used via glUseProgram(blurshader) to activate the shader.
%
% stddev = Standard deviation of kernel to use. Defaults to 2.5.
% width  = Width of filter-kernel. Currently only a width of 5 is
% supported, so this argument is optional and defaults to 5.
%
% Currently you will need the Matlab imageprocessing toolbox for this to
% work, as we use the toolbox function 'fspecial' to compute the filter
% kernel.
%
% Example of use:
%
% Somewhere during initialization of your script you call:
% blurshader = Create2DGaussianBlurShader(2.5);
%
% When you want to draw an image blurred with a gaussian lowpass, you do:
%
% glUseProgram(blurshader);
% Screen('DrawTexture', win, mytexture, ....);
% glUseProgram(0);
%

% History:
% 15.04.2006 written by Mario Kleiner.

if nargin < 1
    stddev = 2.5;
end;

if nargin < 2 || isempty(width)
    width = 11;
end;

if width~=11
%    error('Create2DGaussianBlurShader: Invalid width specified. Currently only width=5 supported.');
end;

% Build and initialize gaussian blur shader (5x5, stddev=2.5):
try
    % Use the imageprocssing toolbox function fspecial for creation of
    % kernel:
    kernel = fspecial('gaussian', width, stddev);
catch
    error('Create2DGaussianBlurShader failed: You do not seem to have the image processing toolbox installed.');
end;

% Create shader from convolution kernel and return handle to it:
blurshader = EXPCreateStatic2DConvolutionShader(kernel);
return;