forked from hanshuting/manual-multisession-alignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_multisession_template_example.m
More file actions
62 lines (48 loc) · 1.67 KB
/
save_multisession_template_example.m
File metadata and controls
62 lines (48 loc) · 1.67 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
59
60
61
62
clear all;
%%
base_dir = 'W:\Transfer\Shuting\Xin_multi day recording';
file_names = {'XS089_20230811', 'XS089_20230812'};
nset = length(file_names);
save_path = fullfile(base_dir, 'results');
if ~exist(save_path)
mkdir(save_path);
end
%% load template and spatial components
template = cell(1,nset);
ROI_mask = cell(1,nset);
for dataid = 1:nset
data_file = fullfile(base_dir, file_names{dataid}, 'Fall.mat');
data = load(data_file);
dims = size(data.ops.meanImg);
% save template - avg projection
% im = data.ops.meanImg;
% save template - max projection
im = zeros(dims);
im(data.ops.yrange(1)+1:data.ops.yrange(2), data.ops.xrange(1)+1:data.ops.xrange(2)) = ...
data.ops.max_proj;
template{dataid} = im;
dims = size(im);
% get spatial components
for i = 1:length(data.stat)
An = false(dims);
idx = sub2ind(dims, data.stat{i}.ypix+1, data.stat{i}.xpix+1);
An(idx) = 1;
ROI_mask{dataid}.cent(i,:) = double(data.stat{i}.med([2,1])) + 1;
ROI_mask{dataid}.cont{i} = cell2mat(bwboundaries(An==1));
end
ROI_mask{dataid}.cent = ROI_mask{dataid}.cent(data.iscell(:,1)==1,:);
ROI_mask{dataid}.cont = ROI_mask{dataid}.cont(data.iscell(:,1)==1);
end
%% plot template
figure; set(gcf,'color','w');
for dataid = 1:nset
subplot(1,nset,dataid);
if isempty(template{dataid}); continue; end
imagesc(template{dataid}); colormap(gray); hold on;
title(['day ' num2str(dataid)], 'FontWeight', 'Normal');
axis off;
end
linkaxes;
%% save
save(fullfile(save_path, 'template.mat'), 'template', '-v7.3');
save(fullfile(save_path, 'spatial.mat'), 'ROI_mask', '-v7.3');