📄 bfm_plot_brainlv_sa.m
字号:
function bfm_plot_brainlv_sa(ViewBootstrapRatio, PLSresultFile, ...
grp_idx, lv_idx, new_fig, behav_idx, sa, cluster_info, update)
if (new_fig)
bg_img = getappdata(gcbf,'BackgroundImg');
rot_amount = getappdata(gcbf,'RotateAmount');
if (ViewBootstrapRatio)
blv = getappdata(gcbf,'BSRatio');
else
blv = getappdata(gcbf,'BLVData');
end
else
bg_img = getappdata(gcf,'BackgroundImg');
rot_amount = getappdata(gcf,'RotateAmount');
if (ViewBootstrapRatio)
blv = getappdata(gcf,'BSRatio');
else
blv = getappdata(gcf,'BLVData');
end
end
if ~isempty(behav_idx) % called from datamatcorrs plot
blv = blv{grp_idx, behav_idx};
end
if isempty(bg_img)
no_background_image = 1;
else
no_background_image = 0;
end
if ~isempty(behav_idx) % called from datamatcorrs plot
load(PLSresultFile,'num_conditions','st_dims','st_coords','s','st_voxel_size','st_origin','behavname');
num_behav = length(behavname);
else
load(PLSresultFile,'num_conditions','st_dims','st_coords','s','st_voxel_size','st_origin');
end
% match variable name among PET, BfMRI & fMRI
%
dims = st_dims;
newcoords = st_coords;
voxel_size = st_voxel_size;
origin = st_origin;
if sa
dims_sa = dims([2,4,3,1]);
voxel_size = voxel_size([2,3,1]);
origin = origin([2,3,1]);
else
dims_sa = dims([1,4,3,2]);
voxel_size = voxel_size([1,3,2]);
origin = origin([1,3,2]);
end
% slice_idx = [2:5:65];
slice_idx = [1:dims_sa(4)];
num_slices = length(slice_idx);
slices = dims_sa(4);
if grp_idx
num_lv = num_conditions;
else
num_lv = size(blv,2);
end
brainlv = blv(:,lv_idx);
if (ViewBootstrapRatio)
h = findobj(gcf,'Tag','BSThreshold'); thresh = str2num(get(h,'String'));
h = findobj(gcf,'Tag','MaxRatio'); max_blv = str2num(get(h,'String'));
h = findobj(gcf,'Tag','MinRatio'); min_blv = str2num(get(h,'String'));
else
h = findobj(gcf,'Tag','Threshold'); thresh = str2num(get(h,'String'));
h = findobj(gcf,'Tag','MaxValue'); max_blv = str2num(get(h,'String'));
h = findobj(gcf,'Tag','MinValue'); min_blv = str2num(get(h,'String'));
end
too_large = find(brainlv > max_blv); brainlv(too_large) = max_blv;
too_small = find(brainlv < min_blv); brainlv(too_small) = min_blv;
if mod(rot_amount,2)
img_height = dims_sa(2); % rows - after 90 or 270 rotation
img_width = dims_sa(1); % by default, 90 rotation
else
img_height = dims_sa(1); % rows
img_width = dims_sa(2);
end
% display the images
%
if (new_fig)
[axes_hdl,colorbar_hdl] = bfm_create_newblv_ui;
else
axes_hdl = getappdata(gcf,'BlvAxes');
colorbar_hdl = getappdata(gcf,'Colorbar');
end
axes(axes_hdl);
rows = dims_sa(1);
cols = dims_sa(2);
slices = dims_sa(4);
% create the appropriate colormap
%
% cmap = set_colormap(max_blv, min_blv, thresh);
bg_values = [1 1 1];
num_blv_colors = 25;
brain_region_color_idx = 51;
first_lower_color_idx = 101;
first_upper_color_idx = 126;
% set up the colormap for the background
%
bg_brain_values = [0.54 0.54 0.54];
if (no_background_image),
bg_cmap = ones(100,1)*bg_brain_values; % the brain regions
else
bg_cmap = bone(140);
bg_cmap = bg_cmap(1:100,:);
end;
% colormap entries
% 1 - 100 : for the brain regions (background) image
% 101 - 125 : for the negative blv values below threshold
% 126 - 150 : for the positive blv values above threshold
% 151 : for the non-brain regions
cmap = zeros(151,3);
jetmap = jet(64);
cmap(1:100,:) = bg_cmap; % the brain regions
cmap(101:125,:) = jetmap([1:25],:); % the negative blv values
cmap(126:150,:) = jetmap([36:60],:); % the positive blv values
cmap(end,:) = bg_values; % the nonbrain regions
% set up the colormap for the display colorbar
%
cbar_size = 100;
cbar_map = ones(cbar_size,1) * bg_brain_values;
cbar_step = (max_blv - min_blv) / cbar_size;
% prevent_num_lower_color_0
%
if (abs(min_blv) - thresh) < cbar_step & (abs(min_blv) - thresh) ~= 0
cbar_size = ceil((max_blv - min_blv) / (abs(min_blv) - thresh));
cbar_map = ones(cbar_size,1) * bg_brain_values;
cbar_step = (max_blv - min_blv) / cbar_size;
end
if (abs(max_blv) - thresh) < cbar_step & (abs(max_blv) - thresh) ~= 0
cbar_size = ceil((max_blv - min_blv) / (abs(max_blv) - thresh));
cbar_map = ones(cbar_size,1) * bg_brain_values;
cbar_step = (max_blv - min_blv) / cbar_size;
end
if cbar_step ~= 0
% num_lower_color = round((abs(min_blv) - thresh) / cbar_step);
if max_blv > -abs(thresh)
num_lower_color = round((abs(min_blv) - thresh) / cbar_step);
else
num_lower_color = round((abs(min_blv) - abs(max_blv)) / cbar_step);
end
if round(64 / 25 * num_lower_color) > 0
jetmap = jet(round(64 / 25 * num_lower_color));
cbar_map(1:num_lower_color,:) = jetmap(1:num_lower_color,:);
end
% num_upper_color = round((max_blv - thresh) / cbar_step);
if min_blv < abs(thresh)
num_upper_color = round((max_blv - thresh) / cbar_step);
else
num_upper_color = round((max_blv - min_blv) / cbar_step);
end
if round(64 / 25 * num_upper_color) > 0
jetmap = jet(round(64 / 25 * num_upper_color));
first_jet_color = round((36 / 64) * size(jetmap,1));
jet_range = [first_jet_color:first_jet_color+num_upper_color-1];
cbar_map(end-num_upper_color+1:end,:) = jetmap(jet_range,:);
end
% Create the image slices in which voxels are set to be within certain range
%
% lower_interval = (abs(min_blv) - thresh) / (num_blv_colors-1);
% upper_interval = (max_blv - thresh) / (num_blv_colors-1);
if max_blv > -abs(thresh)
lower_interval = (abs(min_blv) - thresh) / (num_blv_colors-1);
else
lower_interval = (abs(min_blv) - abs(max_blv)) / (num_blv_colors-1);
end
if min_blv < abs(thresh)
upper_interval = (max_blv - thresh) / (num_blv_colors-1);
else
upper_interval = (max_blv - min_blv) / (num_blv_colors-1);
end
disp_blv = zeros(1,length(newcoords)) + brain_region_color_idx;
lower_idx = find(brainlv <= -thresh);
blv_offset = brainlv(lower_idx) - min_blv;
if lower_interval ~=0
lower_color_idx = round(blv_offset/lower_interval)+first_lower_color_idx;
else
lower_color_idx = ones(size(blv_offset)) * first_lower_color_idx;
end
disp_blv(lower_idx) = lower_color_idx;
upper_idx = find(brainlv >= thresh);
blv_offset = max_blv - brainlv(upper_idx);
if upper_interval ~=0
upper_color_idx = num_blv_colors - round(blv_offset/upper_interval);
else
upper_color_idx = num_blv_colors * ones(size(blv_offset));
end
upper_color_idx = upper_color_idx + first_upper_color_idx - 1;
disp_blv(upper_idx) = upper_color_idx;
else
disp_blv = zeros(1,length(newcoords)) + brain_region_color_idx;
if abs(min_blv) < 1e-6
max_blv = min_blv + eps;
else
max_blv = min_blv + abs(min_blv)*1e-9;
end
end
% get non_cluster_coords
%
if isempty(cluster_info)
cluster_idx = newcoords;
else
cluster_idx = cluster_info.data{1}.idx;
end
if isequal(newcoords, cluster_idx)
non_cluster_coords = [];
else
[tmp cluster_coords] = intersect(newcoords,cluster_idx);
non_cluster_coords = ones(1,length(newcoords));
non_cluster_coords(cluster_coords) = 0;
non_cluster_coords = find(non_cluster_coords);
end
if (no_background_image),
non_brain_region_color_idx = size(cmap,1);
img = zeros(1,rows*cols*slices) + non_brain_region_color_idx;
disp_blv(non_cluster_coords) = brain_region_color_idx;
img(newcoords) = disp_blv;
img = reshape(img,[dims(1) dims(2) 1 dims(4)]);
else
max_bg = max(bg_img(:));
min_bg = min(bg_img(:));
img = (bg_img - min_bg) / (max_bg - min_bg) * 100;
disp_blv(non_cluster_coords) = img(newcoords(non_cluster_coords));
if exist('lower_idx','var') & ~isempty(lower_idx)
img(newcoords(lower_idx)) = disp_blv(lower_idx);
end
if exist('upper_idx','var') & ~isempty(upper_idx)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -