function [xpts, ypts, zpts, img_fh, plt_fh] = get_voxel_2dspectrum3d_compare( xf2f1_data, f2vals, f1vals, options )
%GET_VOXEL_SPECTRUM Point and click display of MRSI data
%
% Displays spatial signal energy distribution of the data
% and prompts the user to select points. The spectrum of each voxel is
% plotted as it is selected.
%
% Author: Bryan Clifford
% Created: 2015-02-13
%
% INPUTS:
% ---- Required ----
% xf_data spatial-spectral distribution
%
% ---- Optional ----
% xvals spectral axis values (default [1:size(xf_data,4)])
%
% options.selectPts set to true (default) to prompt user to select
% spatial locations of spectra.
% options.xpts,ypts,zpts if options.selectPts=false these parameters are
% required and are the locations of the selected
% spectra.
% options.dispImg set to true (default) to display the absolute peak
% integral distribution
% options.axlabel label of spectral axis (default: 'Chemical Shift')
% options.imgLims range [min max] of spectral values used for image
% energy (defaults to minimum and maximum of 'xvals')
% options.plttype type of spectrum plot ('abs', 'real', 'imag')
% default value is 'abs'
% options.imgtype type of image ('l1','l2')
% default value is 'l1'
% options.negxaxis (defaults to false) show the negative XTick values
% options.markerSize size of spectrum location marker (defaults to 5pts)
% options.dont_hold set to false (true) to show previous selected spectra
% options.numCont number of contour lines (default 20)
%
% OUTPUTS:
% xpts, ypts, zpts spatial locations of selected spectra
% img/plt_fh figure handles to the distribution and spectrum plots
%
% Created by Bryan A. Clifford, 2015
% Chao Ma: 06/26/2015, add ratio to options:caxis([0 max(img(:))/ratio]);
% Bryan Clifford: 1/15/2016, display axis square instead of image
% Bryan Clifford: 3/2/2016, make default of negxaxis false and default
% colormap gray.
% Yibo Zhao: 09/03/2018, add try... catch... end, to avoid error messages
% when closing the figure directly.
% add options.dont_hold(default false); if true,
% only the newest spetrum will be shown.
% Yudu Li: 09/15/2018, add option.xReverse (default is false). If set
% to true, the displayed spectrum is reversed along x-dir.
% Yibo Zhao: 09/20/2018, make the second input argument (xvals) optional;
% its default value is [1:size(xf_data,4)].
%--------------------------------------------------------------------------
% ---- Parse User Input ----
assert(ndims(xf2f1_data)==5,'Input data should be 5D.')
if ~exist('f2vals','var')||isempty(f2vals)
f2vals = 1:size(xf2f1_data,4);
end
if ~exist('f1vals','var')||isempty(f1vals)
f1vals = 1:size(xf2f1_data,5);
end
if (nargin==4)
if isfield(options,'selectPts')
selectPts = options.selectPts;
if ~selectPts
if (isfield(options,'xpts') && isfield(options, 'ypts') && isfield(options, 'zpts'))
xpts = options.xpts;
ypts = options.ypts;
zpts = options.zpts;
else
xpts = [];
ypts = [];
zpts = [];
end
end
else
selectPts = true;
end
if isfield(options,'dispImg')
dispImg = options.dispImg;
else
dispImg = true;
end
if isfield(options,'axlabel')
axlabel = options.axlabel;
else
axlabel = 'Chemical Shift';
end
if isfield(options,'ratio')
ratio = options.ratio;
else
ratio = 1;
end
if isfield(options,'imgLims')
imgLims = options.imgLims;
if any([1 2] ~= size(imgLims))
disp('ERROR: size of imgLims should be [1 2]')
return
end
if (imgLims(2) < imgLims(1))
disp('ERROR: imgLims(2) must be greater than or equal to imgLims(1)');
return
end
else
imgLims = [min(f2vals), max(f2vals)];
end
if isfield(options,'plttype')
plttype = options.plttype;
if ~(strcmp(plttype,'abs') || strcmp(plttype,'real') || strcmp(plttype,'imag'))
disp('Plot type options are: ''abs'' (default), ''real'', ''imag'', ''realimag''');
disp('Plotting absolute value of spectra');
plttype = 'abs';
end
else
plttype = 'abs';
end
if isfield(options,'imgtype')
imgtype = options.imgtype;
if ~(strcmp(imgtype,'l1') || strcmp(imgtype,'l2'))
disp('Image type options are: ''l1'' (default), ''l2''');
disp('Displaying L1 integral distribution');
imgtype = 'l1';
end
else
imgtype = 'l1';
end
if isfield(options,'negxaxis')
negxaxis = options.negxaxis;
else
negxaxis = false;
end
if isfield(options,'markerSize')
markerSize = options.markerSize;
else
markerSize = 5;
end
if isfield(options,'dont_hold')
dont_hold = options.dont_hold;
else
dont_hold = true;
end
if isfield(options,'xReverse')
xReverse = options.xReverse;
else
xReverse = false;
end
if isfield(options,'numCont')
numCont = options.numCont;
else
numCont = 20;
end
else % Use defaults
selectPts = true;
dispImg = true;
axlabel = 'Chemical Shift';
imgLims = [min(f2vals), max(f2vals)];
plttype = 'abs';
imgtype = 'l1';
negxaxis = false;
ratio = 1;
markerSize = 5;
dont_hold = true;
xReverse = false;
numCont = 20;
end
xmax = imgLims(2);
xmin = imgLims(1);
% --------
% Create Spectrum Plot
if selectPts || ~isempty(xpts)
plt_fh = figure();
title('\bfVoxel Spectra');
xlabel(axlabel);
xlim([min(f2vals) max(f2vals)])
ylabel('J');
plt_ax = gca;
legend_str = {};
if ~dont_hold
hold(plt_ax,'all');
end
if negxaxis
set(plt_ax,'XDir','Reverse');
end
else
plt_fh = -1;
end
% Create image
locs = find(f2vals>=xmin & f2vals<=xmax);
if strcmp(imgtype,'l1')
if exist('options','var') && isfield(options,'ref')
img = abs(options.ref);
title_pref = '\bfWater reference image\rm';
else
img = sum(abs(xf2f1_data(:,:,:,locs,1)),4);
title_pref = '\bfMagnitude Peak Integral Distribution\rm';
end
elseif strcmp(imgtype,'l2')
if exist('options','var') && isfield(options,'ref')
img = abs(options.ref);
title_pref = '\bfWater reference image\rm';
else
img = sqrt(sum(abs(xf2f1_data(:,:,:,locs,1)).^2,4));
title_pref = '\bfSpectral L2 Distribution\rm';
end
end
[Ny, Nx, Nz] = size(img);
% Display peak image and let user select reference points
if selectPts || dispImg
评论0