-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeTriangles.py
46 lines (36 loc) · 1.36 KB
/
makeTriangles.py
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
'''
Script to generate a nunch of triangle images for training an ANN to find triangles.
The hope is that we can apply this ANN to other images to find triangles.
The triangles will be somewhat equilateral.
'''
import numpy
import PIL
import PIL.Image
import PIL.ImageDraw
imageSizes = [250,
500,]
# Colours of the (background, triangle, and width)
imageColours = [('black', 'white', 1),
('white','black', 1),
('white', 'pink', 5)] # for testing purposes
for iSize in imageSizes:
for i in range(50):
# top point (make it near the top centre)
x1 = numpy.random.randint(low=(iSize/2)*0.75, high=(iSize/2)*1.25)
y1 = numpy.random.randint(low=0, high=iSize*.1)
## left point
x2 = numpy.random.randint(low=0, high=x1)
y2 = numpy.random.randint(low=iSize/2, high=iSize)
# right point
x3 = numpy.random.randint(low=min((x2+(x1-x2)*2)*0.9, iSize-1), high= min((x2+(x1-x2)*2)*1.1, iSize))
y3 = numpy.random.randint(low=(y2)*0.9, high= min((y2)*1.1,iSize))
print x1, y1
print x2, y2
print x3, y3
for iCol in imageColours:
img = PIL.Image.new('RGB', (iSize,iSize), iCol[0])
draw = PIL.ImageDraw.Draw(img)
draw.line((x1,y1, x2, y2), iCol[1], width=iCol[2])
draw.line((x2,y2, x3, y3), iCol[1], width=iCol[2])
draw.line((x3,y3, x1, y1), iCol[1], width=iCol[2])
img.save('./trainingTriangles/' + str(i) + '_' + iCol[1] + '.bmp')