-
Notifications
You must be signed in to change notification settings - Fork 0
/
detectBodyPartsFromHeatmaps.m
32 lines (27 loc) · 1.33 KB
/
detectBodyPartsFromHeatmaps.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
% INPUT
% heatmaps: matrix of size [heatmapHeight * heatmapWidth * numBodyParts]
% one heatmap for each body part showing probability that particular
% body part is located at a particular location in the image
% params: struct with constants
% OUTPUT
% bodyParts: cell array of size [numBodyParts * 1] where each cell is
% matrix of size [numDetections(variable) * 2(x,y)]
% detectionScores: cell array of size [numBodyParts * 1] where each cell is
% matrix of size [numDetections(variable) * 1(detectionScore)]
function [bodyParts,detectionScores] = detectBodyPartsFromHeatmaps(heatmaps,params)
bodyParts = cell(params.NUM_BODY_PARTS,1);
detectionScores = cell(params.NUM_BODY_PARTS,1);
for i = 1:params.NUM_BODY_PARTS
%get the heatmap for the current body part type
h = heatmaps(:,:,i);
%suppress values below threshold
h(h < params.FILTER_THRESHOLD) = NaN;
%apply max filter to heatmap
maxImage = imdilate(h,ones(params.FILTER_WINDOW_SIZE));
%suppress non-max values
maxes = (h == maxImage);%maxes occur where the heatmap is equal to the max filter
[rows,cols] = ind2sub(size(maxes),find(maxes)); %find nonzero indices
bodyParts{i} = [cols rows];
detectionScores{i} = h(maxes);
end
end