source: an2_res2table.m @ 63

Last change on this file since 63 was 53, checked in by tjniskan, 11 years ago
  • Fixed a bug in an2_readfid.m that in some cases didn't calculate

the array length in procpar correctly. Also changed the handling of
array parameter in an2_readprocpar.m.

  • Fixed a bug in an2_rot3d.m
  • Fixed bugs here and there
  • Added some incomplete code for upcoming new features.

M misclib/nifti4dto3d.m
M misclib/fmri_corr.m
M an2_rot3d.m
M an2_revision.m
M an2_readprocpar.m
M an2_data_read.m
M aedes.m
M an2_res2table.m
M an2_copy_roi.m
M an2_roi_copy_gui.m
M an2_readfid.m
M an2_saveres.m
M an2_write_nifti.m

File size: 6.7 KB
Line 
1function ResTable = an2_res2table(Res,varargin)
2% AN2_RES2TABLE -
3%   
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% Defaults
32SortByRoi = false; % Sort by ROIs or FileNames.
33DecSep = ',';
34NumDec = 3;
35ResTable = {};
36ResFileName = '';
37dirs = [1 2 3]; % By default show all directions
38
39% Check Res-structure
40if ~isstruct(Res) && ~isfield(Res,'Stat') && ...
41      ~isfield(Res,'FileInfo') && ~isfield(Res,'DateTime')
42  error('Invalid Res-structure')
43end
44
45
46% Parse varargin
47for ii=1:2:length(varargin)
48  switch lower(varargin{ii})
49   case 'sortbyroi'
50    SortByRoi = varargin{ii+1};
51   case 'decsep'
52    DecSep = varargin{ii+1};
53   case 'numdec'
54    NumDec = varargin{ii+1};
55   case 'resfilename'
56    ResFileName = varargin{ii+1};
57   case {'directions','dirs'}
58    tmp = varargin{ii+1};
59    dirs = find(ismember('XYZ',tmp));
60   otherwise
61    error('Unknown parameter %s',varargin{ii})
62  end
63end
64
65FileInfo = Res.FileInfo;
66DateTime = Res.DateTime;
67
68nRois = length(Res.Stat);
69
70% Ensure backward compatibility
71if ~isfield(Res.Stat(1),'Sum')
72  for ii=1:length(Res.Stat)
73    Res.Stat(ii).Sum = NaN(1,length(Res.Stat(ii).Mean));
74    if isfield(Res.Stat(1),'XD')
75      Res.Stat(ii).XD.Sum = NaN(1,length(Res.Stat(ii).XD.Mean));
76      Res.Stat(ii).YD.Sum = NaN(1,length(Res.Stat(ii).YD.Mean));
77      Res.Stat(ii).ZD.Sum = NaN(1,length(Res.Stat(ii).ZD.Mean));
78    end
79  end
80end
81
82% Allocate space for ResTable
83if Res.Stat(1).isMixed
84  if SortByRoi
85    ResTable=cell(1,7);
86  else
87    ResTable=cell(1,8);
88  end
89else
90  %ResTable=cell(7+nRois+5*3+nRois*3*length(Res.Stat(1).Mean),6);
91  ResTable=cell(1,7);
92end
93
94%size(ResTable)
95% Write date, time and Res filename
96ResTable{1,1} = ResFileName; % Res-file name
97ResTable{2,1} = DateTime; %
98
99
100% concatenate file and path names
101fnames={};
102for ii=1:length(Res.FileInfo.DataFileName)
103  fnames{ii} = [Res.FileInfo.DataPathName{ii},Res.FileInfo.DataFileName{ii}];
104end
105% $$$ fnames=cellstr([char(Res.FileInfo.DataPathName) ...
106% $$$                char(Res.FileInfo.DataFileName)]);
107
108%% Parse Res structure
109start_ind = 3;
110
111% Parse mixed type results
112if Res.Stat(1).isMixed
113  for ii=1:nRois
114    if SortByRoi
115      start_ind = start_ind+2;
116      mtrx=[Res.Stat(ii).Mean(:) Res.Stat(ii).Std(:) Res.Stat(ii).Sum(:) ...
117            Res.Stat(ii).Min(:) Res.Stat(ii).Max(:) ...
118            Res.Stat(ii).PixelCount(:)];
119      ResTable{start_ind,1}=['ROI: ',Res.Stat(ii).Label];
120      ResTable(start_ind+1:start_ind+2,:) = {'Filename','Mean','STD','Sum','Min','Max',...
121                          'Pixel count';'------','------','------','------','------',...
122                          '------','------'};
123      ResTable(start_ind+3:start_ind+3+length(Res.Stat(ii).Mean)-1,1) = fnames;
124      ResTable(start_ind+3:start_ind+3+length(Res.Stat(ii).Mean)-1,2:end-1) = ...
125          strrep(an2_cellsprintf(['%.' num2str(NumDec) 'f'],mtrx(:,1:end-1)),'.', ...
126                 DecSep);
127      ResTable(start_ind+3:start_ind+3+length(Res.Stat(ii).Mean)-1,end) = ...
128          strrep(an2_cellsprintf(['%.0f'],mtrx(:,end)),'.', ...
129                 DecSep);
130      start_ind = start_ind+3+size(mtrx,1);
131    else
132      mtrx=[Res.Stat(ii).Mean(:) Res.Stat(ii).Std(:) Res.Stat(ii).Sum(:) Res.Stat(ii).Min(:) Res.Stat(ii).Max(:) ...
133            Res.Stat(ii).PixelCount(:)];
134      ResTable(start_ind+1:start_ind+2,:) = {'Filename','ROI','Mean','STD','Sum','Min','Max',...
135                          'Pixel count';'------','------','------','------','------',...
136                          '------','------','------'};
137      ResTable(start_ind+2+ii:nRois:start_ind+3+nRois*length(Res.Stat(ii).Mean)-1,1) ...
138          = fnames;
139      ResTable(start_ind+2+ii:nRois:start_ind+3+nRois*length(Res.Stat(ii).Mean)-1,2) ...
140          = {Res.Stat(ii).Label};
141      ResTable(start_ind+2+ii:nRois:start_ind+3+nRois*length(Res.Stat(ii).Mean)-1,3:end-1) ...
142          = strrep(an2_cellsprintf(['%.' num2str(NumDec) 'f'],mtrx(:,1:end-1)),'.', ...
143                   DecSep);
144      ResTable(start_ind+2+ii:nRois:start_ind+3+nRois*length(Res.Stat(ii).Mean)-1,end) = ...
145          strrep(an2_cellsprintf(['%.0f'],mtrx(:,end)),'.', ...
146                 DecSep);
147    end
148  end
149else % Parse normal type results
150
151    % Construct totals
152    ResTable{5,1} = 'TOTAL';
153    ResTable(6:7,:) = {'ROI','Mean','STD','Sum','Min','Max','Pixel count';...
154                       '------','------','------','------',...
155                       '------','------','------'};
156    RowInd = 8;
157    for kk=1:nRois
158      totals = [Res.Stat(kk).Mean,Res.Stat(kk).Std,Res.Stat(kk).Sum,Res.Stat(kk).Min,...
159               Res.Stat(kk).Max];
160      ResTable{RowInd,1} = Res.Stat(kk).Label;
161      ResTable(RowInd,2:6) = strrep(an2_cellsprintf(['%.' num2str(NumDec) 'f'],...
162                                                  totals),'.',DecSep);
163      ResTable(RowInd,7) =  strrep(an2_cellsprintf('%.0f',Res.Stat(kk).PixelCount),'.',...
164                                     DecSep);
165      RowInd=RowInd+1;
166    end
167   
168    dir_str = {'X-Direction','XD';...
169               'Y-Direction','YD';...
170               'Z-Direction','ZD'};
171   
172   
173    for kk=dirs
174      % Construct X, Y, and Z directions
175      RowInd = RowInd+2;
176      D = dir_str{kk,2};
177      ResTable{RowInd,1} = dir_str{kk,1};
178      ResTable(RowInd+1:RowInd+2,:) = {'ROI','Mean','STD','Sum','Min','Max','Pixel count';...
179                          '------','------','------','------',...
180                          '------','------','------'};
181      RowInd=RowInd+3;
182      for ii=1:nRois
183        totals = [Res.Stat(ii).(D).Mean(:),Res.Stat(ii).(D).Std(:),Res.Stat(ii).(D).Sum(:),...
184                  Res.Stat(ii).(D).Min(:),...
185                  Res.Stat(ii).(D).Max(:)];
186        ResTable(RowInd:RowInd+length(totals(:,1))-1,1) = ...
187            cellstr(repmat(Res.Stat(ii).Label,length(totals(:,1)),1));
188        ResTable(RowInd:RowInd+length(totals(:,1))-1,2:end-1) = ...
189            strrep(an2_cellsprintf(['%.' num2str(NumDec) 'f'],...
190                               totals),'.',DecSep);
191        ResTable(RowInd:RowInd+length(totals(:,1))-1,end) = ...
192            strrep(an2_cellsprintf('%.0f',Res.Stat(ii).(D).PixelCount),'.',...
193                   DecSep);
194        RowInd = RowInd+length(totals(:,1));
195      end
196    end
197
198end
199
Note: See TracBrowser for help on using the repository browser.

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