-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmake_grayplot.m
More file actions
58 lines (43 loc) · 1.41 KB
/
make_grayplot.m
File metadata and controls
58 lines (43 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
% make_grayplot.m
%
% inputs: filenames, not structures. uses vista niftiRead rather than
% matlab for now
%
% will use voxels ~= 0 for mask
%
% if out_img is empty, just plot. if out_img is defined, plot hidden and
% save
%
% TCS 10/19/2021
function make_grayplot(data_nii_file,mask_nii_file,out_img)
data_nii = niftiRead(data_nii_file);
% if no mask given, find std dev ~= 0 voxels to analyze
if nargin < 2 || isempty(mask_nii_file)
mask_nii = data_nii;
mask_nii.data = mask_nii.data(:,:,:,1);
mask_nii.data = std(double(data_nii.data),[],4) ~= 0;
else
mask_nii = niftiRead(mask_nii_file);
end
% if not single/double, cast to double
if ~ismember(class(data_nii.data),{'single','double'})
data_nii.data = double(data_nii.data);
end
data_mat = niftiExtract(data_nii,mask_nii);
% normalize, detrend, etc
data_mat_norm = detrend(data_mat,2); % linear (quad?) detrend
data_mat_norm = data_mat_norm./std(data_mat_norm,[],1);
%data_mat_norm = data_mat;
if nargin < 3 || isempty(out_img)
% figure out scale...
clims = prctile(data_mat_norm(:),[5 95]);
figure;
imagesc((0:(data_nii.dim(4)))*data_nii.pixdim(4),1:size(data_mat_norm,2),data_mat_norm.');
%set(gca,'CLim',clims,'TickDir','out');
imax = gca;
imax.CLim = clims; imax.TickDir = 'out'; imax.Box = 'off';
colormap gray;
xlabel('Time (s)'); ylabel('Voxel');
th = title(data_nii_file,'Interpreter','none');
end
return