source: plugins/calculate_snr.m @ 77

Last change on this file since 77 was 77, checked in by tjniskan, 10 years ago
  • Fixed a strange bug related to resizing Aedes window in Matlab

R2008a (and possibly R2008b and R2009a).

  • Fixed bugs of Voxel TimeSeries? and Overlay Control figure

handles not being properly destroyed on exit.

  • Changed default values for reading VNMR files (now Fast Read is on

by default, output precision is single and data is oriented using
PROCPAR.orient)

  • Fixed a bug in the calculate SNR -plugin
  • Made a temporary workaround for controlling the output in the "View

ROI statistics" -table. A proper GUI implementation will (hopefully) follow
shortly. The output can be controlled by using Aedes preferences. For
example setpref('Aedes','StatPrintDirs?','TXYZV') will print in the
output Total, X-dir, Y-dir, Z-dir and V-dir statistics.

M an2_revision.m
M an2_data_read.m
M an2_resviewer.m
M aedes.m
M an2_res2table.m
M plugins/calculate_snr.m
M an2_readfid.m
M an2_readfidprefs.m
M an2_roi_stats.m

File size: 4.0 KB
Line 
1function calculate_snr(DATA,ROI,AddInfo)
2% calculate_snr - Calculate Signal-to-noise ratio (SNR) from two ROIs
3%   (this is an Aedes plugin)
4%
5% This plugin looks for two ROIs labeled "signal" and "noise", which it
6% will then use to calculate SNR. SNR value is printed in the workspace and
7% show in a messagebox.
8
9% This function is a part of Aedes - A graphical tool for analyzing
10% medical images
11%
12% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
13%
14% Department of Physics, Department of Neurobiology
15% University of Kuopio, FINLAND
16%
17% This program may be used under the terms of the GNU General Public
18% License version 2.0 as published by the Free Software Foundation
19% and appearing in the file LICENSE.TXT included in the packaging of
20% this program.
21%
22% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
23% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24
25
26% -------------------------------------------------------------------------
27% First check if two ROIs labeled "signal" and "noise" are defined. If not,
28% display an error and return.
29% -------------------------------------------------------------------------
30
31% Check if ROI-structure is empty, i.e. no ROIs have been defined. Display
32% an error ROIs have not been defined.
33if isempty(ROI)
34  errordlg(['No ROIs defined. Please draw ROIs for "signal" and "noise" ',...
35    'and label them correspondingly.'],'SNR Plugin Error');
36  return
37end
38
39% Check that there are at least two ROIs defined with the labels "signal"
40% and "noise"
41if length(ROI)<2
42    errordlg(['Too few ROIs found. Please draw ROIs for "signal" and "noise" ',...
43    'and label them correspondingly.'],'SNR Plugin Error');
44  return
45end
46
47% Get indices for "signal" and "noise" ROIs
48SignalRoiInd = find(strcmpi('signal',{ROI(:).label}));
49NoiseRoiInd = find(strcmpi('noise',{ROI(:).label}));
50
51% If either signal or noise ROI is not found, display an error and return
52if isempty(SignalRoiInd) || isempty(NoiseRoiInd)
53  errordlg(['Please draw ROIs for "signal" and "noise" ',...
54    'and label them correspondingly.'],'SNR Plugin Error');
55  return
56end
57
58% Display general info
59fprintf(1,'\n') % empty line
60disp('==========================')
61disp('= Signal-to-noise ratios =')
62disp('==========================')
63
64% We almost always have to handle stacked and non-stacked data differently.
65% Stacked or mixed data means that multiple slices have been opened in
66% Aedes using the "Open multiple files" dialog. Non-stacked or non-mixed
67% data set is e.g. a regular fid-file, which contains one or more slices.
68if AddInfo.isDataMixed
69  fprintf(1,'------------------------------\n')
70  fprintf(1,'Slice nbr\tSNR\tFile Name\n')
71  fprintf(1,'------------------------------\n')
72 
73  % Calculate SNR for every slice
74  snr = zeros(length(DATA),1);
75  for ii=1:length(DATA)
76    signal = DATA{ii}.FTDATA(ROI(SignalRoiInd).voxels{ii});
77    noise = DATA{ii}.FTDATA(ROI(NoiseRoiInd).voxels{ii});
78    if isempty(signal) || isempty(noise)
79      snr(ii) = NaN;
80    else
81      mean_signal = mean(signal);
82      mean_noise = mean(noise);
83      snr(ii) = mean_signal/mean_noise;
84    end
85    fprintf(1,'Slice %d:\t%f\t%s%s\n',ii,snr(ii),...
86      DATA{ii}.HDR.fpath,DATA{ii}.HDR.fname)
87  end
88else
89  % Calculate SNR for every slice in the slice (X) direction. If there are
90  % more than one volumes, use the current volume.
91  fprintf(1,'Filename:\n%s%s\n',DATA{1}.HDR.fpath,DATA{1}.HDR.fname)
92  fprintf(1,'------------------------------\n')
93  fprintf(1,'Slice nbr\tSNR\n')
94  fprintf(1,'------------------------------\n')
95 
96  snr = zeros(size(DATA{1}.FTDATA,3),1);
97  for ii=1:size(DATA{1}.FTDATA,3)
98    vol=AddInfo.CurrentVol;
99    data = DATA{1}.FTDATA(:,:,ii,vol);
100    signal=data(ROI(SignalRoiInd).voxels{1}(:,:,ii,vol));
101    noise=data(ROI(NoiseRoiInd).voxels{1}(:,:,ii,vol));
102    if isempty(signal) || isempty(noise)
103      snr(ii) = NaN;
104    else
105      mean_signal = mean(signal);
106      mean_noise = mean(noise);
107      snr(ii) = mean_signal/mean_noise;
108    end
109    fprintf(1,'Slice %d:\t%f\n',ii,snr(ii))
110  end
111end
112
113
114
Note: See TracBrowser for help on using the repository browser.

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