-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimmieng.asv
51 lines (48 loc) · 1.71 KB
/
timmieng.asv
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
%% Chuong trinh cat ra vung mieng, va tinh ra toa do hai diem ngoai cung
% cua mieng.
% Dau vao :
% Image : Anh goc
% x1 : Toa do hang cua tam con nguoi ben trai
% x2 : Toa do hang cua tam con nguoi ben phai
% y1 : Toa do cot cua tam con nguoi ben trai
% y2 : Toa do cot cua tam con nguoi ben phai
% Dau ra :
% point_left: Toa do cua diem ngoai cung ben trai
% point_right : Toa do cua diem ngoai cung ben phai
% mouth : Anh mieng duoc cat.
% By : Nguyen Van Linh
% SipLab_K52, Dien tu vien thong, Dai hoc Bach Khoa Ha Noi
function [mouth_out,point]=timmieng(Image,x1,y1,x2,y2)
% Tinh khoang cach hai mat.
%distance_eyes = norm([(x2-x1),(y2-y1)]);
[m,n] = size(Image);
distance_col = y2-y1;
if ((x2+distance_col-10)>0) & ((x1+distance_col+20)<m) &((y1-3)>0)&((y2+3)<n)
mouth = Image((x2+distance_col-10):(x2+distance_col+20),(y1-3):(y2+3),:);
else
mouth = Image;
end
mouth_cut = mouth;
mouth = rgb2gray(mouth);
%mouth = edge(mouth,'canny');
se = strel('disk',3);
mouth = imclose(mouth,se);
th = graythresh(mouth);
mouth = edge(mouth,'canny',th);
%mouth = im2bw(mouth);
mouth = bwmorph(mouth,'Skel',Inf);
[mouth,cenline] = maxregion(mouth);
[Xmouth,Ymouth] = find(mouth==1);
[point1,j] = min(Xmouth(:));
point = point1;
%point = [point1,Ymouth(j)];
mouth((point1+4):size(mouth,1),1:round(size(mouth,2)/4)) = 0;
mouth((point1+4):size(mouth,1),round(3*size(mouth,2)/4):size(mouth,2)) = 0;
i = find(Xmouth==(point1+3));
Pout = Ymouth(i);
for k=1:size(i,1)
kcach(k) = norm([(size(mouth,1)-(point1+3)),(round(size(mouth,2)/2)-Pout(k))]);
end
[point_out,j] = min(kcach(:));
point2 = Pout(j);
point = [(point1+3),point2];