📄 pet_create_datamat_ui.m
字号:
'String','Check image orientation', ...
'Callback','pet_create_datamat_ui(''ORIENT'');',...
'Tag','ORIENTButton');
% x = 0.25;
x = 0.5;
y = 0.1;
% w = 0.15;
w = 0.2;
h = 0.07;
pos = [x y w h];
c = uicontrol('Parent',h0, ... % RUN Button
'Style','pushbutton', ...
'Units','normal', ...
'fontunit','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','center', ...
'Position',pos, ...
'String','Create', ...
'Callback','pet_create_datamat_ui(''RUN_BUTTON'');',...
'Tag','RUNButton');
% x = 1-x-w;
x = x + w + 0.05;
pos = [x y w h];
c = uicontrol('Parent',h0, ... % CANCEL Button
'Style','pushbutton', ...
'Units','normal', ...
'fontunit','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','center', ...
'Position',pos, ...
'String','Cancel', ...
'Callback','pet_create_datamat_ui(''CANCEL_BUTTON'');',...
'Tag','CANCELButton');
x = 0.01;
y = 0;
w = 1;
h = 0.04;
pos = [x y w h];
c = uicontrol('Parent',h0, ... % Message Line
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'ForegroundColor',[0.8 0.0 0.0], ...
'fontunit','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'Position',pos, ...
'String','', ...
'Tag','MessageLine');
setappdata(h0,'SessionFile',session_file);
setappdata(h0, 'session_win_hdl',session_win_hdl);
setappdata(h0,'BrainRegionFile',[]);
setappdata(h0,'Threshold',0.25);
setappdata(h0, 'merged_conds', []);
return; % init
%----------------------------------------------------------------------------
function SelectPredefineBrainRegion()
if get(findobj(gcf,'Tag','PredefineRegionChkButton'),'Value') == 0 % click itself
set(findobj(gcf,'Tag','PredefineRegionChkButton'),'Value',1);
else
set(findobj(gcbf,'Tag','AutoRegionChkButton'),'Value',0);
set(findobj(gcbf,'Tag','AutoRegionThresholdLabel'), ...
'Foreground',[0.5 0.5 0.5]);
set(findobj(gcbf,'Tag','AutoRegionThresholdEdit'),'Enable','off');
set(findobj(gcf,'Tag','ConsiderAllVoxels'),'Value', 0);
set(findobj(gcbf,'Tag','ConsiderAllVoxels'),'Enable','off');
set(findobj(gcbf,'Tag','PredefineRegionFileLabel'),'Foreground',[0 0 0]);
set(findobj(gcbf,'Tag','PredefineRegionFileEdit'),'Enable','on');
set(findobj(gcbf,'Tag','PredefineRegionFileButton'),'Enable','on');
end
return; % SelectPredefineBrainRegion
%----------------------------------------------------------------------------
function SelectAutoBrainRegion()
if get(findobj(gcf,'Tag','AutoRegionChkButton'),'Value') == 0 % click itself
set(findobj(gcf,'Tag','AutoRegionChkButton'),'Value',1);
else
set(findobj(gcbf,'Tag','PredefineRegionChkButton'),'Value',0);
set(findobj(gcbf,'Tag','PredefineRegionFileLabel'), ...
'Foreground',[0.5 0.5 0.5]);
set(findobj(gcbf,'Tag','PredefineRegionFileEdit'),'Enable','off');
set(findobj(gcbf,'Tag','PredefineRegionFileButton'),'Enable','off');
set(findobj(gcbf,'Tag','AutoRegionThresholdLabel'),'Foreground',[0 0 0]);
set(findobj(gcbf,'Tag','AutoRegionThresholdEdit'),'Enable','on');
set(findobj(gcbf,'Tag','ConsiderAllVoxels'),'Enable','on');
end
return; % SelectAutoBrainRegion
%----------------------------------------------------------------------------
function SelectConsiderAllVoxels
if get(findobj(gcbf,'Tag','ConsiderAllVoxels'),'Value') == 0
set(findobj(gcbf,'Tag','AutoRegionThresholdEdit'),'Enable','on');
set(findobj(gcbf,'Tag','AutoRegionThresholdEdit'),'String','0.25');
setappdata(gcbf,'Threshold',0.25);
else
set(findobj(gcbf,'Tag','AutoRegionThresholdEdit'),'Enable','off');
set(findobj(gcbf,'Tag','AutoRegionThresholdEdit'),'String','0');
setappdata(gcbf,'Threshold',0);
end
return; % SelectConsiderAllVoxels
%----------------------------------------------------------------------------
function EditBrainRegionFile()
fname = get(gcbo,'String');
fname = deblank(fliplr(deblank(fliplr(fname))));
if isempty(fname)
setappdata(gcf,'BrainRegionFile',[]);
return;
end;
pathfile = fullfile(pwd, fname);
if (exist(pathfile,'file') ~= 2)
pathfile = fname;
if (exist(pathfile,'file') ~= 2)
msg = 'ERROR: Invalid file specified.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
setappdata(gcf,'BrainRegionFile',[]);
return;
end
end;
% make sure the IMG file can be accessed.
%
try
dummy = rri_imginfo(pathfile);
catch
msg = 'ERROR: Cannot open the file. Make sure it is an IMG file.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
set(gcbo,'String',pathfile);
setappdata(gcf,'BrainRegionFile',pathfile);
return; % EditBrainRegionFile
%----------------------------------------------------------------------------
function SelectBrainRegionFile()
[fname, fpath] = uigetfile('*.img','Brain Region Mask');
if isequal(fname,0), % no file has been selected
return;
end;
if ~isequal(fpath,filesep) & ~isequal(fpath,0)
fname = fullfile(fpath,fname);
end;
% make sure the IMG file can be accessed.
%
try
dummy = rri_imginfo(fname);
catch
msg = 'ERROR: Cannot open the file. Make sure it is an IMG file.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
set(findobj(gcbf,'Tag','PredefineRegionFileEdit'),'String',fname);
setappdata(gcf,'BrainRegionFile',fname);
return; % SelectBrainRegionFile
%----------------------------------------------------------------------------
function SetThreshold()
try
threshold = str2num(get(gcbo,'String'));
if (threshold < 0) | (threshold > 1)
msg = 'ERROR: Threshold must be between 0 and 1.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
setappdata(gcf,'Threshold',[]);
return;
end;
setappdata(gcf,'Threshold',threshold);
catch
msg = 'ERROR: Invalid threshold value.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
setappdata(gcf,'Threshold',[]);
return;
end;
return; % SetThreshold
%----------------------------------------------------------------------------
function nonbrain_coords = find_nonbrain_coords(dataset,coord_thresh,considerall)
[num_scans num_voxels] = size(dataset);
nonbrain_coords = zeros(1,num_voxels);
for i=1:num_scans,
scan_threshold = double(max(dataset(i,:))) * coord_thresh;
if considerall
idx = find(dataset(i,:) < scan_threshold);
else
idx = find(dataset(i,:) <= scan_threshold);
end
nonbrain_coords(idx) = 1;
end
return;
%----------------------------------------------------------------------------
function delete_fig
try
load('pls_profile');
pls_profile = which('pls_profile.mat');
pet_create_datamat_pos = get(gcbf,'position');
save(pls_profile, '-append', 'pet_create_datamat_pos');
catch
end
return; % delete_fig
%----------------------------------------------------------------------------
function status = SaveDatamatOptions()
status = 0; % set status to fail first
STOptions.session_win_hdl = getappdata(gcf,'session_win_hdl');
% For brain region
%
if (get(findobj(gcbf,'Tag','PredefineRegionChkButton'),'Value') == 1)
STOptions.UseBrainRegionFile = 1;
STOptions.BrainRegionFile = getappdata(gcf,'BrainRegionFile');
if isempty(STOptions.BrainRegionFile),
msg = 'ERROR: Invalid file for the brain region mask.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
STOptions.Threshold = [];
STOptions.ConsiderAllVoxels = 0;
else
STOptions.UseBrainRegionFile = 0;
STOptions.BrainRegionFile = [];
STOptions.Threshold = getappdata(gcf,'Threshold');
if isempty(STOptions.Threshold)
msg = 'ERROR: Invalid threshold value.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end;
STOptions.ConsiderAllVoxels = ...
get(findobj(gcbf,'Tag','ConsiderAllVoxels'),'value');
end;
h = findobj(gcbf,'Tag','MeanRatioChkButton');
STOptions.NormalizeVolumeMean = get(h,'Value');
status = 1;
setappdata(gcf,'STOptions',STOptions);
return; % SaveDatamatOptions
%----------------------------------------------------------------------------
function CreateDatamat()
if exist('plslog.m','file')
plslog('Create PET Datamat');
end
tic;
options = getappdata(gcf,'STOptions');
merged_conds = getappdata(gcf, 'merged_conds');
session_file = getappdata(gcf,'SessionFile');
load(session_file);
if isfield(session_info, 'behavdata')
behavdata = session_info.behavdata;
else
behavdata = [];
end
if isfield(session_info, 'behavname')
behavname = session_info.behavname;
else
behavname = {};
end
pls_data_path = session_info.pls_data_path;
num_behavior = session_info.num_behavior;
datamat_prefix = session_info.datamat_prefix;
num_conditions = session_info.num_conditions;
condition = session_info.condition;
num_subjects = session_info.num_subjects;
subject = session_info.subject;
subj_name = session_info.subj_name;
subj_files = session_info.subj_files;
k = num_conditions;
n = num_subjects;
filename = [datamat_prefix, '_PETdatamat.mat'];
use_brain_mask = options.UseBrainRegionFile;
brain_mask_file = options.BrainRegionFile;
brain_mask = [];
mask_dims = [];
if use_brain_mask
brain_mask = load_nii(brain_mask_file, 1);
brain_mask = reshape(int8(brain_mask.img), [brain_mask.hdr.dime.dim(2:3) 1 brain_mask.hdr.dime.dim(4)]);
mask_dims = size(brain_mask);
create_datamat_info.brain_mask_file = brain_mask_file;
create_datamat_info.brain_coord_thresh = [];
else
create_datamat_info.brain_mask_file = '';
create_datamat_info.brain_coord_thresh = options.Threshold;
end
coord_thresh = options.Threshold;
normalize_volume_mean = options.NormalizeVolumeMean;
create_datamat_info.normalize_volume_mean = normalize_volume_mean;
create_datamat_info.consider_all_voxels_as_brain = options.ConsiderAllVoxels;
curr = pwd;
if isempty(curr)
curr = filesep;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -