1 | function 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 |
---|

32 | data_sz = [size(DATA{1}.FTDATA,1) ... |
---|

33 | size(DATA{1}.FTDATA,2) ... |
---|

34 | size(DATA{1}.FTDATA,3) ... |
---|

35 | size(DATA{1}.FTDATA,4)]; |
---|

36 | n1 = 1:data_sz(1); |
---|

37 | n2 = 1:data_sz(2); |
---|

38 | n3 = 1:data_sz(3); |
---|

39 | nSlices = data_sz(3); |
---|

40 | nVols = data_sz(4); |
---|

41 | N2 = repmat(n2,data_sz(1),1); |
---|

42 | N2 = N2(:); |
---|

43 | N1 = n1.'; |
---|

44 | N1 = repmat(N1,data_sz(2),1); |
---|

45 | N3 = n3; |
---|

46 | N3 = repmat(N3,length(N2),1); |
---|

47 | N3 = N3(:); |
---|

48 | tmp = [N1 N2]; |
---|

49 | C = [repmat(tmp,nSlices,1) N3]; |
---|

50 | |
---|

51 | % Calculate center of mass to all volumes |
---|

52 | if 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 |
---|

58 | else |
---|

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 |
---|

64 | end |
---|

65 | |
---|

66 | % Plot the center of mass indices relative to first volume |
---|

67 | fh=figure; |
---|

68 | ax=axes; |
---|

69 | plot(ax,1:nVols,COM(:,1)-COM(1,1),'b'); |
---|

70 | hold on |
---|

71 | plot(ax,1:nVols,COM(:,2)-COM(1,2),'g'); |
---|

72 | plot(ax,1:nVols,COM(:,3)-COM(1,3),'r'); |
---|

73 | hold off |
---|

74 | |
---|

75 | xlabel(ax,'Volume number'); |
---|

76 | ylabel(ax,'Relative movement (pixels)'); |
---|

77 | title(ax,'Relative center of mass displacement') |
---|

78 | legend(ax,'Z-dir','Y-dir','X-dir') |
---|

79 | |
---|

80 | |
---|