[15] | 1 | function ResTable = an2_res2table(Res,varargin) |
---|
| 2 | % AN2_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 = ''; |
---|
| 37 | dirs = [1 2 3]; % By default show all directions |
---|
| 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}; |
---|
| 59 | dirs = find(ismember('XYZ',tmp)); |
---|
| 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)); |
---|
| 78 | end |
---|
| 79 | end |
---|
| 80 | end |
---|
| 81 | |
---|
| 82 | % Allocate space for ResTable |
---|
| 83 | if Res.Stat(1).isMixed |
---|
| 84 | if SortByRoi |
---|
| 85 | ResTable=cell(1,7); |
---|
| 86 | else |
---|
| 87 | ResTable=cell(1,8); |
---|
| 88 | end |
---|
| 89 | else |
---|
| 90 | %ResTable=cell(7+nRois+5*3+nRois*3*length(Res.Stat(1).Mean),6); |
---|
| 91 | ResTable=cell(1,7); |
---|
| 92 | end |
---|
| 93 | |
---|
| 94 | %size(ResTable) |
---|
| 95 | % Write date, time and Res filename |
---|
| 96 | ResTable{1,1} = ResFileName; % Res-file name |
---|
| 97 | ResTable{2,1} = DateTime; % |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | % concatenate file and path names |
---|
| 101 | fnames={}; |
---|
| 102 | for ii=1:length(Res.FileInfo.DataFileName) |
---|
| 103 | fnames{ii} = [Res.FileInfo.DataPathName{ii},Res.FileInfo.DataFileName{ii}]; |
---|
| 104 | end |
---|
| 105 | % $$$ fnames=cellstr([char(Res.FileInfo.DataPathName) ... |
---|
| 106 | % $$$ char(Res.FileInfo.DataFileName)]); |
---|
| 107 | |
---|
| 108 | %% Parse Res structure |
---|
| 109 | start_ind = 3; |
---|
| 110 | |
---|
| 111 | % Parse mixed type results |
---|
| 112 | if 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) = ... |
---|
[15] | 125 | strrep(an2_cellsprintf(['%.' num2str(NumDec) 'f'],mtrx(:,1:end-1)),'.', ... |
---|
[2] | 126 | DecSep); |
---|
| 127 | ResTable(start_ind+3:start_ind+3+length(Res.Stat(ii).Mean)-1,end) = ... |
---|
[15] | 128 | strrep(an2_cellsprintf(['%.0f'],mtrx(:,end)),'.', ... |
---|
[2] | 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) ... |
---|
[15] | 142 | = strrep(an2_cellsprintf(['%.' num2str(NumDec) 'f'],mtrx(:,1:end-1)),'.', ... |
---|
[2] | 143 | DecSep); |
---|
| 144 | ResTable(start_ind+2+ii:nRois:start_ind+3+nRois*length(Res.Stat(ii).Mean)-1,end) = ... |
---|
[15] | 145 | strrep(an2_cellsprintf(['%.0f'],mtrx(:,end)),'.', ... |
---|
[2] | 146 | DecSep); |
---|
| 147 | end |
---|
| 148 | end |
---|
| 149 | else % 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; |
---|
[15] | 161 | ResTable(RowInd,2:6) = strrep(an2_cellsprintf(['%.' num2str(NumDec) 'f'],... |
---|
[2] | 162 | totals),'.',DecSep); |
---|
[15] | 163 | ResTable(RowInd,7) = strrep(an2_cellsprintf('%.0f',Res.Stat(kk).PixelCount),'.',... |
---|
[2] | 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}; |
---|
[53] | 178 | ResTable(RowInd+1:RowInd+2,:) = {'ROI','Mean','STD','Sum','Min','Max','Pixel count';... |
---|
[2] | 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) = ... |
---|
[15] | 189 | strrep(an2_cellsprintf(['%.' num2str(NumDec) 'f'],... |
---|
[2] | 190 | totals),'.',DecSep); |
---|
| 191 | ResTable(RowInd:RowInd+length(totals(:,1))-1,end) = ... |
---|
[15] | 192 | strrep(an2_cellsprintf('%.0f',Res.Stat(ii).(D).PixelCount),'.',... |
---|
[2] | 193 | DecSep); |
---|
| 194 | RowInd = RowInd+length(totals(:,1)); |
---|
| 195 | end |
---|
| 196 | end |
---|
| 197 | |
---|
| 198 | end |
---|
| 199 | |
---|