-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_extract_regions_from_labels.m
47 lines (37 loc) · 1.34 KB
/
run_extract_regions_from_labels.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
% Create the regions from the ground truth (manually annotated) labels.
addpath('common/');
consts.level=0;
Consts;
if ~exist(consts.imageRegionsDir, 'dir')
mkdir(consts.imageRegionsDir);
end
%%
for ii = 1 : consts.numImages
fprintf('Extracting regions from labels %d/%d.\n', ii, consts.numImages);
if ~consts.useImages(ii)
continue;
end
load(sprintf(consts.objectLabelsFilename, ii), 'imgObjectLabels');
load(sprintf(consts.instanceLabelsFilename, ii), 'imgInstanceLabels');
imgRegions = get_regions_from_labels(imgObjectLabels, imgInstanceLabels);
% Chuck any regions that are not big enough.
[~, R] = get_region_ids(imgRegions);
for rr = 1 : R
regionMask = imgRegions == rr;
if nnz(regionMask) < consts.MIN_PIXELS_PER_REGION
fprintf('Discarding a region with less than %d pixels.\n', consts.MIN_PIXELS_PER_REGION);
imgRegions(regionMask) = 0;
end
end
% Now, go back and remap the labels to avoid situations in which we have
% regions [1 2 4].
[regionIds, R] = get_region_ids(imgRegions);
for rr = 1 : R
regionMask = imgRegions == regionIds(rr);
imgRegions(regionMask) = rr;
end
[regionIds, R] = get_region_ids(imgRegions);
assert(max(imgRegions(:)) == R);
assert(max(imgRegions(:)) == numel(regionIds));
save(sprintf(consts.imageRegionsFilename, ii), 'imgRegions');
end