[80] | 1 | function Res = aedes_roi_stats(DATA,ROI) |
---|
| 2 | % AEDES_ROI_STATS - Calculate ROI statistics |
---|
[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 | Res = []; |
---|
| 32 | |
---|
| 33 | %% Check input arguments |
---|
| 34 | if nargin<2 |
---|
| 35 | error('Two input arguments are required') |
---|
| 36 | elseif nargin>2 |
---|
| 37 | error('Too many input arguments') |
---|
| 38 | end |
---|
| 39 | |
---|
| 40 | % Ensure that DATA is a cell array |
---|
| 41 | if ~iscell(DATA) |
---|
| 42 | DATA = {DATA}; |
---|
| 43 | end |
---|
| 44 | |
---|
| 45 | % if ROI is empty, return empty |
---|
| 46 | if isempty(ROI) |
---|
| 47 | return |
---|
| 48 | end |
---|
| 49 | |
---|
| 50 | % Check if data is in mixed form |
---|
| 51 | if length(DATA)>1 || ndims(DATA{1}.FTDATA)==2 |
---|
| 52 | isDataMixed = true; |
---|
| 53 | else |
---|
| 54 | isDataMixed = false; |
---|
| 55 | end |
---|
| 56 | |
---|
| 57 | % Generate timestamp |
---|
| 58 | DateTime = datestr(now); |
---|
| 59 | |
---|
| 60 | % Generate file info |
---|
| 61 | for ii=1:length(DATA) |
---|
| 62 | FileInfo.DataFileName{ii} = DATA{ii}.HDR.fname; |
---|
| 63 | FileInfo.DataPathName{ii} = DATA{ii}.HDR.fpath; |
---|
| 64 | end |
---|
| 65 | Res.DateTime = DateTime; |
---|
| 66 | Res.FileInfo = FileInfo; |
---|
| 67 | Res.Stat = []; |
---|
| 68 | |
---|
| 69 | for ii=1:length(ROI) |
---|
| 70 | |
---|
| 71 | if isDataMixed |
---|
| 72 | Res.Stat(ii).FileName = {}; |
---|
| 73 | end |
---|
| 74 | |
---|
| 75 | for kk=1:length(DATA) |
---|
| 76 | |
---|
| 77 | % Statistics for mixed data type |
---|
| 78 | if isDataMixed |
---|
| 79 | % Get ROI data |
---|
| 80 | data = DATA{kk}.FTDATA(ROI(ii).voxels{kk}); |
---|
| 81 | data = double(data); |
---|
| 82 | Res.Stat(ii).FileName{kk,1} = DATA{kk}.HDR.fpath; |
---|
| 83 | Res.Stat(ii).FileName{kk,2} = DATA{kk}.HDR.fname; |
---|
| 84 | if kk==1 |
---|
| 85 | Res.Stat(ii).isMixed = true; |
---|
| 86 | Res.Stat(ii).Label = ROI(ii).label; |
---|
| 87 | end |
---|
| 88 | |
---|
| 89 | if isempty(data) |
---|
| 90 | Res.Stat(ii).Mean(kk) = NaN; |
---|
| 91 | Res.Stat(ii).Std(kk) = NaN; |
---|
| 92 | Res.Stat(ii).Sum(kk) = NaN; |
---|
| 93 | Res.Stat(ii).Max(kk) = NaN; |
---|
| 94 | Res.Stat(ii).Min(kk) = NaN; |
---|
| 95 | Res.Stat(ii).PixelCount(kk) = 0; |
---|
| 96 | else |
---|
| 97 | Res.Stat(ii).Mean(kk) = mean(data); |
---|
| 98 | Res.Stat(ii).Std(kk) = std(data); |
---|
| 99 | Res.Stat(ii).Sum(kk) = sum(data); |
---|
| 100 | Res.Stat(ii).Max(kk) = max(data); |
---|
| 101 | Res.Stat(ii).Min(kk) = min(data); |
---|
| 102 | Res.Stat(ii).PixelCount(kk) = length(data); |
---|
| 103 | end |
---|
| 104 | |
---|
| 105 | else % Statistics for normal type data |
---|
| 106 | |
---|
| 107 | %% Overall results for current ROI |
---|
| 108 | data=DATA{kk}.FTDATA(ROI(ii).voxels{kk}); |
---|
| 109 | data = double(data); |
---|
| 110 | Res.Stat(ii).isMixed = false; |
---|
| 111 | Res.Stat(ii).Label = ROI(ii).label; |
---|
| 112 | Res.Stat(ii).Mean = mean(data); |
---|
| 113 | Res.Stat(ii).Std = std(data); |
---|
| 114 | Res.Stat(ii).Sum = sum(data); |
---|
| 115 | Res.Stat(ii).Max = max(data); |
---|
| 116 | Res.Stat(ii).Min = min(data); |
---|
[77] | 117 | Res.Stat(ii).PixelCount = length(data); |
---|
| 118 | if isempty(data) |
---|
| 119 | Res.Stat(ii).Mean = NaN; |
---|
| 120 | Res.Stat(ii).Std = NaN; |
---|
| 121 | Res.Stat(ii).Sum = NaN; |
---|
| 122 | Res.Stat(ii).Max = NaN; |
---|
| 123 | Res.Stat(ii).Min = NaN; |
---|
| 124 | Res.Stat(ii).PixelCount = 0; |
---|
| 125 | end |
---|
| 126 | |
---|
[2] | 127 | %% Calculate results in X direction |
---|
| 128 | Res.Stat(ii).XD.Mean = []; |
---|
| 129 | Res.Stat(ii).XD.Std = []; |
---|
| 130 | Res.Stat(ii).XD.Sum = []; |
---|
| 131 | Res.Stat(ii).XD.Max = []; |
---|
| 132 | Res.Stat(ii).XD.Min = []; |
---|
| 133 | Res.Stat(ii).XD.PixelCount = []; |
---|
| 134 | |
---|
| 135 | for jj=1:size(ROI(ii).voxels{kk},3) |
---|
| 136 | roix=ROI(ii).voxels{kk}(:,:,jj,:); |
---|
| 137 | datax = DATA{kk}.FTDATA(:,:,jj,:); |
---|
| 138 | tmpx=datax(roix); |
---|
| 139 | tmpx = double(tmpx); |
---|
| 140 | if isempty(tmpx) |
---|
| 141 | Res.Stat(ii).XD.Mean(end+1) = NaN; |
---|
| 142 | Res.Stat(ii).XD.Std(end+1) = NaN; |
---|
| 143 | Res.Stat(ii).XD.Sum(end+1) = NaN; |
---|
| 144 | Res.Stat(ii).XD.Max(end+1) = NaN; |
---|
| 145 | Res.Stat(ii).XD.Min(end+1) = NaN; |
---|
| 146 | Res.Stat(ii).XD.PixelCount(end+1) = 0; |
---|
| 147 | else |
---|
| 148 | Res.Stat(ii).XD.Mean(end+1) = mean(tmpx); |
---|
| 149 | Res.Stat(ii).XD.Std(end+1) = std(tmpx); |
---|
| 150 | Res.Stat(ii).XD.Sum(end+1) = sum(tmpx); |
---|
| 151 | Res.Stat(ii).XD.Max(end+1) = max(tmpx); |
---|
| 152 | Res.Stat(ii).XD.Min(end+1) = min(tmpx); |
---|
| 153 | Res.Stat(ii).XD.PixelCount(end+1) = length(tmpx); |
---|
| 154 | end |
---|
| 155 | end |
---|
| 156 | |
---|
| 157 | %% Calculate results in Y direction |
---|
| 158 | Res.Stat(ii).YD.Mean = []; |
---|
| 159 | Res.Stat(ii).YD.Std = []; |
---|
| 160 | Res.Stat(ii).YD.Sum = []; |
---|
| 161 | Res.Stat(ii).YD.Max = []; |
---|
| 162 | Res.Stat(ii).YD.Min = []; |
---|
| 163 | Res.Stat(ii).YD.PixelCount = []; |
---|
| 164 | |
---|
| 165 | for jj=1:size(ROI(ii).voxels{kk},2) |
---|
| 166 | roiy=ROI(ii).voxels{kk}(:,jj,:,:); |
---|
| 167 | datay = DATA{kk}.FTDATA(:,jj,:,:); |
---|
| 168 | tmpy=datay(roiy); |
---|
| 169 | tmpy=double(tmpy); |
---|
| 170 | if isempty(tmpy) |
---|
| 171 | Res.Stat(ii).YD.Mean(end+1) = NaN; |
---|
| 172 | Res.Stat(ii).YD.Std(end+1) = NaN; |
---|
| 173 | Res.Stat(ii).YD.Sum(end+1) = NaN; |
---|
| 174 | Res.Stat(ii).YD.Max(end+1) = NaN; |
---|
| 175 | Res.Stat(ii).YD.Min(end+1) = NaN; |
---|
| 176 | Res.Stat(ii).YD.PixelCount(end+1) = 0; |
---|
| 177 | else |
---|
| 178 | Res.Stat(ii).YD.Mean(end+1) = mean(tmpy); |
---|
| 179 | Res.Stat(ii).YD.Std(end+1) = std(tmpy); |
---|
| 180 | Res.Stat(ii).YD.Sum(end+1) = sum(tmpy); |
---|
| 181 | Res.Stat(ii).YD.Max(end+1) = max(tmpy); |
---|
| 182 | Res.Stat(ii).YD.Min(end+1) = min(tmpy); |
---|
| 183 | Res.Stat(ii).YD.PixelCount(end+1) = length(tmpy); |
---|
| 184 | end |
---|
| 185 | end |
---|
| 186 | |
---|
| 187 | %% Calculate results in Z direction |
---|
| 188 | Res.Stat(ii).ZD.Mean = []; |
---|
| 189 | Res.Stat(ii).ZD.Std = []; |
---|
| 190 | Res.Stat(ii).ZD.Sum = []; |
---|
| 191 | Res.Stat(ii).ZD.Max = []; |
---|
| 192 | Res.Stat(ii).ZD.Min = []; |
---|
| 193 | Res.Stat(ii).ZD.PixelCount = []; |
---|
| 194 | |
---|
| 195 | for jj=1:size(ROI(ii).voxels{kk},1) |
---|
| 196 | roiz=ROI(ii).voxels{kk}(jj,:,:,:); |
---|
| 197 | dataz = DATA{kk}.FTDATA(jj,:,:,:); |
---|
| 198 | tmpz=dataz(roiz); |
---|
| 199 | tmpz=double(tmpz); |
---|
| 200 | if isempty(tmpz) |
---|
| 201 | Res.Stat(ii).ZD.Mean(end+1) = NaN; |
---|
| 202 | Res.Stat(ii).ZD.Std(end+1) = NaN; |
---|
| 203 | Res.Stat(ii).ZD.Sum(end+1) = NaN; |
---|
| 204 | Res.Stat(ii).ZD.Max(end+1) = NaN; |
---|
| 205 | Res.Stat(ii).ZD.Min(end+1) = NaN; |
---|
| 206 | Res.Stat(ii).ZD.PixelCount(end+1) = 0; |
---|
| 207 | else |
---|
| 208 | Res.Stat(ii).ZD.Mean(end+1) = mean(tmpz); |
---|
| 209 | Res.Stat(ii).ZD.Std(end+1) = std(tmpz); |
---|
| 210 | Res.Stat(ii).ZD.Sum(end+1) = sum(tmpz); |
---|
| 211 | Res.Stat(ii).ZD.Max(end+1) = max(tmpz); |
---|
| 212 | Res.Stat(ii).ZD.Min(end+1) = min(tmpz); |
---|
| 213 | Res.Stat(ii).ZD.PixelCount(end+1) = length(tmpz); |
---|
| 214 | end |
---|
| 215 | end |
---|
[77] | 216 | |
---|
| 217 | %% Calculate results in V direction |
---|
| 218 | Res.Stat(ii).VD.Mean = []; |
---|
| 219 | Res.Stat(ii).VD.Std = []; |
---|
| 220 | Res.Stat(ii).VD.Sum = []; |
---|
| 221 | Res.Stat(ii).VD.Max = []; |
---|
| 222 | Res.Stat(ii).VD.Min = []; |
---|
| 223 | Res.Stat(ii).VD.PixelCount = []; |
---|
| 224 | |
---|
| 225 | for jj=1:size(ROI(ii).voxels{kk},4) |
---|
| 226 | roiv=ROI(ii).voxels{kk}(:,:,:,jj); |
---|
| 227 | datav = DATA{kk}.FTDATA(:,:,:,jj); |
---|
| 228 | tmpv=datav(roiv); |
---|
| 229 | tmpv=double(tmpv); |
---|
| 230 | if isempty(tmpv) |
---|
| 231 | Res.Stat(ii).VD.Mean(end+1) = NaN; |
---|
| 232 | Res.Stat(ii).VD.Std(end+1) = NaN; |
---|
| 233 | Res.Stat(ii).VD.Sum(end+1) = NaN; |
---|
| 234 | Res.Stat(ii).VD.Max(end+1) = NaN; |
---|
| 235 | Res.Stat(ii).VD.Min(end+1) = NaN; |
---|
| 236 | Res.Stat(ii).VD.PixelCount(end+1) = 0; |
---|
| 237 | else |
---|
| 238 | Res.Stat(ii).VD.Mean(end+1) = mean(tmpv); |
---|
| 239 | Res.Stat(ii).VD.Std(end+1) = std(tmpv); |
---|
| 240 | Res.Stat(ii).VD.Sum(end+1) = sum(tmpv); |
---|
| 241 | Res.Stat(ii).VD.Max(end+1) = max(tmpv); |
---|
| 242 | Res.Stat(ii).VD.Min(end+1) = min(tmpv); |
---|
| 243 | Res.Stat(ii).VD.PixelCount(end+1) = length(tmpv); |
---|
| 244 | end |
---|
| 245 | end |
---|
[2] | 246 | end |
---|
| 247 | end |
---|
| 248 | end |
---|
| 249 | |
---|
| 250 | % - EOF - |
---|