-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlotImportantLinesForSupervoxels.m
178 lines (152 loc) · 5.31 KB
/
PlotImportantLinesForSupervoxels.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
function [hfig_showlines,hax_showlines,...
hfig_showlineaverage,hax_showlineaverage] = ...
PlotImportantLinesForSupervoxels(imdata,line_names_show,varargin)
[computeavemethod,hfig_showlines,hfig_showlineaverage,labels,supervoxeldata,SetStatusFcn,anatomydir,isflylightdir] = ...
myparse(varargin,'computeavemethod','',...
'hfig_showlines',[],'hfig_showlineaverage',[],'labels',[],'supervoxeldata',[],'SetStatusFcn',@fprintf,...
'anatomydir','','isflylightdir',true);
hax_showlineaverage = [];
nlinesshow = numel(line_names_show);
isflylightwebsiteinfo = isfield(imdata,'maxproj_url');
if isflylightwebsiteinfo,
isonweb = ~cellfun(@isempty,{imdata.maxproj_url});
end
% create figure
if isempty(hfig_showlines) || ~ishandle(hfig_showlines);
hfig_showlines = figure;
else
clf(hfig_showlines);
end
% show max projections
% create axes
nax = nlinesshow+1;
nr = ceil(sqrt(nax));
nc = ceil(nax/nr);
hax_showlines = createsubplots(nr,nc,.01,hfig_showlines);
hax_showlines = reshape(hax_showlines,[nr,nc])';
delete(hax_showlines(nlinesshow+1:end));
hax_showlines = hax_showlines(1:nlinesshow);
% show the max projection images
didplot = false(1,nlinesshow);
for i = 1:nlinesshow,
% find images of this line
if ~isflylightdir && isflylightwebsiteinfo,
idxanat = find(isonweb & strcmp({imdata.line},line_names_show{i}));
else
idxanat = find(strcmp({imdata.line},line_names_show{i}));
end
% sort by qi
[~,order2] = sort([imdata(idxanat).qi]);
% find registered max proj images
reg_file = '';
for j = idxanat(order2)',
if ~isflylightdir && isflylightwebsiteinfo,
reg_file = imdata(j).reg_file_url;
else
reg_file = GetRegMaxProjFile(imdata(j));
end
if ~isempty(reg_file),
break;
end
end
% if not registered, find original max proj images
if isempty(reg_file),
for j = idxanat(order2)',
if ~isflylightdir && isflylightwebsiteinfo,
reg_file = imdata(j).maxproj_url;
else
reg_file = imdata(j).maxproj_file_system_path;
if ~exist(reg_file,'file'),
reg_file = '';
end
end
if ~isempty(reg_file),
break;
end
end
end
% plot
if ~isempty(reg_file),
try
im = imread(reg_file);
image(im,'Parent',hax_showlines(i));
axis(hax_showlines(i),'image','off');
didplot(i) = true;
end
end
end
linkaxes(hax_showlines(didplot));
if ~all(didplot),
delete(hax_showlines(~didplot));
end
if isempty(computeavemethod) && isempty(supervoxeldata),
computeavemethod = 'True';
elseif isempty(computeavemethod) && (isempty(anatomydir) || ~exist(anatomydir,'dir')),
computeavemethod = 'Supervoxel';
end
if isempty(computeavemethod),
computeavemethod = questdlg('Show supervoxel-based average (less slow) or true average (slow)?',...
'Line average type','Supervoxel','True','Cancel','Supervoxel');
end
if strcmpi(computeavemethod,'Cancel'),
return;
end
% create figure for average
if isempty(hfig_showlineaverage) || ~ishandle(hfig_showlineaverage);
hfig_showlineaverage = figure;
else
clf(hfig_showlineaverage);
end
hax_showlineaverage = createsubplots(nr,nc,.01,hfig_showlineaverage);
hax_showlineaverage = reshape(hax_showlineaverage,[nr,nc])';
delete(hax_showlineaverage(nlinesshow+2:end));
hax_showlineaverage = hax_showlineaverage(1:nax);
if strcmpi(computeavemethod,'Supervoxel'),
meanimcurr = nan(size(labels),'single');
meanimcurr(labels>0) = mean(supervoxeldata(:,labels(labels>0)),1);
elseif strcmpi(computeavemethod,'True'),
SetStatusFcn('Reading in line %d / %d...',1,nlinesshow);
i = 1;
filename = fullfile(anatomydir,sprintf('meanim_%s.mat',line_names_show{i}));
tmp = load(filename,'meanim');
imcurr = repmat(permute(tmp.meanim,[2,1,3]),[1,1,1,nlinesshow]);
for i = 2:nlinesshow,
SetStatusFcn('Reading in line %d / %d...',i,nlinesshow);
filename = fullfile(anatomydir,sprintf('meanim_%s.mat',line_names_show{i}));
tmp = load(filename,'meanim');
imcurr(:,:,:,i) = permute(tmp.meanim,[2,1,3]);
end
meanimcurr = mean(imcurr,4);
end
imagesc(max(meanimcurr,[],3),'Parent',hax_showlineaverage(nax),[0,1]);
axis(hax_showlineaverage(nax),'image','off');
colormap(hax_showlineaverage(nax),kjetsmooth(256));
if verLessThan('matlab','8.4.0'),
colorbar('peer',hax_showlineaverage(nax),'East');
else
colorbar('peer',handle(hax_showlineaverage(nax)),'East');
end
drawnow;
for i = 1:nlinesshow,
if strcmpi(computeavemethod,'Supervoxel'),
imcurr = nan(size(labels),'single');
imcurr(labels>0) = supervoxeldata(i,labels(labels>0));
imcurr = meanimcurr .* imcurr;
imagesc(max(imcurr,[],3),'Parent',hax_showlineaverage(i),[0,1]);
else
imagesc(max(meanimcurr.*imcurr(:,:,:,i),[],3),'Parent',hax_showlineaverage(i),[0,1]);
end
axis(hax_showlineaverage(i),'image','off');
colormap(hax_showlineaverage(i),kjetsmooth(256));
% TODO: move to main function
% text(5,5,sprintf('%s: (beh = %.1f) * (anat = %.1f) -> (index = %.1f)',...
% line_names_show{i},...
% handles.bamap.normbehaviordata(i),...
% supervoxeldata(i,supervoxelid),...
% handles.bamap.normbehaviordata(i)*supervoxeldata(i,supervoxelid)),...
% 'Color','w','HorizontalAlignment','left','VerticalAlignment','top',...
% 'Interpreter','none','Parent',hax_showlineaverage(i));
drawnow;
end
impixelinfo(hfig_showlineaverage);
linkaxes(hax_showlineaverage);