source: aedes_res2table.m

Last change on this file was 133, checked in by tjniskan, 7 years ago
  • Fixed the Matlab version detection bug
  • Added zoom function to mouse wheel
  • Fixed a bug in contrast auto-balancing

M aedes_getmatlabversion.m
M aedes_resviewer.m
M aedes.m
M aedes_res2table.m
M aedes_revision.m
M aedes_juigetfiles.m

File size: 7.0 KB
Line 
1function ResTable = aedes_res2table(Res,varargin)
2% AEDES_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 = [0 1 2 3 4]; % By default show all directions (1,2,3,4) and total (0)
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('TXYZV',tmp))-1;
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      Res.Stat(ii).VD.Sum = NaN(1,length(Res.Stat(ii).VD.Mean));
79    end
80  end
81end
82
83% Allocate space for ResTable
84if Res.Stat(1).isMixed
85  if SortByRoi
86    ResTable=cell(1,7);
87  else
88    ResTable=cell(1,8);
89  end
90else
91  %ResTable=cell(7+nRois+5*3+nRois*3*length(Res.Stat(1).Mean),6);
92  ResTable=cell(1,7);
93end
94
95%size(ResTable)
96% Write date, time and Res filename
97ResTable{1,1} = ResFileName; % Res-file name
98ResTable{2,1} = DateTime; %
99
100
101% concatenate file and path names
102fnames={};
103for ii=1:length(Res.FileInfo.DataFileName)
104  fnames{ii} = [Res.FileInfo.DataPathName{ii},Res.FileInfo.DataFileName{ii}];
105end
106% $$$ fnames=cellstr([char(Res.FileInfo.DataPathName) ...
107% $$$                char(Res.FileInfo.DataFileName)]);
108
109%% Parse Res structure
110start_ind = 3;
111
112% Parse mixed type results
113if Res.Stat(1).isMixed
114  for ii=1:nRois
115    if SortByRoi
116      start_ind = start_ind+2;
117      mtrx=[Res.Stat(ii).Mean(:) Res.Stat(ii).Std(:) Res.Stat(ii).Sum(:) ...
118            Res.Stat(ii).Min(:) Res.Stat(ii).Max(:) ...
119            Res.Stat(ii).PixelCount(:)];
120      ResTable{start_ind,1}=['ROI: ',Res.Stat(ii).Label];
121      ResTable(start_ind+1:start_ind+2,:) = {'Filename','Mean','STD','Sum','Min','Max',...
122                          'Pixel count';'------','------','------','------','------',...
123                          '------','------'};
124      ResTable(start_ind+3:start_ind+3+length(Res.Stat(ii).Mean)-1,1) = fnames;
125      ResTable(start_ind+3:start_ind+3+length(Res.Stat(ii).Mean)-1,2:end-1) = ...
126          strrep(aedes_cellsprintf(['%.' num2str(NumDec) 'f'],mtrx(:,1:end-1)),'.', ...
127                 DecSep);
128      ResTable(start_ind+3:start_ind+3+length(Res.Stat(ii).Mean)-1,end) = ...
129          strrep(aedes_cellsprintf(['%.0f'],mtrx(:,end)),'.', ...
130                 DecSep);
131      start_ind = start_ind+3+size(mtrx,1);
132    else
133      mtrx=[Res.Stat(ii).Mean(:) Res.Stat(ii).Std(:) Res.Stat(ii).Sum(:) Res.Stat(ii).Min(:) Res.Stat(ii).Max(:) ...
134            Res.Stat(ii).PixelCount(:)];
135      ResTable(start_ind+1:start_ind+2,:) = {'Filename','ROI','Mean','STD','Sum','Min','Max',...
136                          'Pixel count';'------','------','------','------','------',...
137                          '------','------','------'};
138      ResTable(start_ind+2+ii:nRois:start_ind+3+nRois*length(Res.Stat(ii).Mean)-1,1) ...
139          = fnames;
140      ResTable(start_ind+2+ii:nRois:start_ind+3+nRois*length(Res.Stat(ii).Mean)-1,2) ...
141          = {Res.Stat(ii).Label};
142      ResTable(start_ind+2+ii:nRois:start_ind+3+nRois*length(Res.Stat(ii).Mean)-1,3:end-1) ...
143          = strrep(aedes_cellsprintf(['%.' num2str(NumDec) 'f'],mtrx(:,1:end-1)),'.', ...
144                   DecSep);
145      ResTable(start_ind+2+ii:nRois:start_ind+3+nRois*length(Res.Stat(ii).Mean)-1,end) = ...
146          strrep(aedes_cellsprintf(['%.0f'],mtrx(:,end)),'.', ...
147                 DecSep);
148    end
149  end
150else % Parse normal type results
151
152    % Construct totals
153    if any(dirs==0)
154      ResTable{5,1} = 'TOTAL';
155      ResTable(6:7,:) = {'ROI','Mean','STD','Sum','Min','Max','Pixel count';...
156        '------','------','------','------',...
157        '------','------','------'};
158      RowInd = 8;
159      for kk=1:nRois
160        totals = [Res.Stat(kk).Mean,Res.Stat(kk).Std,Res.Stat(kk).Sum,Res.Stat(kk).Min,...
161          Res.Stat(kk).Max];
162        ResTable{RowInd,1} = Res.Stat(kk).Label;
163        ResTable(RowInd,2:6) = strrep(aedes_cellsprintf(['%.' num2str(NumDec) 'f'],...
164          totals),'.',DecSep);
165        ResTable(RowInd,7) =  strrep(aedes_cellsprintf('%.0f',Res.Stat(kk).PixelCount),'.',...
166          DecSep);
167        RowInd=RowInd+1;
168      end
169    else
170      RowInd = 3;
171    end
172   
173    dir_str = {'X-Direction','XD';...
174               'Y-Direction','YD';...
175               'Z-Direction','ZD';...
176               'V-Direction','VD'};
177   
178   
179    for kk=dirs
180      if kk==0
181        continue
182      end
183     
184      % Construct X, Y, and Z directions
185      RowInd = RowInd+2;
186      D = dir_str{kk,2};
187      ResTable{RowInd,1} = dir_str{kk,1};
188      ResTable(RowInd+1:RowInd+2,:) = {'ROI','Mean','STD','Sum','Min','Max','Pixel count';...
189                          '------','------','------','------',...
190                          '------','------','------'};
191      RowInd=RowInd+3;
192      for ii=1:nRois
193        totals = [Res.Stat(ii).(D).Mean(:),Res.Stat(ii).(D).Std(:),Res.Stat(ii).(D).Sum(:),...
194                  Res.Stat(ii).(D).Min(:),...
195                  Res.Stat(ii).(D).Max(:)];
196        ResTable(RowInd:RowInd+length(totals(:,1))-1,1) = ...
197            cellstr(repmat(Res.Stat(ii).Label,length(totals(:,1)),1));
198        ResTable(RowInd:RowInd+length(totals(:,1))-1,2:end-1) = ...
199            strrep(aedes_cellsprintf(['%.' num2str(NumDec) 'f'],...
200                               totals),'.',DecSep);
201        ResTable(RowInd:RowInd+length(totals(:,1))-1,end) = ...
202            strrep(aedes_cellsprintf('%.0f',Res.Stat(ii).(D).PixelCount),'.',...
203                   DecSep);
204        RowInd = RowInd+length(totals(:,1));
205      end
206    end
207
208end
209
210vers = aedes_getmatlabversion;
211if vers>=7.06
212  % Convert empty matrices to empty strings
213  ResTable(cellfun('isempty',ResTable))={''};
214end
Note: See TracBrowser for help on using the repository browser.

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