-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblockInsideRectangle.m
35 lines (31 loc) · 1.17 KB
/
blockInsideRectangle.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
function [result] = blockInsideRectangle(block,rectangle,threshold)
pointTopLeft = [block(1) block(2)];
pointTopRight = [(block(1)+block(3)) block(2)];
pointBottomLeft = [block(1) (block(2)+block(4))];
pointBottomRight = [(block(1)+block(3)) (block(2)+block(4))];
points=[pointTopLeft; pointTopRight; pointBottomLeft; pointBottomRight];
found=false;
cont=1;
while (~found) & (cont<=4)
point = points(cont,:);
found = pointInsideRectangle(point,rectangle);
cont = cont+1;
end
if found
inside=0;
for x=block(1):block(1)+block(3)
for y=block(2):block(2)+block(4)
if pointInsideRectangle([x y],rectangle)
inside = inside + 1;
end
end
end
p=inside/(floor(block(3))*floor(block(4)));
result = p > threshold;
else
result =false;
end
end
function [result] = pointInsideRectangle(point,rectangle)
result = point(1)>rectangle(1) & point(1)<(rectangle(1)+rectangle(3)) & point(2)>rectangle(2) & point(2)<(rectangle(2)+rectangle(4));
end