-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathshape_plot_subj.m
121 lines (106 loc) · 3.67 KB
/
shape_plot_subj.m
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
function ind = shape_plot_subj(dat, model, opt, ind)
% Plot PG + lower bound stuff
% This function is highly specific to this particular model. Not sure I can
% come up with a generic "plotModel" function, even though it could be
% nice.
if opt.ui.verbose && ischar(opt.ui.figure_sub)
if nargin < 4 || isempty(ind)
N = min(opt.f.N, 5);
ind = randperm(numel(dat), N);
else
N = numel(ind);
end
f = findobj('Type', 'Figure', 'Name', opt.ui.figure_sub);
if isempty(f)
f = figure('Name', opt.ui.figure_sub, 'NumberTitle', 'off');
end
set(0, 'CurrentFigure', f);
clf(f);
nw = 4;
nh = N;
i = 0;
for j=1:numel(ind)
i = plot_one(dat(ind(j)), model, opt, i, nh, nw);
end
end
end
function i = plot_one(dat, model, opt, i, nh, nw)
if dat.f.observed
% -------------------------------------------------------------
% Observed image
i = i+1;
subplot(nh, nw, i);
if any(strcmpi(opt.model.name, {'categorical', 'multinomial', 'cat', 'mult'}))
im = catToColor(dat.f.f(:,:,ceil(size(dat.f.f,3)/2),:));
implot = @(X) image(X);
else
im = dat.f.f(:,:,ceil(size(dat.f.f,3)/2),1);
implot = @(X) colormap(get(imagesc(X), 'Parent'), 'gray');
end
dim = [size(im) 1 1];
if dim(4) > 1
im = reshape(im, [dim(1:2) dim(4)]);
end
im = permute(im, [2 1 3]);
vs = sqrt(sum(dat.f.M(1:3,1:3).^2));
asp = 1./[vs(2) vs(1) 1];
implot(im(end:-1:1,:,:));
daspect(asp);
axis off
% -------------------------------------------------------------
% Warped template
i = i+1;
subplot(nh, nw, i);
if any(strcmpi(opt.model.name, {'categorical', 'multinomial', 'cat', 'mult'}))
im = catToColor(dat.tpl.wmu(:,:,ceil(size(dat.tpl.wmu,3)/2),:));
implot = @(X) image(X);
else
im = dat.tpl.wmu(:,:,ceil(size(dat.tpl.wmu,3)/2),1);
implot = @(X) colormap(get(imagesc(X), 'Parent'), 'gray');
end
dim = [size(im) 1 1];
if dim(4) > 1
im = reshape(im, [dim(1:2) dim(4)]);
end
im = permute(im, [2 1 3]);
vs = sqrt(sum(dat.f.M(1:3,1:3).^2));
asp = 1./[vs(2) vs(1) 1];
implot(im(end:-1:1,:,:));
daspect(asp);
axis off
% -------------------------------------------------------------
% Deformation
i = i + 1;
subplot(nh,nw,i)
def = numeric(dat.v.ipsi);
latf = [size(dat.f.f) 1];
latf = latf(1:3);
if isfield(dat.q, 'A')
Aq = dat.q.A;
else
Aq = eye(4);
end
id = reconstructIPsi(Aq, spm_warps('identity', opt.tpl.lat), ...
'lat', latf, 'Mf', dat.f.M, 'Mmu', opt.tpl.M);
def = def - id;
clear id
im = defToColor(def(:,:,ceil(size(def,3)/2),:));
clear def
dim = [size(im) 1 1];
im = permute(reshape(im, [dim(1:2) dim(4)]), [2 1 3]);
vs = sqrt(sum(dat.f.M(1:3,1:3).^2));
asp = 1./[vs(2) vs(1) 1];
image(im(end:-1:1,:,:));
daspect(asp);
axis off
% -------------------------------------------------------------
% Latent coordinates
i = i + 1;
subplot(nh,nw,i)
scatter(model.z.Z(1,:),model.z.Z(2,:), 'filled')
hold on
scatter(dat.z.z(1), dat.z.z(2), 500, 'red', 'p', 'filled')
hold off
else
end
end