-
Notifications
You must be signed in to change notification settings - Fork 6
/
SmoothRealTime2.m
40 lines (33 loc) · 1.16 KB
/
SmoothRealTime2.m
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
function [outputLastPat] = SmoothRealTime2(inputLastPat,roiDims,roiInds,FWHM)
% function [outputPatVec] = SmoothRealTime(inputPatVec,roiDims,roiInds,FWHM)
%
% Inputs:
% - inputLastPat : last pattern acquired [1 x voxels]
% - roiDims : roi dimensions [mask width x mask height x slices]
% - roiInds : roi indices [= find(mask)];
% - FWHM : full width half max of gaussian
%
% Outputs:
% - outputLastPat: smoothed version of last pattern acquired [1 x voxels]
%
%
% MdB, 8/2011
%smoothing parameters
smooth_kernelsize = [3 3 3]; %[units]
voxel_size = 3; %[mm]
smooth_sigma = (FWHM/voxel_size)/(2*sqrt(2*log(2)));
% create a mask array to normalize the smoothing at the boundaries
% of the masked area
norm = zeros(roiDims);
norm(roiInds) = 1;
%convert 1D pattern vector to 3D pattern volume
inputLastPatVol = zeros(roiDims);
inputLastPatVol(roiInds) = inputLastPat;
%smooth in 3D
inputLastPatVol = smooth3(inputLastPatVol,'gaussian',smooth_kernelsize,smooth_sigma);
norm = smooth3(norm,'gaussian',smooth_kernelsize,smooth_sigma);
% normalize
result = inputLastPatVol ./ norm;
%replace in pattern matrix
outputLastPat = result(roiInds);
end