-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.m
54 lines (51 loc) · 1.7 KB
/
main.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
48
49
50
51
52
53
54
clear;
clc;
close all;
format compact;
format long;
RGBImg = imread('./imgs/TestImage.jpg');
grayImg = rgb2gray(RGBImg);
cb_scale = 2;
cr_scale = 1;
% statistical information
[cb_mean, cr_mean, cb_std, cr_std] = cbcrPlate(cb_scale, cr_scale)
% image binarization
result = FaceBinarization(RGBImg, cb_mean, cr_mean, cb_std, cr_std, cb_scale, cr_scale);
% fill background holes
result = bwfill(result, 'holes');
% remove isolated small white area
result = bwareaopen(result, 500);
% erosion
result = imerode(result, ones(5));
% Robert edge
edgeImg = edge(grayImg, 'roberts', 0.1);
edgeImg = ~edgeImg;
% integeration of 2 images, result + edge image
result = 255*(double(result) & double(edgeImg));
% erosion
result = imerode(result, ones(5));
% fill background holes
result = bwfill(result, 'holes');
% remove isolated small white area
result = bwareaopen(result, 500);
% group labeling
[segments, num_segments] = bwlabel(result);
status = regionprops(segments, 'BoundingBox');
width_all = []; height_all = [];
for i=1:num_segments
width_all = [width_all; status(i).BoundingBox(3)];
height_all = [height_all; status(i).BoundingBox(4)];
end
% figure;
% subplot(221), hist(width_all, 50), title('标记区域宽的分布图');
% subplot(222), hist(height_all, 50), title('标记区域高的分布图');
% subplot(223), hist(height_all./width_all, 50), title('标记区域高宽比的分布图');
% show labeled image
figure, imshow(RGBImg);
for i=1:num_segments
width = status(i).BoundingBox(3);
height = status(i).BoundingBox(4);
ratio = height/width;
if ratio > 3 || ratio < 0.75 || (width < 40 & height < 50) continue; end
rectangle('position', status(i).BoundingBox, 'edgecolor', 'r');
end