-
Notifications
You must be signed in to change notification settings - Fork 0
/
img_seperate.m
40 lines (33 loc) · 923 Bytes
/
img_seperate.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 [count, s] = img_seperate(label_matrix)
%IMG_SEPERATE 此处显示有关此函数的摘要
% 统计label数目
count = 0;
label = [];
h = size(label_matrix, 1);
w = size(label_matrix, 2);
for i = 1 : h
for j = 1 : w
if label_matrix(i,j) == 0
continue;
else
if ~ismember(label_matrix(i,j), label)
label = [label, label_matrix(i,j)];
count = count + 1;
end
end
end
end
s(count) = struct('Image',[],'address',[],'Centroid',[],'BoundingBox',[]);
for i=1:count
[r,c] = find(label_matrix == label(i));
s(i).address = [r,c];
r_ = r-min(r)+1;
c_ = c-min(c)+1;
s(i).Image = zeros(max(r_)+20,max(c_)+20);
s(i).BoundingBox=[min(r)-0.5,min(c)-0.5,max(r)+0.5,max(c)+0.5];
for q=1:size(r_)
s(i).Image(r_(q)+10,c_(q)+10)=1;
end
s(i).Centroid=[mean(r),mean(c)];
end
end