source: plugins/fmri_plugins/motion_estimate.m

Last change on this file was 136, checked in by tjniskan, 9 years ago
  • Added a plugin for quickly estimating motion in fMRI data using center of mass
  • A small fix for brain_masking.m plugin

M plugins/brain_masking.m
A plugins/fmri_plugins/motion_estimate.m
M aedes_revision.m

File size: 2.0 KB
Line 
1function motion_estimate(DATA,ROI,AddInfo)
2% MOTION_ESTIMATE - Estimate motion using center of mass
3%   (this is an Aedes plugin)
4%
5% Synopsis:
6%
7% Description:
8%
9% Examples:
10%
11% See also:
12%
13
14% This function is a part of Aedes - A graphical tool for analyzing
15% medical images
16%
17% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
18%
19% Department of Physics, Department of Neurobiology
20% University of Kuopio, FINLAND
21%
22% This program may be used under the terms of the GNU General Public
23% License version 2.0 as published by the Free Software Foundation
24% and appearing in the file LICENSE.TXT included in the packaging of
25% this program.
26%
27% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29
30
31% Calculate index vector for center of mass
32data_sz = [size(DATA{1}.FTDATA,1) ...
33  size(DATA{1}.FTDATA,2) ...
34  size(DATA{1}.FTDATA,3) ...
35  size(DATA{1}.FTDATA,4)];
36n1 = 1:data_sz(1);
37n2 = 1:data_sz(2);
38n3 = 1:data_sz(3);
39nSlices = data_sz(3);
40nVols = data_sz(4);
41N2 = repmat(n2,data_sz(1),1);
42N2 = N2(:);
43N1 = n1.';
44N1 = repmat(N1,data_sz(2),1);
45N3 = n3;
46N3 = repmat(N3,length(N2),1);
47N3 = N3(:);
48tmp = [N1 N2];
49C = [repmat(tmp,nSlices,1) N3];
50
51% Calculate center of mass to all volumes
52if AddInfo.isDataMixed
53  COM = zeros(length(DATA),3);
54  for ii=1:length(DATA)
55    data=double(DATA{ii}.FTDATA);
56    COM(ii,:) = data(:).'*C/sum(data(:),'double');
57  end
58else
59  COM = zeros(nVols,3);
60  for ii=1:nVols
61    data=double(DATA{1}.FTDATA(:,:,:,ii));
62    COM(ii,:) = data(:).'*C/sum(data(:),'double');
63  end
64end
65
66% Plot the center of mass indices relative to first volume
67fh=figure;
68ax=axes;
69plot(ax,1:nVols,COM(:,1)-COM(1,1),'b');
70hold on
71plot(ax,1:nVols,COM(:,2)-COM(1,2),'g');
72plot(ax,1:nVols,COM(:,3)-COM(1,3),'r');
73hold off
74
75xlabel(ax,'Volume number');
76ylabel(ax,'Relative movement (pixels)');
77title(ax,'Relative center of mass displacement')
78legend(ax,'Z-dir','Y-dir','X-dir')
79
80
Note: See TracBrowser for help on using the repository browser.

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