-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_circle_num_to_arena_id_map.m
39 lines (33 loc) · 1.21 KB
/
get_circle_num_to_arena_id_map.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
function arena_map = get_circle_num_to_arena_id_map(masks)
% Initialize the map container
arena_map = containers.Map('KeyType', 'int32', 'ValueType', 'char');
% Get the number of masks
[numMasks, ~, ~] = size(masks);
% Initialize arrays to store centroid coordinates
centroidsX = zeros(1, numMasks);
centroidsY = zeros(1, numMasks);
% Calculate centroids for each mask
for m = 1:numMasks
currentMask = squeeze(masks(m, :, :));
props = regionprops(currentMask, 'Centroid');
centroidsX(m) = props.Centroid(1);
centroidsY(m) = props.Centroid(2);
end
% Calculate average centroid coordinates
avgX = mean(centroidsX);
avgY = mean(centroidsY);
% Determine quadrant for each mask
for m = 1:numMasks
if centroidsX(m) > avgX && centroidsY(m) < avgY
arena_id = 'A';
elseif centroidsX(m) > avgX && centroidsY(m) > avgY
arena_id = 'B';
elseif centroidsX(m) < avgX && centroidsY(m) > avgY
arena_id = 'C';
else % centroidsX(m) < avgX && centroidsY(m) < avgY
arena_id = 'D';
end
% Map the mask number to the arena_id
arena_map(m) = arena_id;
end
end