[80] | 1 | function ResTable = aedes_res2table(Res,varargin) |
---|
| 2 | % AEDES_RES2TABLE - |
---|
[2] | 3 | % |
---|
| 4 | % |
---|
| 5 | % Synopsis: |
---|
| 6 | % |
---|
| 7 | % Description: |
---|
| 8 | % |
---|
| 9 | % Examples: |
---|
| 10 | % |
---|
| 11 | % See also: |
---|
| 12 | % |
---|
| 13 | |
---|
[39] | 14 | % This function is a part of Aedes - A graphical tool for analyzing |
---|
[36] | 15 | % medical images |
---|
[2] | 16 | % |
---|
[36] | 17 | % Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi> |
---|
| 18 | % |
---|
[45] | 19 | % Department of Physics, Department of Neurobiology |
---|
[39] | 20 | % University of Kuopio, FINLAND |
---|
[36] | 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. |
---|
[2] | 29 | |
---|
[36] | 30 | |
---|
[2] | 31 | % Defaults |
---|
| 32 | SortByRoi = false; % Sort by ROIs or FileNames. |
---|
| 33 | DecSep = ','; |
---|
| 34 | NumDec = 3; |
---|
| 35 | ResTable = {}; |
---|
| 36 | ResFileName = ''; |
---|
[77] | 37 | dirs = [0 1 2 3 4]; % By default show all directions (1,2,3,4) and total (0) |
---|
[2] | 38 | |
---|
| 39 | % Check Res-structure |
---|
| 40 | if ~isstruct(Res) && ~isfield(Res,'Stat') && ... |
---|
| 41 | ~isfield(Res,'FileInfo') && ~isfield(Res,'DateTime') |
---|
| 42 | error('Invalid Res-structure') |
---|
| 43 | end |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | % Parse varargin |
---|
| 47 | for 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}; |
---|
[77] | 59 | dirs = find(ismember('TXYZV',tmp))-1; |
---|
[2] | 60 | otherwise |
---|
| 61 | error('Unknown parameter %s',varargin{ii}) |
---|
| 62 | end |
---|
| 63 | end |
---|
| 64 | |
---|
| 65 | FileInfo = Res.FileInfo; |
---|
| 66 | DateTime = Res.DateTime; |
---|
| 67 | |
---|
| 68 | nRois = length(Res.Stat); |
---|
| 69 | |
---|
| 70 | % Ensure backward compatibility |
---|
| 71 | if ~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)); |
---|
[77] | 78 | Res.Stat(ii).VD.Sum = NaN(1,length(Res.Stat(ii).VD.Mean)); |
---|
[2] | 79 | end |
---|
| 80 | end |
---|
| 81 | end |
---|
| 82 | |
---|
| 83 | % Allocate space for ResTable |
---|
| 84 | if Res.Stat(1).isMixed |
---|
| 85 | if SortByRoi |
---|
| 86 | ResTable=cell(1,7); |
---|
| 87 | else |
---|
| 88 | ResTable=cell(1,8); |
---|
| 89 | end |
---|
| 90 | else |
---|
| 91 | %ResTable=cell(7+nRois+5*3+nRois*3*length(Res.Stat(1).Mean),6); |
---|
| 92 | ResTable=cell(1,7); |
---|
| 93 | end |
---|
| 94 | |
---|
| 95 | %size(ResTable) |
---|
| 96 | % Write date, time and Res filename |
---|
| 97 | ResTable{1,1} = ResFileName; % Res-file name |
---|
| 98 | ResTable{2,1} = DateTime; % |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | % concatenate file and path names |
---|
| 102 | fnames={}; |
---|
| 103 | for ii=1:length(Res.FileInfo.DataFileName) |
---|
| 104 | fnames{ii} = [Res.FileInfo.DataPathName{ii},Res.FileInfo.DataFileName{ii}]; |
---|
| 105 | end |
---|
| 106 | % $$$ fnames=cellstr([char(Res.FileInfo.DataPathName) ... |
---|
| 107 | % $$$ char(Res.FileInfo.DataFileName)]); |
---|
| 108 | |
---|
| 109 | %% Parse Res structure |
---|
| 110 | start_ind = 3; |
---|
| 111 | |
---|
| 112 | % Parse mixed type results |
---|
| 113 | if 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) = ... |
---|
[80] | 126 | strrep(aedes_cellsprintf(['%.' num2str(NumDec) 'f'],mtrx(:,1:end-1)),'.', ... |
---|
[2] | 127 | DecSep); |
---|
| 128 | ResTable(start_ind+3:start_ind+3+length(Res.Stat(ii).Mean)-1,end) = ... |
---|
[80] | 129 | strrep(aedes_cellsprintf(['%.0f'],mtrx(:,end)),'.', ... |
---|
[2] | 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) ... |
---|
[80] | 143 | = strrep(aedes_cellsprintf(['%.' num2str(NumDec) 'f'],mtrx(:,1:end-1)),'.', ... |
---|
[2] | 144 | DecSep); |
---|
| 145 | ResTable(start_ind+2+ii:nRois:start_ind+3+nRois*length(Res.Stat(ii).Mean)-1,end) = ... |
---|
[80] | 146 | strrep(aedes_cellsprintf(['%.0f'],mtrx(:,end)),'.', ... |
---|
[2] | 147 | DecSep); |
---|
| 148 | end |
---|
| 149 | end |
---|
| 150 | else % Parse normal type results |
---|
| 151 | |
---|
| 152 | % Construct totals |
---|
[77] | 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; |
---|
[80] | 163 | ResTable(RowInd,2:6) = strrep(aedes_cellsprintf(['%.' num2str(NumDec) 'f'],... |
---|
[77] | 164 | totals),'.',DecSep); |
---|
[80] | 165 | ResTable(RowInd,7) = strrep(aedes_cellsprintf('%.0f',Res.Stat(kk).PixelCount),'.',... |
---|
[77] | 166 | DecSep); |
---|
| 167 | RowInd=RowInd+1; |
---|
| 168 | end |
---|
| 169 | else |
---|
| 170 | RowInd = 3; |
---|
[2] | 171 | end |
---|
| 172 | |
---|
| 173 | dir_str = {'X-Direction','XD';... |
---|
| 174 | 'Y-Direction','YD';... |
---|
[77] | 175 | 'Z-Direction','ZD';... |
---|
| 176 | 'V-Direction','VD'}; |
---|
[2] | 177 | |
---|
| 178 | |
---|
| 179 | for kk=dirs |
---|
[77] | 180 | if kk==0 |
---|
| 181 | continue |
---|
| 182 | end |
---|
| 183 | |
---|
[2] | 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}; |
---|
[53] | 188 | ResTable(RowInd+1:RowInd+2,:) = {'ROI','Mean','STD','Sum','Min','Max','Pixel count';... |
---|
[2] | 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) = ... |
---|
[80] | 199 | strrep(aedes_cellsprintf(['%.' num2str(NumDec) 'f'],... |
---|
[2] | 200 | totals),'.',DecSep); |
---|
| 201 | ResTable(RowInd:RowInd+length(totals(:,1))-1,end) = ... |
---|
[80] | 202 | strrep(aedes_cellsprintf('%.0f',Res.Stat(ii).(D).PixelCount),'.',... |
---|
[2] | 203 | DecSep); |
---|
| 204 | RowInd = RowInd+length(totals(:,1)); |
---|
| 205 | end |
---|
| 206 | end |
---|
| 207 | |
---|
| 208 | end |
---|
| 209 | |
---|
[133] | 210 | vers = aedes_getmatlabversion; |
---|
| 211 | if vers>=7.06 |
---|
| 212 | % Convert empty matrices to empty strings |
---|
| 213 | ResTable(cellfun('isempty',ResTable))={''}; |
---|
| 214 | end |
---|