📄 pet_plot_brainlv_3v.m
字号:
%% h_img = image(blv_disp,'CDataMapping','scaled');
% h_img = image(blv_disp);
if update
h_img = findobj(gcf,'tag','BLVImg');
set(h_img,'CData',blv_disp);
else
h_img = image(blv_disp);
end
set(h_img,'Tag','BLVImg');
colormap(cmap);
num_plus = repmat({'+ '},1,rows_disp);
for i = 0:rows_disp-1
num_plus{i+1} = [num2str(i*cols_disp) num_plus{i+1}];
end
set(gca,'tickdir','out','ticklength',[0.001 0.001]);
set(gca,'xtick',[img_width/2:img_width:img_width*cols_disp]);
set(gca,'xticklabel',[1:cols_disp]);
set(gca,'ytick',[img_height/2:img_height:img_height*rows_disp]);
set(gca,'yticklabel',num_plus);
if (new_fig)
create_colorbar(colorbar_hdl, cbar_map, min_blv, max_blv);
return;
end
end
if (0) % if 0, newcolor: above block were vintage approach
blv = brainlv';
blv = unmapblv(blv,newcoords,prod(dims)); % make no_data voxel 0
% reshape blv to make each slice 1 column for 26 columns
%
blv = reshape(blv, img_height*img_width, num_slices);
% Overlay matrix 'blv' onto MRI template
%
template_file = getappdata(gcf,'template_file');
if isempty(template_file)
if no_background_image
if isequal(dims, [65,87,1,26])
template_file = 'pet_template';
load(template_file);
else
pet_template = zeros(dims);
pet_template(newcoords) = 150;
pet_template = reshape(pet_template, ...
[dims(1)*dims(2),dims(4)]);
end
else
bg_img = reshape(bg_img, [dims(1)*dims(2),dims(4)]);
pet_template = bg_img;
end
else
load(template_file);
end;
% Apply pet_template (where: max=203, min=9)
% so, the extreme range of temp could be: [-91, 458]
%
temp = pet_template + (blv>thresh)*255 + (blv<(thresh*(-1)))*(-100);
% rotate image
%
for i=1:num_slices
tmp=reshape(temp(:,i),img_width,img_height);
tmp=rot90(tmp,mod(rot_amount,4));
blv(:,i)=tmp(:);
end
% save a cornor of the last slice as the background intensity
%
bg_intensity = blv(1, num_slices);
% calculate how many slices to display for each row and column
% it's an algorithm from montage which will layout the slice
% in near square
%
if dims(1) > dims(2)
siz = [dims(1), dims(2), dims(4)];
else
siz = [dims(2), dims(1), dims(4)];
end
cols_disp = sqrt(prod(siz))/siz(2);
rows_disp = siz(3)/cols_disp;
if (ceil(cols_disp)-cols_disp) < (ceil(rows_disp)-rows_disp),
cols_disp = ceil(cols_disp); rows_disp = ceil(siz(3)/cols_disp);
else
rows_disp = ceil(rows_disp); cols_disp = ceil(siz(3)/rows_disp);
end
max_slice = rows_disp * cols_disp;
rest_slices = max_slice - num_slices;
empty_slices = -1 * ones(1,rest_slices);
slice_idx = [slice_idx, empty_slices];
% for empty slice (27-30), filled them with background intensity
%
blv_filled = [blv, ...
bg_intensity * ...
ones(img_height*img_width,rows_disp*cols_disp-num_slices)];
blv_disp = [];
for(row = 0:rows_disp-1)
% take 'cols_disp' amount of slices from blv_filled
% and put into blv_row
%
blv_row = blv_filled(:,[row*cols_disp+1:row*cols_disp+cols_disp]);
% reshape the slice to integrate the whole row together
%
blv_row = reshape(blv_row, [img_height, img_width*cols_disp]);
blv_disp = [blv_disp; blv_row];
end
blv_disp = reshape(blv_disp, [rows_disp*img_height, cols_disp*img_width]);
h_img = image(blv_disp,'CDataMapping','scaled');
set(h_img,'Tag','BLVImg');
colormap(map);
num_plus = repmat({'+ '},1,rows_disp);
for i = 0:rows_disp-1
num_plus{i+1} = [num2str(i*cols_disp) num_plus{i+1}];
end
set(gca,'tickdir','out','ticklength',[0.001 0.001]);
set(gca,'xtick',[img_width/2:img_width:img_width*cols_disp]);
set(gca,'xticklabel',[1:cols_disp]);
set(gca,'ytick',[img_height/2:img_height:img_height*rows_disp]);
set(gca,'yticklabel',num_plus);
if (new_fig)
% create_colorbar(colorbar_hdl, map, min_blv, max_blv);
return;
end
end % if 0, newcolor: above block were vintage approach
if 0
if grp_idx % called from datamatcorrs plot
set(h_img,'ButtonDownFcn','pet_plot_datamatcorrs(''SelectPixel'')');
else
set(h_img,'ButtonDownFcn','pet_result_3v_ui(''SelectPixel'')');
end
end
origin1 = getappdata(gcf,'Origin');
if ~isempty(origin1)
origin = origin1;
end
nii = make_nii(squeeze(img), voxel_size, origin);
gui3view.figure = gcf;
gui3view.area = [0.32 0.1 0.55 0.85];
if grp_idx % called from datamatcorrs plot
if update
opt.command = 'updateimg';
opt.usecolorbar = 0;
view_nii(gcf,nii.img,opt);
opt1.setcolormap = cmap;
view_nii(gcf,opt1);
else
if isstruct
opt.setbuttondown = 'struct_plot_datamatcorrs_3v(''SelectPixel'');';
else
opt.setbuttondown = 'pet_plot_datamatcorrs_3v(''SelectPixel'');';
end
opt.setarea = [0.32 0.1 0.55 0.85];
opt.setcolormap = cmap;
opt.useimagesc = 0;
opt.usepanel = 0;
opt.usecolorbar = 0;
tstfig = getappdata(gcf,'nii_view');
if isempty(tstfig)
opt.command = 'init';
else
opt.command = 'updatenii';
end
view_nii(gcf,nii,opt);
end
else
if update
opt.command = 'updateimg';
opt.usecolorbar = 0;
view_nii(gcf,nii.img,opt);
opt1.setcolormap = cmap;
view_nii(gcf,opt1);
else
if isstruct
opt.setbuttondown = 'struct_result_3v_ui(''SelectPixel'');';
else
opt.setbuttondown = 'pet_result_3v_ui(''SelectPixel'');';
end
opt.setarea = [0.32 0.1 0.55 0.85];
opt.setcolormap = cmap;
opt.useimagesc = 0;
opt.usepanel = 0;
opt.usecolorbar = 0;
tstfig = getappdata(gcf,'nii_view');
if isempty(tstfig)
opt.command = 'init';
else
opt.command = 'updatenii';
end
view_nii(gcf,nii,opt);
end
end
nii_view = getappdata(gcf,'nii_view');
h = findobj(gcf,'Tag','XYZVoxel');
set(h,'String',sprintf('%d %d %d',nii_view.imgXYZ.vox));
h = findobj(gcf,'Tag','XYZmm');
set(h,'String',sprintf('%2.1f %2.1f %2.1f',nii_view.imgXYZ.mm));
setappdata(gcf,'xyz',nii_view.imgXYZ.vox);
create_colorbar( colorbar_hdl, cbar_map, min_blv, max_blv ); % newcolor: was commented
% save the attributes of the current image
%
setappdata(gcf,'Dims',dims);
setappdata(gcf,'VoxelSize',voxel_size);
setappdata(gcf,'Origin',origin);
setappdata(gcf,'SliceIdx',slice_idx);
setappdata(gcf,'ImgHeight',img_height);
setappdata(gcf,'ImgWidth',img_width);
% setappdata(gcf,'RowsDisp',rows_disp);
% setappdata(gcf,'ColsDisp',cols_disp);
setappdata(gcf,'ImgRotateFlg',1);
setappdata(gcf,'NumLVs',num_lv);
% setappdata(gcf,'BLVData',brainlv);
setappdata(gcf,'BLVCoords',newcoords);
setappdata(gcf,'BLVThreshold',thresh);
setappdata(gcf,'RotateAmount',rot_amount);
setappdata(gcf,'BLVDisplay',blv);
% in order to use function like 'cluster' etc. created by fMRI
%
setappdata(gcf,'STDims',dims);
setappdata(gcf,'STVoxelSize',voxel_size);
setappdata(gcf,'STOrigin',origin);
setappdata(gcf,'WinSize',1);
if ViewBootstrapRatio
setappdata(gcf,'BSThreshold',thresh);
setappdata(gcf,'BSRatioCoords',newcoords);
end
if ~isempty(behav_idx) % called from datamatcorrs plot
setappdata(gcf,'NumBehav',num_behav);
end
% save background to img
%
setappdata(gcf,'cmap',cmap);
return; % pet_plot_brainlv_3v
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Convert the indexed matrix back into the original matrix
%
% Usage [outmat]=unmapblv(inmat, coords, siz)
%
% I (inmat): indexed matrix
% I (coords): index
% I (siz): size of original matrix
% O (outmat): original matrix
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [outmat] = unmapblv(inmat, coords, siz)
[r c]=size(inmat);
outmat=zeros(r,siz);
for i=1:r;
outmat(i,coords)=inmat(i,:);
end
return; % unmapblv
% adopted from bfm
%
%--------------------------------------------------------------------------
function [range, bar_data] = create_colorbar(axes_hdl,cmap,min_range,max_range)
tick_steps = (max_range - min_range) / (size(cmap,1) - 1);
y_range = [min_range:tick_steps:max_range];
range = [max_range:-tick_steps:min_range];
axes(axes_hdl);
img_h = image([0,1],[min_range max_range],[1:size(cmap,1)]');
% use true colour for the colour bar to make sure change of colormap
% won't affect it
%
bar_data = get(img_h,'CData');
len = length(bar_data);
cdata = zeros(len,1,3);
for i=1:len,
cdata(i,1,:) = cmap(bar_data(i),:);
end;
set(img_h,'CData',cdata);
% setup the axes property
% set(axes_hdl, 'XTick',[],'XLim',[0 1], ...
% 'YLim',[min_range max_range], ...
% 'YDir','normal', ...
% 'YAxisLocation','right');
set(axes_hdl, 'XTick',[], ...
'YLim',[min_range max_range], ...
'YDir','normal', ...
'YAxisLocation','right');
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -