source: misclib/fmri_smooth.m @ 80

Last change on this file since 80 was 80, checked in by tjniskan, 10 years ago
  • Changed the historical "an2_" prefix to "aedes_" in all files. NOTE:

Any script or function relying to Aedes functions will be broken
because of this. Just do a search/replace from "an2_" to "aedes_" in
your files and all should be well...

  • Changed the name of an2_readtab.m to a more informative

aedes_readphasetable.m

File size: 1.8 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 = aedes_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 -----------------------
60nVols = size(data,4);
61for ii=1:nVols
62  if ii==1
63    fprintf(1,'Smoothing volume %d/%d',ii,nVols);
64    bsz = length(sprintf('%d/%d',ii,nVols));
65  else
66    fprintf(1,repmat('\b',1,bsz));
67    bsz = length(sprintf('%d/%d',ii,nVols));
68    fprintf(1,'%d/%d',ii,nVols);
69  end
70  tmp_data = data(:,:,:,ii);
71  smooth_data(:,:,:,ii) = imfilter(tmp_data,s_kernel);
72end
73fprintf(1,'\n');
74
75if nargout>0
76  smooth_data_out = smooth_data;
77end
78
79% Write output files
80if writeSmoothedData
81  aedes_write_nifti(smooth_data,out_file)
82end
Note: See TracBrowser for help on using the repository browser.

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