-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
81 lines (46 loc) · 1.68 KB
/
main.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
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
import json
import os
import time
from tifffile import TiffFile
import numpy as np
import matplotlib.pyplot as plt
from cpuParallelFunctions import makePropertyMap
import build.cudaProcesses as cudaProcesses
###############################################
print("\npython: loading markersLUT")
with open("marker_to_propertyLUT.json","r") as f:
inputLUT=json.load(f)
print("python: loading tiff file")
with TiffFile("V_uint16.tiff") as tif:
V_input=tif.asarray().astype(np.uint32)
sliceForPlot=400
del inputLUT["-1"]
offsetFactor=1e6
inputLUT_python={int(key):int(val*offsetFactor) for key,val in inputLUT.items()}
tic = time.perf_counter()
V_python=makePropertyMap(V_input, inputLUT_python,parallelHandle=True)
V_python=V_python.astype(np.float32)/offsetFactor
toc=time.perf_counter()
time_python=time.strftime("%Mm%Ss", time.gmtime(toc-tic))
inputSlice=V_input[sliceForPlot].copy()
shapeTuple=V_input.shape
V_input=V_input.ravel()
print("\ncalling cudaProcessis.run()")
tic = time.perf_counter()
offsetFactor=cudaProcesses.run(inputLUT,V_input)
toc=time.perf_counter()
time_cuda=time.strftime("%Mm%Ss", time.gmtime(toc-tic))
print("back to python:")
plt.figure(figsize=[8,8],num="inputSlice")
plt.imshow(inputSlice)
V_input=V_input.reshape(shapeTuple)
V_input=V_input/offsetFactor
plt.figure(figsize=[8,8],num="outputSlice_cuda")
plt.imshow(V_input[sliceForPlot])
plt.figure(figsize=[8,8],num="outputSlice_python")
plt.imshow(V_python[sliceForPlot])
plt.figure(figsize=[8,8],num="Error checking: python vs cuda")
plt.imshow(V_python[sliceForPlot]-V_input[sliceForPlot])
print("\n\nExecution time_python : ",time_python)
print( "Execution time_cuda : ",time_cuda)
plt.show()