forked from MouseLightPipeline/pipeline-featmatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute_point_match_stack.m
63 lines (58 loc) · 3.53 KB
/
compute_point_match_stack.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
function result = compute_point_match_stack(sample_date, tile_index_from_ijk1, ijk1_from_tile_index, relative_path_from_tile_index)
% Get dimensions
tile_lattice_shape = size(tile_index_from_ijk1) ;
tile_count = length(relative_path_from_tile_index) ;
channel_count = 2 ;
% Determine which pairs are valid
central_tile_relative_path_from_pair_index = cell(tile_count,1) ;
other_tile_relative_path_from_pair_index = cell(tile_count,1) ;
central_tile_ijk1_from_pair_index = nan(tile_count, 3) ;
pair_count_so_far = 0 ;
for central_tile_index = 1 : tile_count ,
center_ijk1 = ijk1_from_tile_index(central_tile_index, :) ;
other_ijk1 = center_ijk1 + [0 0 1] ;
if all(other_ijk1 <= tile_lattice_shape) ,
other_tile_index = tile_index_from_ijk1(other_ijk1(1), other_ijk1(2), other_ijk1(3)) ;
if ~isnan(other_tile_index) ,
% Found a pair, so add the relative paths to the lists
other_tile_relative_path = relative_path_from_tile_index{other_tile_index} ;
center_tile_relative_path = relative_path_from_tile_index{central_tile_index} ;
pair_count_so_far = pair_count_so_far + 1 ;
pair_index = pair_count_so_far ;
central_tile_relative_path_from_pair_index{pair_index} = center_tile_relative_path ;
other_tile_relative_path_from_pair_index{pair_index} = other_tile_relative_path ;
central_tile_ijk1_from_pair_index(pair_index, :) = center_ijk1 ;
end
end
end
pair_count = pair_count_so_far ;
central_tile_relative_path_from_pair_index = central_tile_relative_path_from_pair_index(1:pair_count) ; % trim
other_tile_relative_path_from_pair_index = other_tile_relative_path_from_pair_index(1:pair_count) ; %#ok<NASGU> % trim
central_tile_ijk1_from_pair_index = central_tile_ijk1_from_pair_index(1:pair_count,:) ; % trim
z_point_match_path = fullfile('/nrs/mouselight/pipeline_output', sample_date, 'stage_4_point_match_output') ;
match_count_from_ijk1_and_channel_index = nan(tile_lattice_shape(1), tile_lattice_shape(2), tile_lattice_shape(3), channel_count) ;
for pair_index = 1 : pair_count ,
central_tile_relative_path = central_tile_relative_path_from_pair_index{pair_index} ;
%other_tile_relative_path = other_tile_relative_path_from_pair_index{pair_index} ;
central_tile_ijk1 = central_tile_ijk1_from_pair_index(pair_index,:) ;
for channel_index = 1 : channel_count ,
if isequal(sample_date, '2020-11-26') ,
% Special handling older samples
if channel_index == 0 ,
continue
else
z_match_output_file_name = fullfile(z_point_match_path, central_tile_relative_path, 'match-Z.mat') ; % this is for channel 1
end
else
% The general case
z_match_output_file_name = fullfile(z_point_match_path, central_tile_relative_path, sprintf('channel-%d-match-Z.mat', channel_index-1)) ;
end
if exist(z_match_output_file_name, 'file') ,
load(z_match_output_file_name, 'paireddescriptor') ;
match_count = size(paireddescriptor.X, 1) ;
match_count_from_ijk1_and_channel_index(central_tile_ijk1(1), central_tile_ijk1(2), central_tile_ijk1(3), channel_index) = match_count ;
end
end
end
result = match_count_from_ijk1_and_channel_index ;
end