Spaces:
Runtime error
Runtime error
Commit
·
ad868f8
1
Parent(s):
bd24849
patched image normalization
Browse files
app.py
CHANGED
@@ -18,8 +18,6 @@ import numpy as np
|
|
18 |
import PIL
|
19 |
import SimpleITK as sitk
|
20 |
|
21 |
-
MINVAL,MAXVAL = -1000,1000
|
22 |
-
|
23 |
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
24 |
example_image_path = os.path.join(THIS_DIR,'files','promis12-test-Case00.nii.gz') # from promise12
|
25 |
example_mask_path = os.path.join(THIS_DIR,'files','promis12-test-Case00-mask.nii.gz') # from promise12
|
@@ -32,27 +30,26 @@ def load_data(input1,input2):
|
|
32 |
mydict['mask_path'] = input2.name
|
33 |
img = sitk.GetArrayFromImage(sitk.ReadImage(mydict['image_path']))
|
34 |
mask = sitk.GetArrayFromImage(sitk.ReadImage(mydict['mask_path']))
|
35 |
-
|
|
|
36 |
mydict['img'] = img.astype(np.uint8)
|
37 |
mydict['mask'] = mask.astype(np.uint8)
|
38 |
return f"Image and mask files uploaded, move the above slider to trigger rendering of below component."
|
39 |
|
40 |
def render(x, state):
|
41 |
-
print(x,state)
|
42 |
if len(mydict)==4:
|
43 |
if x > mydict['img'].shape[0]-1:
|
44 |
x = mydict['img'].shape[0]-1
|
45 |
if x < 0:
|
46 |
x = 0
|
47 |
-
|
48 |
mask = mydict['mask'][x,:,:]
|
49 |
-
|
50 |
-
value = (im,[(mask,"prostate")])
|
51 |
zmin, zmax = 0,mydict['img'].shape[0]-1
|
52 |
else:
|
53 |
-
|
54 |
zmin, zmax = None, None
|
55 |
-
value = (
|
56 |
|
57 |
return value,f'z-value: {x}, (zmin: {zmin}, zmax: {zmax})'
|
58 |
|
|
|
18 |
import PIL
|
19 |
import SimpleITK as sitk
|
20 |
|
|
|
|
|
21 |
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
22 |
example_image_path = os.path.join(THIS_DIR,'files','promis12-test-Case00.nii.gz') # from promise12
|
23 |
example_mask_path = os.path.join(THIS_DIR,'files','promis12-test-Case00-mask.nii.gz') # from promise12
|
|
|
30 |
mydict['mask_path'] = input2.name
|
31 |
img = sitk.GetArrayFromImage(sitk.ReadImage(mydict['image_path']))
|
32 |
mask = sitk.GetArrayFromImage(sitk.ReadImage(mydict['mask_path']))
|
33 |
+
minval,maxval = np.min(img),np.max(img)
|
34 |
+
img = ((img-minval)/(maxval-minval)).clip(0,1)*255
|
35 |
mydict['img'] = img.astype(np.uint8)
|
36 |
mydict['mask'] = mask.astype(np.uint8)
|
37 |
return f"Image and mask files uploaded, move the above slider to trigger rendering of below component."
|
38 |
|
39 |
def render(x, state):
|
|
|
40 |
if len(mydict)==4:
|
41 |
if x > mydict['img'].shape[0]-1:
|
42 |
x = mydict['img'].shape[0]-1
|
43 |
if x < 0:
|
44 |
x = 0
|
45 |
+
image = mydict['img'][x,:,:]
|
46 |
mask = mydict['mask'][x,:,:]
|
47 |
+
value = (image,[(mask,"prostate")])
|
|
|
48 |
zmin, zmax = 0,mydict['img'].shape[0]-1
|
49 |
else:
|
50 |
+
image = np.zeros(10,10)
|
51 |
zmin, zmax = None, None
|
52 |
+
value = (image,[])
|
53 |
|
54 |
return value,f'z-value: {x}, (zmin: {zmin}, zmax: {zmax})'
|
55 |
|