Skip to content

Commit

Permalink
add example file to generate template
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshuting committed Aug 14, 2023
1 parent 7daafb5 commit 1f6fb64
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
Binary file modified manual_multisession_align.mlapp
Binary file not shown.
62 changes: 62 additions & 0 deletions save_multisession_template_example.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,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');


Binary file modified view_multisession_align.mlapp
Binary file not shown.

0 comments on commit 1f6fb64

Please sign in to comment.