-
Notifications
You must be signed in to change notification settings - Fork 36
/
read_crisp_regions.m
35 lines (26 loc) · 1 KB
/
read_crisp_regions.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
function regions = read_crisp_regions(filePath, imageSize)
% convert RGB mask into one where each region has an integer from 1 to max
% regions
mask_ = imread(filePath) ;
[~,~,mask] = unique(reshape(mask_, [], size(mask_,3)),'rows') ;
mask = reshape(mask, [size(mask_,1) size(mask_,2)]) ;
% make sure you read the {name}_l.png file --> edges should are set to 0
% make the boundary of the rsegions equal to zero
mask(mask == max(mask(:))) = 0 ;
% make sure that the mask has the same dimension of the image
mask = imresize(mask, imageSize, 'nearest') ;
% compute areas
areas = accumarray(mask(:)+1,1,[max(mask(:))+1 1])' ;
% convert to a region list
regions.basis = mask ;
regions.labels = num2cell(1:max(mask(:))) ;
regions.scores = zeros(1, numel(regions.labels)) ;
regions.areas = areas(2:end) ;
% after resizing some regions could be entirely lost; we should remove
% these from the list
ok = regions.areas > 0 ;
if any(~ok)
regions.areas(~ok) = [] ;
regions.labels(~ok) = [] ;
regions.scores(~ok) = [] ;
end