biomedisa 2024.5.19__py3-none-any.whl → 2024.5.20__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- biomedisa/__init__.py +2 -6
- biomedisa/deeplearning.py +10 -12
- biomedisa/{biomedisa_features → features}/DataGenerator.py +1 -1
- biomedisa/{biomedisa_features → features}/DataGeneratorCrop.py +1 -1
- biomedisa/{biomedisa_features → features}/PredictDataGenerator.py +1 -1
- biomedisa/{biomedisa_features → features}/PredictDataGeneratorCrop.py +1 -1
- biomedisa/{biomedisa_features → features}/active_contour.py +15 -18
- biomedisa/{biomedisa_features → features}/assd.py +1 -1
- biomedisa/{biomedisa_features → features}/biomedisa_helper.py +7 -7
- biomedisa/{biomedisa_features → features}/create_slices.py +2 -4
- biomedisa/{biomedisa_features → features}/crop_helper.py +5 -5
- biomedisa/{biomedisa_features → features}/curvop_numba.py +1 -1
- biomedisa/{biomedisa_features → features}/django_env.py +9 -10
- biomedisa/{biomedisa_features → features}/keras_helper.py +6 -7
- biomedisa/{biomedisa_features → features}/nc_reader.py +1 -1
- biomedisa/{biomedisa_features → features}/pid.py +2 -2
- biomedisa/{biomedisa_features → features}/process_image.py +12 -14
- biomedisa/{biomedisa_features → features}/pycuda_test.py +2 -1
- biomedisa/{biomedisa_features → features}/random_walk/gpu_kernels.py +2 -1
- biomedisa/{biomedisa_features → features}/random_walk/pycuda_large.py +2 -2
- biomedisa/{biomedisa_features → features}/random_walk/pycuda_large_allx.py +2 -2
- biomedisa/{biomedisa_features → features}/random_walk/pycuda_small.py +2 -2
- biomedisa/{biomedisa_features → features}/random_walk/pycuda_small_allx.py +2 -2
- biomedisa/{biomedisa_features → features}/random_walk/pyopencl_large.py +1 -1
- biomedisa/{biomedisa_features → features}/random_walk/pyopencl_small.py +1 -1
- biomedisa/{biomedisa_features → features}/random_walk/rw_large.py +11 -11
- biomedisa/{biomedisa_features → features}/random_walk/rw_small.py +12 -12
- biomedisa/{biomedisa_features → features}/remove_outlier.py +13 -16
- biomedisa/features/split_volume.py +167 -0
- biomedisa/interpolation.py +10 -12
- biomedisa/mesh.py +9 -12
- {biomedisa-2024.5.19.dist-info → biomedisa-2024.5.20.dist-info}/METADATA +10 -10
- biomedisa-2024.5.20.dist-info/RECORD +44 -0
- biomedisa/biomedisa_features/split_volume.py +0 -274
- biomedisa-2024.5.19.dist-info/RECORD +0 -44
- /biomedisa/{biomedisa_features → features}/__init__.py +0 -0
- /biomedisa/{biomedisa_features → features}/amira_to_np/__init__.py +0 -0
- /biomedisa/{biomedisa_features → features}/amira_to_np/amira_data_stream.py +0 -0
- /biomedisa/{biomedisa_features → features}/amira_to_np/amira_grammar.py +0 -0
- /biomedisa/{biomedisa_features → features}/amira_to_np/amira_header.py +0 -0
- /biomedisa/{biomedisa_features → features}/amira_to_np/amira_helper.py +0 -0
- /biomedisa/{biomedisa_features → features}/random_walk/__init__.py +0 -0
- {biomedisa-2024.5.19.dist-info → biomedisa-2024.5.20.dist-info}/LICENSE +0 -0
- {biomedisa-2024.5.19.dist-info → biomedisa-2024.5.20.dist-info}/WHEEL +0 -0
- {biomedisa-2024.5.19.dist-info → biomedisa-2024.5.20.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
##########################################################################
|
2
2
|
## ##
|
3
|
-
## Copyright (c) 2024 Philipp Lösel. All rights reserved.
|
3
|
+
## Copyright (c) 2019-2024 Philipp Lösel. All rights reserved. ##
|
4
4
|
## ##
|
5
5
|
## This file is part of the open source project biomedisa. ##
|
6
6
|
## ##
|
@@ -1,6 +1,6 @@
|
|
1
1
|
##########################################################################
|
2
2
|
## ##
|
3
|
-
## Copyright (c)
|
3
|
+
## Copyright (c) 2019-2024 Philipp Lösel. All rights reserved. ##
|
4
4
|
## ##
|
5
5
|
## This file is part of the open source project biomedisa. ##
|
6
6
|
## ##
|
@@ -1,6 +1,6 @@
|
|
1
1
|
##########################################################################
|
2
2
|
## ##
|
3
|
-
## Copyright (c) 2024 Philipp Lösel. All rights reserved.
|
3
|
+
## Copyright (c) 2019-2024 Philipp Lösel. All rights reserved. ##
|
4
4
|
## ##
|
5
5
|
## This file is part of the open source project biomedisa. ##
|
6
6
|
## ##
|
@@ -26,9 +26,9 @@
|
|
26
26
|
## ##
|
27
27
|
##########################################################################
|
28
28
|
|
29
|
-
from
|
30
|
-
from
|
31
|
-
from
|
29
|
+
from biomedisa.features.remove_outlier import clean, fill
|
30
|
+
from biomedisa.features.active_contour import activeContour
|
31
|
+
from biomedisa.features.biomedisa_helper import (_get_device, save_data, _error_, unique_file_path,
|
32
32
|
splitlargedata, read_labeled_slices_allx_large, read_labeled_slices_large, sendToChildLarge,
|
33
33
|
Dice_score)
|
34
34
|
from mpi4py import MPI
|
@@ -135,12 +135,12 @@ def _diffusion_child(comm, bm=None):
|
|
135
135
|
dev = cuda.Device(rank)
|
136
136
|
ctx, queue = dev.make_context(), None
|
137
137
|
if bm.allaxis:
|
138
|
-
from
|
138
|
+
from biomedisa.features.random_walk.pycuda_large_allx import walk
|
139
139
|
else:
|
140
|
-
from
|
140
|
+
from biomedisa.features.random_walk.pycuda_large import walk
|
141
141
|
else:
|
142
142
|
ctx, queue = _get_device(bm.platform, rank)
|
143
|
-
from
|
143
|
+
from biomedisa.features.random_walk.pyopencl_large import walk
|
144
144
|
|
145
145
|
# run random walks
|
146
146
|
tic = time.time()
|
@@ -279,7 +279,7 @@ def _diffusion_child(comm, bm=None):
|
|
279
279
|
# post processing
|
280
280
|
if bm.django_env:
|
281
281
|
from biomedisa_app.config import config
|
282
|
-
from
|
282
|
+
from biomedisa.features.django_env import post_processing
|
283
283
|
post_processing(bm.path_to_final, time_str, config['SERVER_ALIAS'], bm.remote, bm.queue,
|
284
284
|
dice=dice, uncertainty=bm.uncertainty, smooth=bm.smooth,
|
285
285
|
path_to_uq=bm.path_to_uq, path_to_smooth=bm.path_to_smooth,
|
@@ -341,12 +341,12 @@ def _diffusion_child(comm, bm=None):
|
|
341
341
|
dev = cuda.Device(rank % cuda.Device.count())
|
342
342
|
ctx, queue = dev.make_context(), None
|
343
343
|
if allx:
|
344
|
-
from
|
344
|
+
from biomedisa.features.random_walk.pycuda_large_allx import walk
|
345
345
|
else:
|
346
|
-
from
|
346
|
+
from biomedisa.features.random_walk.pycuda_large import walk
|
347
347
|
else:
|
348
348
|
ctx, queue = _get_device(platform, rank)
|
349
|
-
from
|
349
|
+
from biomedisa.features.random_walk.pyopencl_large import walk
|
350
350
|
|
351
351
|
# run random walks
|
352
352
|
tic = time.time()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
##########################################################################
|
2
2
|
## ##
|
3
|
-
## Copyright (c) 2024 Philipp Lösel. All rights reserved.
|
3
|
+
## Copyright (c) 2019-2024 Philipp Lösel. All rights reserved. ##
|
4
4
|
## ##
|
5
5
|
## This file is part of the open source project biomedisa. ##
|
6
6
|
## ##
|
@@ -26,9 +26,9 @@
|
|
26
26
|
## ##
|
27
27
|
##########################################################################
|
28
28
|
|
29
|
-
from
|
30
|
-
from
|
31
|
-
from
|
29
|
+
from biomedisa.features.remove_outlier import clean, fill
|
30
|
+
from biomedisa.features.active_contour import activeContour
|
31
|
+
from biomedisa.features.biomedisa_helper import (_get_device, save_data, unique_file_path,
|
32
32
|
sendToChild, _split_indices, get_labels, Dice_score)
|
33
33
|
from mpi4py import MPI
|
34
34
|
import numpy as np
|
@@ -63,18 +63,18 @@ def _diffusion_child(comm, bm=None):
|
|
63
63
|
if bm.platform == 'cuda':
|
64
64
|
import pycuda.driver as cuda
|
65
65
|
import pycuda.gpuarray as gpuarray
|
66
|
-
from
|
66
|
+
from biomedisa.features.random_walk.gpu_kernels import (_build_kernel_uncertainty,
|
67
67
|
_build_kernel_max, _build_update_gpu, _build_curvature_gpu)
|
68
68
|
cuda.init()
|
69
69
|
dev = cuda.Device(rank)
|
70
70
|
ctx, queue = dev.make_context(), None
|
71
71
|
if bm.allaxis:
|
72
|
-
from
|
72
|
+
from biomedisa.features.random_walk.pycuda_small_allx import walk
|
73
73
|
else:
|
74
|
-
from
|
74
|
+
from biomedisa.features.random_walk.pycuda_small import walk
|
75
75
|
else:
|
76
76
|
ctx, queue = _get_device(bm.platform, rank)
|
77
|
-
from
|
77
|
+
from biomedisa.features.random_walk.pyopencl_small import walk
|
78
78
|
|
79
79
|
# run random walks
|
80
80
|
tic = time.time()
|
@@ -238,7 +238,7 @@ def _diffusion_child(comm, bm=None):
|
|
238
238
|
# post processing
|
239
239
|
if bm.django_env:
|
240
240
|
from biomedisa_app.config import config
|
241
|
-
from
|
241
|
+
from biomedisa.features.django_env import post_processing
|
242
242
|
post_processing(bm.path_to_final, time_str, config['SERVER_ALIAS'], bm.remote, bm.queue,
|
243
243
|
dice=dice, uncertainty=bm.uncertainty, smooth=bm.smooth,
|
244
244
|
path_to_uq=bm.path_to_uq, path_to_smooth=bm.path_to_smooth,
|
@@ -281,12 +281,12 @@ def _diffusion_child(comm, bm=None):
|
|
281
281
|
dev = cuda.Device(rank % cuda.Device.count())
|
282
282
|
ctx, queue = dev.make_context(), None
|
283
283
|
if allx:
|
284
|
-
from
|
284
|
+
from biomedisa.features.random_walk.pycuda_small_allx import walk
|
285
285
|
else:
|
286
|
-
from
|
286
|
+
from biomedisa.features.random_walk.pycuda_small import walk
|
287
287
|
else:
|
288
288
|
ctx, queue = _get_device(platform, rank)
|
289
|
-
from
|
289
|
+
from biomedisa.features.random_walk.pyopencl_small import walk
|
290
290
|
|
291
291
|
# run random walks
|
292
292
|
tic = time.time()
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/python3
|
2
2
|
##########################################################################
|
3
3
|
## ##
|
4
|
-
## Copyright (c) 2024 Philipp Lösel. All rights reserved.
|
4
|
+
## Copyright (c) 2019-2024 Philipp Lösel. All rights reserved. ##
|
5
5
|
## ##
|
6
6
|
## This file is part of the open source project biomedisa. ##
|
7
7
|
## ##
|
@@ -27,12 +27,9 @@
|
|
27
27
|
## ##
|
28
28
|
##########################################################################
|
29
29
|
|
30
|
-
import
|
31
|
-
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
32
|
-
if not BASE_DIR in sys.path:
|
33
|
-
sys.path.append(BASE_DIR)
|
30
|
+
import os
|
34
31
|
import biomedisa
|
35
|
-
from
|
32
|
+
from biomedisa.features.biomedisa_helper import (load_data, save_data,
|
36
33
|
unique_file_path, silent_remove)
|
37
34
|
import numpy as np
|
38
35
|
from scipy import ndimage
|
@@ -195,13 +192,13 @@ def main_helper(path_to_labels, img_id=None, friend_id=None, fill_holes=True,
|
|
195
192
|
|
196
193
|
def post_processing(path_to_cleaned, path_to_filled, path_to_cleaned_filled, img_id=None, friend_id=None, fill_holes=False, remote=False):
|
197
194
|
if remote:
|
198
|
-
with open(BASE_DIR + '/log/config_6', 'w') as configfile:
|
195
|
+
with open(biomedisa.BASE_DIR + '/log/config_6', 'w') as configfile:
|
199
196
|
print(path_to_cleaned, path_to_filled, path_to_cleaned_filled, file=configfile)
|
200
197
|
else:
|
201
198
|
import django
|
202
199
|
django.setup()
|
203
200
|
from biomedisa_app.models import Upload
|
204
|
-
from
|
201
|
+
from biomedisa.features.create_slices import create_slices
|
205
202
|
from redis import Redis
|
206
203
|
from rq import Queue
|
207
204
|
|
@@ -279,7 +276,7 @@ def init_remove_outlier(image_id, final_id, label_id, fill_holes=True):
|
|
279
276
|
|
280
277
|
# get host information
|
281
278
|
host = ''
|
282
|
-
host_base = BASE_DIR
|
279
|
+
host_base = biomedisa.BASE_DIR
|
283
280
|
subhost, qsub_pid = None, None
|
284
281
|
if 'REMOTE_QUEUE_HOST' in config:
|
285
282
|
host = config['REMOTE_QUEUE_HOST']
|
@@ -292,7 +289,7 @@ def init_remove_outlier(image_id, final_id, label_id, fill_holes=True):
|
|
292
289
|
if host:
|
293
290
|
|
294
291
|
# command
|
295
|
-
cmd = ['python3', host_base+'/
|
292
|
+
cmd = ['python3', host_base+'/biomedisa/features/remove_outlier.py', final.pic.path.replace(biomedisa.BASE_DIR,host_base)]
|
296
293
|
cmd += [f'-iid={image.id}', f'-fid={final.friend}', '-r']
|
297
294
|
|
298
295
|
# command (append only on demand)
|
@@ -309,7 +306,7 @@ def init_remove_outlier(image_id, final_id, label_id, fill_holes=True):
|
|
309
306
|
subprocess.Popen(['ssh', host, 'mkdir', '-p', host_base+'/private_storage/images/'+image.user.username]).wait()
|
310
307
|
|
311
308
|
# send data to host
|
312
|
-
success = send_data_to_host(final.pic.path, host+':'+final.pic.path.replace(BASE_DIR,host_base))
|
309
|
+
success = send_data_to_host(final.pic.path, host+':'+final.pic.path.replace(biomedisa.BASE_DIR,host_base))
|
313
310
|
|
314
311
|
if success==0:
|
315
312
|
|
@@ -325,16 +322,16 @@ def init_remove_outlier(image_id, final_id, label_id, fill_holes=True):
|
|
325
322
|
subprocess.Popen(cmd).wait()
|
326
323
|
|
327
324
|
# config
|
328
|
-
success = subprocess.Popen(['scp', host+':'+host_base+'/log/config_6', BASE_DIR+'/log/config_6']).wait()
|
325
|
+
success = subprocess.Popen(['scp', host+':'+host_base+'/log/config_6', biomedisa.BASE_DIR+'/log/config_6']).wait()
|
329
326
|
|
330
327
|
if success==0:
|
331
|
-
with open(BASE_DIR + '/log/config_6', 'r') as configfile:
|
328
|
+
with open(biomedisa.BASE_DIR + '/log/config_6', 'r') as configfile:
|
332
329
|
cleaned_on_host, filled_on_host, cleaned_filled_on_host = configfile.read().split()
|
333
330
|
|
334
331
|
# local file names
|
335
|
-
path_to_cleaned = unique_file_path(cleaned_on_host.replace(host_base,BASE_DIR))
|
336
|
-
path_to_filled = unique_file_path(filled_on_host.replace(host_base,BASE_DIR))
|
337
|
-
path_to_cleaned_filled = unique_file_path(cleaned_filled_on_host.replace(host_base,BASE_DIR))
|
332
|
+
path_to_cleaned = unique_file_path(cleaned_on_host.replace(host_base,biomedisa.BASE_DIR))
|
333
|
+
path_to_filled = unique_file_path(filled_on_host.replace(host_base,biomedisa.BASE_DIR))
|
334
|
+
path_to_cleaned_filled = unique_file_path(cleaned_filled_on_host.replace(host_base,biomedisa.BASE_DIR))
|
338
335
|
|
339
336
|
# get results
|
340
337
|
subprocess.Popen(['scp', host+':'+cleaned_on_host, path_to_cleaned]).wait()
|
@@ -0,0 +1,167 @@
|
|
1
|
+
##########################################################################
|
2
|
+
## ##
|
3
|
+
## Copyright (c) 2019-2024 Philipp Lösel. All rights reserved. ##
|
4
|
+
## ##
|
5
|
+
## This file is part of the open source project biomedisa. ##
|
6
|
+
## ##
|
7
|
+
## Licensed under the European Union Public Licence (EUPL) ##
|
8
|
+
## v1.2, or - as soon as they will be approved by the ##
|
9
|
+
## European Commission - subsequent versions of the EUPL; ##
|
10
|
+
## ##
|
11
|
+
## You may redistribute it and/or modify it under the terms ##
|
12
|
+
## of the EUPL v1.2. You may not use this work except in ##
|
13
|
+
## compliance with this Licence. ##
|
14
|
+
## ##
|
15
|
+
## You can obtain a copy of the Licence at: ##
|
16
|
+
## ##
|
17
|
+
## https://joinup.ec.europa.eu/page/eupl-text-11-12 ##
|
18
|
+
## ##
|
19
|
+
## Unless required by applicable law or agreed to in ##
|
20
|
+
## writing, software distributed under the Licence is ##
|
21
|
+
## distributed on an "AS IS" basis, WITHOUT WARRANTIES ##
|
22
|
+
## OR CONDITIONS OF ANY KIND, either express or implied. ##
|
23
|
+
## ##
|
24
|
+
## See the Licence for the specific language governing ##
|
25
|
+
## permissions and limitations under the Licence. ##
|
26
|
+
## ##
|
27
|
+
##########################################################################
|
28
|
+
|
29
|
+
import os
|
30
|
+
from biomedisa.features.biomedisa_helper import load_data, save_data
|
31
|
+
from biomedisa.features.interpolation import smart_interpolation
|
32
|
+
from tifffile import imread, imwrite, TiffFile
|
33
|
+
import numpy as np
|
34
|
+
import argparse
|
35
|
+
|
36
|
+
if __name__ == '__main__':
|
37
|
+
|
38
|
+
# initialize arguments
|
39
|
+
parser = argparse.ArgumentParser(description='Biomedisa interpolation.',
|
40
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
41
|
+
|
42
|
+
# required arguments
|
43
|
+
parser.add_argument('path_to_data', type=str, metavar='PATH_TO_IMAGE',
|
44
|
+
help='Location of image data')
|
45
|
+
parser.add_argument('path_to_labels', type=str, metavar='PATH_TO_LABELS',
|
46
|
+
help='Location of label data')
|
47
|
+
|
48
|
+
# optional arguments
|
49
|
+
parser.add_argument('-allx', '--allaxis', action='store_true', default=False,
|
50
|
+
help='If pre-segmentation is not exlusively in xy-plane')
|
51
|
+
parser.add_argument('-u', '--uncertainty', action='store_true', default=False,
|
52
|
+
help='Return uncertainty of segmentation result')
|
53
|
+
parser.add_argument('-s', '--smooth', nargs='?', type=int, const=100, default=0,
|
54
|
+
help='Number of smoothing iterations for segmentation result')
|
55
|
+
parser.add_argument('-ol', '--overlap', type=int, default=50,
|
56
|
+
help='Overlap of sub-blocks')
|
57
|
+
parser.add_argument('-sx','--split_x', type=int, default=1,
|
58
|
+
help='Number of sub-blocks in x-direction')
|
59
|
+
parser.add_argument('-sy','--split_y', type=int, default=1,
|
60
|
+
help='Number of sub-blocks in y-direction')
|
61
|
+
parser.add_argument('-sz','--split_z', type=int, default=1,
|
62
|
+
help='Number of sub-blocks in z-direction')
|
63
|
+
args = parser.parse_args()
|
64
|
+
|
65
|
+
# image size
|
66
|
+
if args.path_to_data[-4:] == '.tif':
|
67
|
+
tif = TiffFile(args.path_to_data)
|
68
|
+
zsh = len(tif.pages)
|
69
|
+
ysh, xsh = tif.pages[0].shape
|
70
|
+
else:
|
71
|
+
print('Warning: This script is optimized for TIFF files. Please consider saving your data in TIFF format.')
|
72
|
+
data, _ = load_data(args.path_to_data)
|
73
|
+
shape = np.array(data.shape).copy()
|
74
|
+
zsh, ysh, xsh = shape
|
75
|
+
del data
|
76
|
+
|
77
|
+
if args.path_to_labels[-4:] != '.tif':
|
78
|
+
print('Warning: This script is optimized for TIFF files. Please consider saving your labels in TIFF format.')
|
79
|
+
|
80
|
+
# split volume
|
81
|
+
sub_size_z = np.ceil(zsh / args.split_z)
|
82
|
+
sub_size_y = np.ceil(ysh / args.split_y)
|
83
|
+
sub_size_x = np.ceil(xsh / args.split_x)
|
84
|
+
|
85
|
+
# allocate memory
|
86
|
+
final = np.zeros((zsh, ysh, xsh), dtype=np.uint8)
|
87
|
+
if args.smooth:
|
88
|
+
final_smooth = np.zeros_like(final)
|
89
|
+
if args.uncertainty:
|
90
|
+
final_uncertainty = np.zeros_like(final)
|
91
|
+
|
92
|
+
# iterate over subvolumes
|
93
|
+
for z_i in range(args.split_z):
|
94
|
+
for y_i in range(args.split_y):
|
95
|
+
for x_i in range(args.split_x):
|
96
|
+
subvolume = z_i * args.split_y * args.split_x + y_i * args.split_x + x_i + 1
|
97
|
+
print('Subvolume:', subvolume, '/', args.split_z * args.split_y * args.split_x)
|
98
|
+
|
99
|
+
# determine z subvolume
|
100
|
+
blockmin_z = int(z_i * sub_size_z)
|
101
|
+
blockmax_z = int((z_i+1) * sub_size_z)
|
102
|
+
datamin_z = max(blockmin_z - args.overlap, 0)
|
103
|
+
datamax_z = min(blockmax_z + args.overlap, zsh)
|
104
|
+
|
105
|
+
# determine y subvolume
|
106
|
+
blockmin_y = int(y_i * sub_size_y)
|
107
|
+
blockmax_y = int((y_i+1) * sub_size_y)
|
108
|
+
datamin_y = max(blockmin_y - args.overlap, 0)
|
109
|
+
datamax_y = min(blockmax_y + args.overlap, ysh)
|
110
|
+
|
111
|
+
# determine x subvolume
|
112
|
+
blockmin_x = int(x_i * sub_size_x)
|
113
|
+
blockmax_x = int((x_i+1) * sub_size_x)
|
114
|
+
datamin_x = max(blockmin_x - args.overlap, 0)
|
115
|
+
datamax_x = min(blockmax_x + args.overlap, xsh)
|
116
|
+
|
117
|
+
# extract image subvolume
|
118
|
+
if args.path_to_data[-4:] == '.tif':
|
119
|
+
data = imread(args.path_to_data, key=range(datamin_z,datamax_z))
|
120
|
+
data = data[:,datamin_y:datamax_y,datamin_x:datamax_x].copy()
|
121
|
+
else:
|
122
|
+
data, _ = load_data(args.path_to_data)
|
123
|
+
data = data[datamin_z:datamax_z,datamin_y:datamax_y,datamin_x:datamax_x].copy()
|
124
|
+
|
125
|
+
# extract label subvolume
|
126
|
+
if args.path_to_labels[-4:] == '.tif':
|
127
|
+
header, final_image_type = None, '.tif'
|
128
|
+
labelData = imread(args.path_to_labels, key=range(datamin_z,datamax_z))
|
129
|
+
labelData = labelData[:,datamin_y:datamax_y,datamin_x:datamax_x].copy()
|
130
|
+
else:
|
131
|
+
labelData, header, final_image_type = load_data(args.path_to_labels, return_extension=True)
|
132
|
+
labelData = labelData[datamin_z:datamax_z,datamin_y:datamax_y,datamin_x:datamax_x].copy()
|
133
|
+
|
134
|
+
# interpolation
|
135
|
+
results = smart_interpolation(data, labelData, uncertainty=args.uncertainty, allaxis=args.allaxis, smooth=args.smooth)
|
136
|
+
|
137
|
+
# append results
|
138
|
+
final[blockmin_z:blockmax_z,blockmin_y:blockmax_y,blockmin_x:blockmax_x] \
|
139
|
+
= results['regular'][blockmin_z-datamin_z:blockmax_z-datamin_z,blockmin_y-datamin_y:blockmax_y-datamin_y,blockmin_x-datamin_x:blockmax_x-datamin_x]
|
140
|
+
if 'smooth' in results and results['smooth'] is not None:
|
141
|
+
final_smooth[blockmin_z:blockmax_z,blockmin_y:blockmax_y,blockmin_x:blockmax_x] \
|
142
|
+
= results['smooth'][blockmin_z-datamin_z:blockmax_z-datamin_z,blockmin_y-datamin_y:blockmax_y-datamin_y,blockmin_x-datamin_x:blockmax_x-datamin_x]
|
143
|
+
if 'uncertainty' in results and results['uncertainty'] is not None:
|
144
|
+
final_uncertainty[blockmin_z:blockmax_z,blockmin_y:blockmax_y,blockmin_x:blockmax_x] \
|
145
|
+
= results['uncertainty'][blockmin_z-datamin_z:blockmax_z-datamin_z,blockmin_y-datamin_y:blockmax_y-datamin_y,blockmin_x-datamin_x:blockmax_x-datamin_x]
|
146
|
+
|
147
|
+
# path to regular result
|
148
|
+
filename, extension = os.path.splitext(os.path.basename(args.path_to_data))
|
149
|
+
if extension == '.gz':
|
150
|
+
filename = filename[:-4]
|
151
|
+
filename = 'final.' + filename
|
152
|
+
path_to_final = args.path_to_data.replace(os.path.basename(args.path_to_data), filename + final_image_type)
|
153
|
+
|
154
|
+
# path to optional results
|
155
|
+
filename, extension = os.path.splitext(path_to_final)
|
156
|
+
if extension == '.gz':
|
157
|
+
filename = filename[:-4]
|
158
|
+
path_to_smooth = filename + '.smooth' + final_image_type
|
159
|
+
path_to_uq = filename + '.uncertainty.tif'
|
160
|
+
|
161
|
+
# save results
|
162
|
+
save_data(path_to_final, final, header)
|
163
|
+
if args.smooth:
|
164
|
+
save_data(path_to_smooth, final_smooth, header)
|
165
|
+
if args.uncertainty:
|
166
|
+
imwrite(path_to_uq, final_uncertainty)
|
167
|
+
|
biomedisa/interpolation.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/python3
|
2
2
|
##########################################################################
|
3
3
|
## ##
|
4
|
-
## Copyright (c) 2024 Philipp Lösel. All rights reserved.
|
4
|
+
## Copyright (c) 2019-2024 Philipp Lösel. All rights reserved. ##
|
5
5
|
## ##
|
6
6
|
## This file is part of the open source project biomedisa. ##
|
7
7
|
## ##
|
@@ -27,11 +27,9 @@
|
|
27
27
|
## ##
|
28
28
|
##########################################################################
|
29
29
|
|
30
|
-
import
|
31
|
-
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
32
|
-
sys.path.append(BASE_DIR)
|
30
|
+
import os
|
33
31
|
import biomedisa
|
34
|
-
from
|
32
|
+
from biomedisa.features.biomedisa_helper import (_get_platform, smooth_img_3x3,
|
35
33
|
pre_processing, _error_, read_labeled_slices, read_labeled_slices_allx,
|
36
34
|
read_indices_allx, predict_blocksize)
|
37
35
|
from multiprocessing import freeze_support
|
@@ -88,14 +86,14 @@ def smart_interpolation(data, labelData, nbrw=10, sorw=4000, acwe=False, acwe_al
|
|
88
86
|
|
89
87
|
# set pid and write in logfile
|
90
88
|
if bm.django_env:
|
91
|
-
from
|
89
|
+
from biomedisa.features.django_env import create_pid_object
|
92
90
|
create_pid_object(os.getpid(), bm.remote, bm.queue, bm.img_id)
|
93
91
|
|
94
92
|
# write in logfile
|
95
93
|
bm.username = os.path.basename(os.path.dirname(bm.path_to_data))
|
96
94
|
bm.shortfilename = os.path.basename(bm.path_to_data)
|
97
|
-
bm.path_to_logfile = BASE_DIR + '/log/logfile.txt'
|
98
|
-
bm.path_to_time = BASE_DIR + '/log/time.txt'
|
95
|
+
bm.path_to_logfile = biomedisa.BASE_DIR + '/log/logfile.txt'
|
96
|
+
bm.path_to_time = biomedisa.BASE_DIR + '/log/time.txt'
|
99
97
|
with open(bm.path_to_logfile, 'a') as logfile:
|
100
98
|
print('%s %s %s %s' %(time.ctime(), bm.username, bm.shortfilename, 'Process was started.'), file=logfile)
|
101
99
|
|
@@ -256,7 +254,7 @@ def smart_interpolation(data, labelData, nbrw=10, sorw=4000, acwe=False, acwe_al
|
|
256
254
|
# create subcommunicator
|
257
255
|
sub_comm = MPI.Comm.Split(comm, 1, rank)
|
258
256
|
|
259
|
-
from
|
257
|
+
from biomedisa.features.random_walk.rw_small import _diffusion_child
|
260
258
|
results = _diffusion_child(sub_comm, bm)
|
261
259
|
|
262
260
|
else:
|
@@ -276,7 +274,7 @@ def smart_interpolation(data, labelData, nbrw=10, sorw=4000, acwe=False, acwe_al
|
|
276
274
|
# create subcommunicator
|
277
275
|
sub_comm = MPI.Comm.Split(comm, 1, rank)
|
278
276
|
|
279
|
-
from
|
277
|
+
from biomedisa.features.random_walk.rw_large import _diffusion_child
|
280
278
|
results = _diffusion_child(sub_comm, bm)
|
281
279
|
|
282
280
|
return results
|
@@ -301,10 +299,10 @@ def smart_interpolation(data, labelData, nbrw=10, sorw=4000, acwe=False, acwe_al
|
|
301
299
|
sub_comm = MPI.Comm.Split(comm, 1, rank)
|
302
300
|
|
303
301
|
if small:
|
304
|
-
from
|
302
|
+
from biomedisa.features.random_walk.rw_small import _diffusion_child
|
305
303
|
_diffusion_child(sub_comm)
|
306
304
|
else:
|
307
|
-
from
|
305
|
+
from biomedisa.features.random_walk.rw_large import _diffusion_child
|
308
306
|
_diffusion_child(sub_comm)
|
309
307
|
|
310
308
|
if __name__ == '__main__':
|
biomedisa/mesh.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/python3
|
2
2
|
##########################################################################
|
3
3
|
## ##
|
4
|
-
## Copyright (c) 2024 Philipp Lösel. All rights reserved.
|
4
|
+
## Copyright (c) 2019-2024 Philipp Lösel. All rights reserved. ##
|
5
5
|
## ##
|
6
6
|
## This file is part of the open source project biomedisa. ##
|
7
7
|
## ##
|
@@ -27,13 +27,10 @@
|
|
27
27
|
## ##
|
28
28
|
##########################################################################
|
29
29
|
|
30
|
-
import os
|
31
|
-
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
32
|
-
if not BASE_DIR in sys.path:
|
33
|
-
sys.path.append(BASE_DIR)
|
30
|
+
import os
|
34
31
|
import numpy as np
|
35
|
-
from
|
36
|
-
from
|
32
|
+
from biomedisa.features.biomedisa_helper import load_data, unique_file_path
|
33
|
+
from biomedisa.features.django_env import create_pid_object
|
37
34
|
from vtk.util.numpy_support import vtk_to_numpy, numpy_to_vtk
|
38
35
|
from stl import mesh
|
39
36
|
import vtk
|
@@ -228,7 +225,7 @@ def init_create_mesh(id):
|
|
228
225
|
|
229
226
|
# get host information
|
230
227
|
host = ''
|
231
|
-
host_base = BASE_DIR
|
228
|
+
host_base = biomedisa.BASE_DIR
|
232
229
|
subhost, qsub_pid = None, None
|
233
230
|
if 'REMOTE_QUEUE_HOST' in config:
|
234
231
|
host = config['REMOTE_QUEUE_HOST']
|
@@ -261,14 +258,14 @@ def init_create_mesh(id):
|
|
261
258
|
if host:
|
262
259
|
|
263
260
|
# command
|
264
|
-
cmd = ['python3', host_base+'/
|
261
|
+
cmd = ['python3', host_base+'/biomedisa/mesh.py', img.pic.path.replace(biomedisa.BASE_DIR,host_base)]
|
265
262
|
cmd += [f'-iid={img.id}', '-r']
|
266
263
|
|
267
264
|
# create user directory
|
268
265
|
subprocess.Popen(['ssh', host, 'mkdir', '-p', host_base+'/private_storage/images/'+img.user.username]).wait()
|
269
266
|
|
270
267
|
# send data to host
|
271
|
-
success = send_data_to_host(img.pic.path, host+':'+img.pic.path.replace(BASE_DIR,host_base))
|
268
|
+
success = send_data_to_host(img.pic.path, host+':'+img.pic.path.replace(biomedisa.BASE_DIR,host_base))
|
272
269
|
|
273
270
|
# qsub start
|
274
271
|
if 'REMOTE_QUEUE_QSUB' in config and config['REMOTE_QUEUE_QSUB']:
|
@@ -291,14 +288,14 @@ def init_create_mesh(id):
|
|
291
288
|
subprocess.Popen(cmd).wait()
|
292
289
|
|
293
290
|
# check if aborted
|
294
|
-
success = subprocess.Popen(['scp', host+':'+host_base+f'/log/pid_7', BASE_DIR+f'/log/pid_7']).wait()
|
291
|
+
success = subprocess.Popen(['scp', host+':'+host_base+f'/log/pid_7', biomedisa.BASE_DIR+f'/log/pid_7']).wait()
|
295
292
|
|
296
293
|
# get result
|
297
294
|
if success==0:
|
298
295
|
# remove pid file
|
299
296
|
subprocess.Popen(['ssh', host, 'rm', host_base+f'/log/pid_7']).wait()
|
300
297
|
|
301
|
-
result_on_host = img.pic.path.replace(BASE_DIR,host_base)
|
298
|
+
result_on_host = img.pic.path.replace(biomedisa.BASE_DIR,host_base)
|
302
299
|
result_on_host = result_on_host.replace(os.path.splitext(result_on_host)[1],'.stl')
|
303
300
|
success = subprocess.Popen(['scp', host+':'+result_on_host, path_to_result]).wait()
|
304
301
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: biomedisa
|
3
|
-
Version: 2024.5.
|
3
|
+
Version: 2024.5.20
|
4
4
|
Summary: Segmentation of 3D volumetric image data
|
5
5
|
Author: Philipp Lösel
|
6
6
|
Author-email: philipp.loesel@anu.edu.au
|
@@ -14,7 +14,7 @@ Requires-Python: >=3.8
|
|
14
14
|
Description-Content-Type: text/markdown
|
15
15
|
License-File: LICENSE
|
16
16
|
|
17
|
-
[](https://biomedisa.info)
|
17
|
+
[](https://biomedisa.info)
|
18
18
|
-----------
|
19
19
|
- [Overview](#overview)
|
20
20
|
- [Hardware Requirements](#hardware-requirements)
|
@@ -55,7 +55,7 @@ Biomedisa (https://biomedisa.info) is a free and easy-to-use open-source applica
|
|
55
55
|
|
56
56
|
#### Python example
|
57
57
|
```python
|
58
|
-
from biomedisa.
|
58
|
+
from biomedisa.features.biomedisa_helper import load_data, save_data
|
59
59
|
from biomedisa.interpolation import smart_interpolation
|
60
60
|
|
61
61
|
# load data
|
@@ -84,7 +84,7 @@ python -m biomedisa.interpolation C:\Users\%USERNAME%\Downloads\tumor.tif C:\Use
|
|
84
84
|
|
85
85
|
#### Python example (training)
|
86
86
|
```python
|
87
|
-
from biomedisa.
|
87
|
+
from biomedisa.features.biomedisa_helper import load_data
|
88
88
|
from biomedisa.deeplearning import deep_learning
|
89
89
|
|
90
90
|
# load image data
|
@@ -124,7 +124,7 @@ If running into ResourceExhaustedError due to out of memory (OOM), try to use sm
|
|
124
124
|
|
125
125
|
#### Python example (prediction)
|
126
126
|
```python
|
127
|
-
from biomedisa.
|
127
|
+
from biomedisa.features.biomedisa_helper import load_data, save_data
|
128
128
|
from biomedisa.deeplearning import deep_learning
|
129
129
|
|
130
130
|
# load data
|
@@ -147,7 +147,7 @@ python -m biomedisa.deeplearning C:\Users\%USERNAME%\Downloads\testing_axial_cro
|
|
147
147
|
|
148
148
|
#### Load and save data (such as Amira Mesh, TIFF, NRRD, NIfTI or DICOM)
|
149
149
|
```python
|
150
|
-
from biomedisa.
|
150
|
+
from biomedisa.features.biomedisa_helper import load_data, save_data
|
151
151
|
|
152
152
|
# load data as numpy array
|
153
153
|
# for DICOM, PNG files, or similar formats, 'path_to_data' must reference
|
@@ -160,7 +160,7 @@ save_data(path_to_data, data, header)
|
|
160
160
|
|
161
161
|
#### Create STL mesh from segmentation (label values are saved as attributes)
|
162
162
|
```python
|
163
|
-
from biomedisa.
|
163
|
+
from biomedisa.features.biomedisa_helper import load_data, save_data
|
164
164
|
from biomedisa.mesh import get_voxel_spacing, save_mesh
|
165
165
|
|
166
166
|
# load segmentation
|
@@ -193,7 +193,7 @@ python -m biomedisa.mesh <path_to_data>
|
|
193
193
|
|
194
194
|
#### Resize data
|
195
195
|
```python
|
196
|
-
from biomedisa.
|
196
|
+
from biomedisa.features.biomedisa_helper import img_resize
|
197
197
|
|
198
198
|
# resize image data
|
199
199
|
zsh, ysh, xsh = data.shape
|
@@ -206,7 +206,7 @@ label_data = img_resize(label_data, new_zsh, new_ysh, new_xsh, labels=True)
|
|
206
206
|
|
207
207
|
#### Remove outliers and fill holes
|
208
208
|
```python
|
209
|
-
from biomedisa.
|
209
|
+
from biomedisa.features.biomedisa_helper import clean, fill
|
210
210
|
|
211
211
|
# delete outliers smaller than 90% of the segment
|
212
212
|
label_data = clean(label_data, 0.9)
|
@@ -217,7 +217,7 @@ label_data = fill(label_data, 0.9)
|
|
217
217
|
|
218
218
|
#### Accuracy assessment
|
219
219
|
```python
|
220
|
-
from biomedisa.
|
220
|
+
from biomedisa.features.biomedisa_helper import Dice_score, ASSD
|
221
221
|
dice = Dice_score(ground_truth, result)
|
222
222
|
assd = ASSD(ground_truth, result)
|
223
223
|
```
|