-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateImagesFromData.py
More file actions
112 lines (85 loc) · 3.47 KB
/
GenerateImagesFromData.py
File metadata and controls
112 lines (85 loc) · 3.47 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Imports and packages =========================================================
from PIL import Image
from GenerateSubsolutions import *
from ScrambleGenerator import *
import numpy as np
imageMultiplier = 100
startState, solution = ScrambleGenerator("SlidingTile", 8, 15)
print(startState)
subsolutions = GenerateSubsolutions("SlidingTile", 8, startState, [[0,1,2],[3,4,5],[6,7,8]])
print(subsolutions)
maxSubsolutionLength = 0
maxChildNumber = 0
for i in range(len(subsolutions)):
if len(subsolutions[i]) > maxChildNumber:
maxChildNumber = len(subsolutions[i])
for j in range(len(subsolutions[i])):
if len(subsolutions[i][j]) > maxSubsolutionLength:
maxSubsolutionLength = len(subsolutions[i][j])
print()
print("Max subsolution length: " + str(maxSubsolutionLength))
print("Max number of children: " + str(maxChildNumber))
for i in range(len(subsolutions)):
newImage = Image.new("RGB", (imageMultiplier*maxSubsolutionLength, imageMultiplier*maxChildNumber))
#dataArray = np.zeros([maxChildNumber, maxSubsolutionLength])
dataArray = []
for j in range(len(subsolutions[i])):
currentSolution = subsolutions[i][j]
for l in range(imageMultiplier):
randomTest = []
for k in range(len(currentSolution)):
if currentSolution[k] == 0:
colour = (255, 0, 0)
elif currentSolution[k] == 1:
colour = (0, 255, 0)
elif currentSolution[k] == 2:
colour = (0, 0, 255)
elif currentSolution[k] == 3:
colour = (255, 255, 0)
for x in range(imageMultiplier):
dataArray.append(colour)
randomTest.append(colour)
for k in range(maxSubsolutionLength - len(currentSolution)):
for x in range(imageMultiplier):
dataArray.append((0,0,0))
randomTest.append(colour)
flattenData = list(dataArray)
#print(flattenData)
newImage.putdata(flattenData)
pngFileName = "TestImages/subsol" + str(i + 1) + ".png"
newImage.save(pngFileName)
newImage = Image.new("RGB", (imageMultiplier*len(solution), imageMultiplier*1))
dataArray = []
currentSolution = solution
for l in range(imageMultiplier):
randomTest = []
for k in range(len(currentSolution)):
if currentSolution[k] == 0:
colour = (255, 0, 0)
elif currentSolution[k] == 1:
colour = (0, 255, 0)
elif currentSolution[k] == 2:
colour = (0, 0, 255)
elif currentSolution[k] == 3:
colour = (255, 255, 0)
for x in range(imageMultiplier):
dataArray.append(colour)
randomTest.append(colour)
for k in range(maxSubsolutionLength - len(currentSolution)):
for x in range(imageMultiplier):
dataArray.append((0,0,0))
randomTest.append(colour)
flattenData = list(dataArray)
#print(flattenData)
newImage.putdata(flattenData)
pngFileName = "TestImages/solution.png"
newImage.save(pngFileName)
# image = Image.open("TestImages/testImage_001.png")
# print(image.mode)
# print(image.size)
# image_out = Image.new(image.mode,image.size)
#
# pixels = list(image.getdata())
# print(pixels.type())
# image_out.putdata(pixels)
# image_out.save('TestImages/test_out.png')