-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_driver.py
More file actions
77 lines (64 loc) · 2.46 KB
/
graph_driver.py
File metadata and controls
77 lines (64 loc) · 2.46 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
import PIL.Image as Image
import os
import shutil
import midend.adaptor as adaptor
import midend.result as result
def generate():
fileIn = "accTests/inputs/RGBtemp/rgb_001.png"
pilImage = Image.open(fileIn)
# Run red, green and blue autos:
color_list = ["r", "g", "b"]
g0 = 1
w = 10
ginf = 0
range_val = 20
consider_deltas = True
resultLists = adaptor.run_dual_mixed_image(pilImage, color_list, g0, w,
ginf, range_val, consider_deltas)
generate_graphs(resultLists)
# Should now be a graph0.png, graph1.png, graph2.png
return resultLists
def generate_graphs(resultList, name_format="graph%d.png"):
for i, x in enumerate(resultList):
# Get a file like object that contains the string of the image.
fileLike = x.plotToStringIO()
lines = fileLike.readlines()
outFile = open(name_format % i, "wb")
firstLine = True
for line in lines:
outFile.write(line)
def generateTriple():
fileIn = "accTests/inputs/RGBtemp/rgb_001.png"
pilImage = Image.open(fileIn)
limit = 32 # Hardcoded as example
range_val = 15 # Hardcoded as example
g0 = 50
w = 2
ginf = 0
firstResult = adaptor.run_triple_mixed_image_part1(pilImage)
generate_graphs([firstResult], name_format="triplegraph_1_%d.png")
secondResult = adaptor.run_triple_part2(firstResult, limit)
generate_graphs([secondResult], name_format="triplegraph_2_%d.png")
finalResult = adaptor.run_triple_part3(secondResult, range_val, g0, w, ginf)
generate_graphs([finalResult], name_format="triplegraph_3_%d.png")
return finalResult
def saveAllFiles(results):
outputPath = "output/"
# save results.txt, filename is usually "results.txt", just making the
# argument obvious
if os.path.exists(outputPath):
shutil.rmtree(outputPath)
os.mkdir(outputPath)
result.saveResultsFile(outputPath, results, filename="results.txt")
# result.saveResultsFile(outputPath, results) is equivalent
# Save other files
for res in results:
#Save data, setting names to their default values
res.saveData(outputPath, dataName=None, fitName=None)
# res.saveData(outputPath) is equivalent
# can also save to a file like object:
# res.saveDataFileLike(dataFileLike, fitFileLike)
if __name__ == "__main__":
outputs = generate()
outputs.append(generateTriple())
saveAllFiles(outputs)