-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestAPI.py
96 lines (74 loc) · 2.81 KB
/
RestAPI.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import python_codes.unity_functions as uf
<<<<<<< Updated upstream
from flask import Flask, request, jsonify
import napari as npi
import tifffile as tf
import numpy as np
=======
from flask import Flask, request
import napari as npi
import tifffile as tf
import numpy as np
>>>>>>> Stashed changes
app = Flask(__name__)
# img = np.moveaxis(tf.imread(r"/media/ibrahim/Extended Storage/cloud/Internship/shapiro/exemplar-001_Ch1_DAPI.tif"), 0, -1)
# viewer = npi.Viewer(title="Test", show=True)
# viewer.add_image(img[...,None], channel_axis=-1)
# viewer.window._qt_viewer.canvas.show(visible=False, run=False)
tiff = {}
@app.route("/v1")
def hello_world():
return {"Value": "Success"}
@app.route('/v1/tiff_img', methods=['POST', 'GET'])
def get_tiff():
if request.method == "POST":
try:
tiff["img"] = request.json["img"]
tiff["shape"] = request.json["shape"]
tiff["dtype"] = request.json["dtype"] #dtype_string
tiff["channel_sizes"] = request.json["channel_sizes"] # dtype_string
return tiff
except Exception as e:
print("Got a problem: {} \n Caused by: {}".format(e, request.data))
return e
else:
try:
#array, kwargs, shape, dtype_string = uf.fluorescent_channel2rgb(tiff["path"])
#tiff["img"] = img.flatten() #[x.flatten().tolist() for x in array] # Integrity is kept intact
#tiff["metadata"] = kwargs
#print("First array of RGB uint16 image: {}".format(tiff["img"][0][:6]))
return tiff #tiff
except Exception as e:
print("Got a problem here: {}".format(e))
return e
@app.route('/v1/napari_test', methods=['GET'])
def napari2VR():
# if request.method == "POST":
# try:
# if request.json["command"] == "Loadin2VR":
# # Start VR
# # Return IMG
#
#
# return tiff
# except Exception as e:
# print("Got a problem: {} \n Caused by: {}".format(e, request.data))
# return e
try:
img = np.moveaxis(tf.imread(r"C:\Schapiro Lab\ibrahim_hiwi\VRproject\VR Demo dataset\image_34.tif"), 0, -1)
viewer = npi.Viewer(title="Test")
viewer.add_image(img, channel_axis=-1)
viewer.show()
array = viewer.screenshot()
tiff["img"] = array.flatten() # Integrity is kept intact
tiff["shape"] = array.shape[:-1]
tiff["dtype"] = str(array.dtype)
tiff["channels"] = array.shape[-1]
print("First array of RGB uint16 image: {}".format(tiff["img"][0][:6]))
return tiff #tiff
except Exception as e:
print("Got a problem here: {}".format(e))
return e
if __name__ == '__main__':
# run app in debug mode on port 5000
app.run(debug=True, port=5000)