Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[79637f]: devel / Demos / geom2d / triangle / triangle.m Maximize Restore History

Download this file

triangle.m    78 lines (69 with data), 2.2 kB

 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#TRIANGLE - compare forme des cellules avec celle d'un triangle.
#
#
# ---------
#
# author : David Legland
# INRA - TPV URPOI - BIA IMASTE
# created the 16/01/2004
#
name = 'qu61';
img = imread(sprintf('~/images/ref2003/img/%s10.bmp', name));
lbl = imread(sprintf('~/matlab/res/seg2d/%slbl.tif', name));
lbl = cleanLabels(lbl);
stats = regionprops(lbl, 'Centroid', 'BoundingBox', 'Area', 'Image');
ori = zeros(double(max(lbl(:))), 24);
for cell = 1:double(max(lbl(:)))
disp(sprintf('cell : %d', cell));
# caracteristiques geometriques de la cellule.
box = stats(cell).BoundingBox;
center = stats(cell).Centroid;
# teste 24 directions possibles.
for angle=0:15:359
#angle = 0;
x0 = floor(center(1));
y0 = floor(center(2));
dx = cos(angle*pi/180);
dy = sin(angle*pi/180);
len = 1;
# distingue les lignes horizontales et verticales
if abs(dx)>abs(dy)
# part de (x0,y0) en incrementant x0
trueY = y0;
dx = sign(dx);
while lbl(y0, x0)==cell
x0 = x0 + dx;
if x0>size(lbl, 2) | x0<1
break;
end
trueY = trueY + dy;
if abs(trueY - y0) > .5
y0 = y0+sign(dy);
if y0>size(lbl, 1) | y0<1
break;
end
end
len = len + 1;
end
else
# part de (x0,y0) en incrementant y0
trueX = x0;
dy = sign(dy);
while lbl(y0, x0)==cell
y0 = y0 + dy;
if y0>size(lbl, 1) | y0<1
break;
end
trueX = trueX + dx;
if abs(trueX - x0) > .5
x0 = x0+sign(dx);
if x0>size(lbl, 2) | x0<1
break;
end
end
len = len + 1;
end
end
ori(cell, angle/15 + 1) = len;
end
end