source: misclib/fmri_smooth.m @ 61

Last change on this file since 61 was 50, checked in by tjniskan, 11 years ago
  • Fixed a typo in an2_smiswrite.m
  • Added some fmri-specific functions under misclib. These do not

affect Aedes at all.

M an2_smiswrite.m
A misclib/fmri_smooth.m
A misclib/fmri_filter.m
A misclib/fmri_corr.m
M an2_revision.m

File size: 1.5 KB
Line 
1function smooth_data_out = fmri_smooth(data,fwhm_sz,voxsize,out_file)
2
3if nargin==4
4  writeSmoothedData = true;
5else
6  writeSmoothedData = false;
7end
8
9if nargin<3 || isempty(voxsize)
10  fwhmInPixels = true;
11else
12  fwhmInPixels = false;
13end
14
15% Check if data is an Aedes structure
16if isstruct(data)
17  data = data.FTDATA;
18elseif ischar(data)
19  data = an2_data_read(data);
20  data = data.FTDATA;
21end
22
23smooth_data = zeros(size(data));
24
25% Check data dimensions
26if any(ndims(data)==[4,3]) && size(data,3)~=1
27  use3Dkernel = true;
28else
29  use3Dkernel = false;
30end
31
32% Calculate standard deviations using FWHM
33if fwhmInPixels
34   stds = fwhm_sz/sqrt(8*log(2));
35else
36  stds = (fwhm_sz/sqrt(8*log(2)))./voxsize;
37end
38
39% Calculate kernel size using STDs
40kernel_sz = round(6*stds);
41
42% Construct the smoothing kernel
43if use3Dkernel
44  [x,y,z] = meshgrid(-kernel_sz(2):kernel_sz(2),...
45        -kernel_sz(1):kernel_sz(1),...
46        -kernel_sz(3):kernel_sz(3));
47  s_kernel = exp(-(x).^2/(2*(stds(1)).^2)...
48        -(y).^2/(2*(stds(2)).^2)...
49        -(z).^2/(2*(stds(3)).^2));
50  s_kernel = s_kernel/sum(s_kernel(:));
51else
52  [x,y] = meshgrid(-kernel_sz(2):kernel_sz(2),...
53        -kernel_sz(1):kernel_sz(1));
54  s_kernel = exp(-(x).^2/(2*(stds(1)).^2)...
55        -(y).^2/(2*(stds(2)).^2));
56  s_kernel = s_kernel/sum(s_kernel(:));
57end
58
59% Smooth the image data -----------------------
60for ii=1:size(data,4)
61  tmp_data = data(:,:,:,ii);
62  smooth_data(:,:,:,ii) = imfilter(tmp_data,s_kernel);
63end
64
65if nargout>0
66  smooth_data_out = smooth_data;
67end
68
69% Write output files
70if writeSmoothedData
71  an2_write_nifti(smooth_data,out_file)
72end
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008