biomedisa 2024.5.18__tar.gz → 2024.5.20__tar.gz

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.
Files changed (50) hide show
  1. {biomedisa-2024.5.18 → biomedisa-2024.5.20}/PKG-INFO +15 -16
  2. {biomedisa-2024.5.18 → biomedisa-2024.5.20}/README.md +14 -15
  3. {biomedisa-2024.5.18 → biomedisa-2024.5.20}/pyproject.toml +1 -1
  4. {biomedisa-2024.5.18 → biomedisa-2024.5.20}/src/biomedisa/__init__.py +2 -6
  5. {biomedisa-2024.5.18 → biomedisa-2024.5.20}/src/biomedisa/deeplearning.py +88 -91
  6. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/DataGenerator.py +1 -1
  7. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/DataGeneratorCrop.py +1 -1
  8. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/PredictDataGenerator.py +1 -1
  9. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/PredictDataGeneratorCrop.py +1 -1
  10. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/active_contour.py +15 -18
  11. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/assd.py +1 -1
  12. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/biomedisa_helper.py +107 -117
  13. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/create_slices.py +51 -60
  14. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/crop_helper.py +111 -116
  15. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/curvop_numba.py +1 -1
  16. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/django_env.py +9 -10
  17. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/keras_helper.py +143 -170
  18. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/nc_reader.py +1 -1
  19. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/pid.py +2 -2
  20. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/process_image.py +12 -14
  21. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/pycuda_test.py +2 -1
  22. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/random_walk/gpu_kernels.py +2 -1
  23. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/random_walk/pycuda_large.py +2 -2
  24. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/random_walk/pycuda_large_allx.py +2 -2
  25. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/random_walk/pycuda_small.py +2 -2
  26. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/random_walk/pycuda_small_allx.py +2 -2
  27. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/random_walk/pyopencl_large.py +1 -1
  28. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/random_walk/pyopencl_small.py +1 -1
  29. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/random_walk/rw_large.py +11 -11
  30. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/random_walk/rw_small.py +12 -12
  31. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/remove_outlier.py +13 -16
  32. biomedisa-2024.5.20/src/biomedisa/features/split_volume.py +167 -0
  33. {biomedisa-2024.5.18 → biomedisa-2024.5.20}/src/biomedisa/interpolation.py +10 -12
  34. {biomedisa-2024.5.18 → biomedisa-2024.5.20}/src/biomedisa/mesh.py +9 -12
  35. {biomedisa-2024.5.18 → biomedisa-2024.5.20}/src/biomedisa.egg-info/PKG-INFO +15 -16
  36. biomedisa-2024.5.20/src/biomedisa.egg-info/SOURCES.txt +46 -0
  37. biomedisa-2024.5.18/src/biomedisa/biomedisa_features/split_volume.py +0 -274
  38. biomedisa-2024.5.18/src/biomedisa.egg-info/SOURCES.txt +0 -46
  39. {biomedisa-2024.5.18 → biomedisa-2024.5.20}/LICENSE +0 -0
  40. {biomedisa-2024.5.18 → biomedisa-2024.5.20}/setup.cfg +0 -0
  41. {biomedisa-2024.5.18 → biomedisa-2024.5.20}/src/biomedisa/__main__.py +0 -0
  42. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/__init__.py +0 -0
  43. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/amira_to_np/__init__.py +0 -0
  44. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/amira_to_np/amira_data_stream.py +0 -0
  45. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/amira_to_np/amira_grammar.py +0 -0
  46. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/amira_to_np/amira_header.py +0 -0
  47. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/amira_to_np/amira_helper.py +0 -0
  48. {biomedisa-2024.5.18/src/biomedisa/biomedisa_features → biomedisa-2024.5.20/src/biomedisa/features}/random_walk/__init__.py +0 -0
  49. {biomedisa-2024.5.18 → biomedisa-2024.5.20}/src/biomedisa.egg-info/dependency_links.txt +0 -0
  50. {biomedisa-2024.5.18 → biomedisa-2024.5.20}/src/biomedisa.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: biomedisa
3
- Version: 2024.5.18
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
- [![biomedisa](biomedisa_app/static/biomedisa_logo.svg)](https://biomedisa.info)
17
+ [![biomedisa](https://raw.githubusercontent.com/biomedisa/biomedisa/master/biomedisa_app/static/biomedisa_logo.svg)](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.biomedisa_features.biomedisa_helper import load_data, save_data
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.biomedisa_features.biomedisa_helper import load_data
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.biomedisa_features.biomedisa_helper import load_data, save_data
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
@@ -140,15 +140,14 @@ save_data('final.Head5.am', results['regular'], results['header'])
140
140
 
141
141
  #### Command-line based (prediction)
142
142
  ```
143
- # start prediction with a batch size of 6
144
- python -m biomedisa.deeplearning C:\Users\%USERNAME%\Downloads\testing_axial_crop_pat13.nii.gz C:\Users\%USERNAME%\Downloads\heart.h5 -p -bs 6
143
+ python -m biomedisa.deeplearning C:\Users\%USERNAME%\Downloads\testing_axial_crop_pat13.nii.gz C:\Users\%USERNAME%\Downloads\heart.h5 -p
145
144
  ```
146
145
 
147
146
  # Biomedisa Features
148
147
 
149
148
  #### Load and save data (such as Amira Mesh, TIFF, NRRD, NIfTI or DICOM)
150
149
  ```python
151
- from biomedisa.biomedisa_features.biomedisa_helper import load_data, save_data
150
+ from biomedisa.features.biomedisa_helper import load_data, save_data
152
151
 
153
152
  # load data as numpy array
154
153
  # for DICOM, PNG files, or similar formats, 'path_to_data' must reference
@@ -161,7 +160,7 @@ save_data(path_to_data, data, header)
161
160
 
162
161
  #### Create STL mesh from segmentation (label values are saved as attributes)
163
162
  ```python
164
- from biomedisa.biomedisa_features.biomedisa_helper import load_data, save_data
163
+ from biomedisa.features.biomedisa_helper import load_data, save_data
165
164
  from biomedisa.mesh import get_voxel_spacing, save_mesh
166
165
 
167
166
  # load segmentation
@@ -194,7 +193,7 @@ python -m biomedisa.mesh <path_to_data>
194
193
 
195
194
  #### Resize data
196
195
  ```python
197
- from biomedisa.biomedisa_features.biomedisa_helper import img_resize
196
+ from biomedisa.features.biomedisa_helper import img_resize
198
197
 
199
198
  # resize image data
200
199
  zsh, ysh, xsh = data.shape
@@ -207,7 +206,7 @@ label_data = img_resize(label_data, new_zsh, new_ysh, new_xsh, labels=True)
207
206
 
208
207
  #### Remove outliers and fill holes
209
208
  ```python
210
- from biomedisa.biomedisa_features.biomedisa_helper import clean, fill
209
+ from biomedisa.features.biomedisa_helper import clean, fill
211
210
 
212
211
  # delete outliers smaller than 90% of the segment
213
212
  label_data = clean(label_data, 0.9)
@@ -218,28 +217,28 @@ label_data = fill(label_data, 0.9)
218
217
 
219
218
  #### Accuracy assessment
220
219
  ```python
221
- from biomedisa.biomedisa_features.biomedisa_helper import Dice_score, ASSD
220
+ from biomedisa.features.biomedisa_helper import Dice_score, ASSD
222
221
  dice = Dice_score(ground_truth, result)
223
222
  assd = ASSD(ground_truth, result)
224
223
  ```
225
224
 
226
225
  # Update Biomedisa
227
- If you installed Biomedisa via Pip.
226
+ If you installed Biomedisa via Pip
228
227
  ```
229
228
  pip install --upgrade biomedisa
230
229
  ```
231
- If you used `git clone`, change to the Biomedisa directory and make a pull request.
230
+ If you used `git clone`, change to the Biomedisa directory and make a pull request
232
231
  ```
233
232
  cd git/biomedisa
234
233
  git pull
235
234
  ```
236
235
 
237
- If you installed the browser based version of Biomedisa (including MySQL database), you also need to update the database.
236
+ If you installed the browser based version of Biomedisa (including MySQL database), you also need to update the database
238
237
  ```
239
238
  python manage.py migrate
240
239
  ```
241
240
 
242
- If you installed an [Apache Server](https://github.com/biomedisa/biomedisa/blob/master/README/APACHE_SERVER.md), you need to restart the server.
241
+ If you installed an [Apache Server](https://github.com/biomedisa/biomedisa/blob/master/README/APACHE_SERVER.md), you need to restart the server
243
242
  ```
244
243
  sudo service apache2 restart
245
244
  ```
@@ -1,4 +1,4 @@
1
- [![biomedisa](biomedisa_app/static/biomedisa_logo.svg)](https://biomedisa.info)
1
+ [![biomedisa](https://raw.githubusercontent.com/biomedisa/biomedisa/master/biomedisa_app/static/biomedisa_logo.svg)](https://biomedisa.info)
2
2
  -----------
3
3
  - [Overview](#overview)
4
4
  - [Hardware Requirements](#hardware-requirements)
@@ -39,7 +39,7 @@ Biomedisa (https://biomedisa.info) is a free and easy-to-use open-source applica
39
39
 
40
40
  #### Python example
41
41
  ```python
42
- from biomedisa.biomedisa_features.biomedisa_helper import load_data, save_data
42
+ from biomedisa.features.biomedisa_helper import load_data, save_data
43
43
  from biomedisa.interpolation import smart_interpolation
44
44
 
45
45
  # load data
@@ -68,7 +68,7 @@ python -m biomedisa.interpolation C:\Users\%USERNAME%\Downloads\tumor.tif C:\Use
68
68
 
69
69
  #### Python example (training)
70
70
  ```python
71
- from biomedisa.biomedisa_features.biomedisa_helper import load_data
71
+ from biomedisa.features.biomedisa_helper import load_data
72
72
  from biomedisa.deeplearning import deep_learning
73
73
 
74
74
  # load image data
@@ -108,7 +108,7 @@ If running into ResourceExhaustedError due to out of memory (OOM), try to use sm
108
108
 
109
109
  #### Python example (prediction)
110
110
  ```python
111
- from biomedisa.biomedisa_features.biomedisa_helper import load_data, save_data
111
+ from biomedisa.features.biomedisa_helper import load_data, save_data
112
112
  from biomedisa.deeplearning import deep_learning
113
113
 
114
114
  # load data
@@ -124,15 +124,14 @@ save_data('final.Head5.am', results['regular'], results['header'])
124
124
 
125
125
  #### Command-line based (prediction)
126
126
  ```
127
- # start prediction with a batch size of 6
128
- python -m biomedisa.deeplearning C:\Users\%USERNAME%\Downloads\testing_axial_crop_pat13.nii.gz C:\Users\%USERNAME%\Downloads\heart.h5 -p -bs 6
127
+ python -m biomedisa.deeplearning C:\Users\%USERNAME%\Downloads\testing_axial_crop_pat13.nii.gz C:\Users\%USERNAME%\Downloads\heart.h5 -p
129
128
  ```
130
129
 
131
130
  # Biomedisa Features
132
131
 
133
132
  #### Load and save data (such as Amira Mesh, TIFF, NRRD, NIfTI or DICOM)
134
133
  ```python
135
- from biomedisa.biomedisa_features.biomedisa_helper import load_data, save_data
134
+ from biomedisa.features.biomedisa_helper import load_data, save_data
136
135
 
137
136
  # load data as numpy array
138
137
  # for DICOM, PNG files, or similar formats, 'path_to_data' must reference
@@ -145,7 +144,7 @@ save_data(path_to_data, data, header)
145
144
 
146
145
  #### Create STL mesh from segmentation (label values are saved as attributes)
147
146
  ```python
148
- from biomedisa.biomedisa_features.biomedisa_helper import load_data, save_data
147
+ from biomedisa.features.biomedisa_helper import load_data, save_data
149
148
  from biomedisa.mesh import get_voxel_spacing, save_mesh
150
149
 
151
150
  # load segmentation
@@ -178,7 +177,7 @@ python -m biomedisa.mesh <path_to_data>
178
177
 
179
178
  #### Resize data
180
179
  ```python
181
- from biomedisa.biomedisa_features.biomedisa_helper import img_resize
180
+ from biomedisa.features.biomedisa_helper import img_resize
182
181
 
183
182
  # resize image data
184
183
  zsh, ysh, xsh = data.shape
@@ -191,7 +190,7 @@ label_data = img_resize(label_data, new_zsh, new_ysh, new_xsh, labels=True)
191
190
 
192
191
  #### Remove outliers and fill holes
193
192
  ```python
194
- from biomedisa.biomedisa_features.biomedisa_helper import clean, fill
193
+ from biomedisa.features.biomedisa_helper import clean, fill
195
194
 
196
195
  # delete outliers smaller than 90% of the segment
197
196
  label_data = clean(label_data, 0.9)
@@ -202,28 +201,28 @@ label_data = fill(label_data, 0.9)
202
201
 
203
202
  #### Accuracy assessment
204
203
  ```python
205
- from biomedisa.biomedisa_features.biomedisa_helper import Dice_score, ASSD
204
+ from biomedisa.features.biomedisa_helper import Dice_score, ASSD
206
205
  dice = Dice_score(ground_truth, result)
207
206
  assd = ASSD(ground_truth, result)
208
207
  ```
209
208
 
210
209
  # Update Biomedisa
211
- If you installed Biomedisa via Pip.
210
+ If you installed Biomedisa via Pip
212
211
  ```
213
212
  pip install --upgrade biomedisa
214
213
  ```
215
- If you used `git clone`, change to the Biomedisa directory and make a pull request.
214
+ If you used `git clone`, change to the Biomedisa directory and make a pull request
216
215
  ```
217
216
  cd git/biomedisa
218
217
  git pull
219
218
  ```
220
219
 
221
- If you installed the browser based version of Biomedisa (including MySQL database), you also need to update the database.
220
+ If you installed the browser based version of Biomedisa (including MySQL database), you also need to update the database
222
221
  ```
223
222
  python manage.py migrate
224
223
  ```
225
224
 
226
- If you installed an [Apache Server](https://github.com/biomedisa/biomedisa/blob/master/README/APACHE_SERVER.md), you need to restart the server.
225
+ If you installed an [Apache Server](https://github.com/biomedisa/biomedisa/blob/master/README/APACHE_SERVER.md), you need to restart the server
227
226
  ```
228
227
  sudo service apache2 restart
229
228
  ```
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "biomedisa"
7
- version = "2024.5.18"
7
+ version = "2024.5.20"
8
8
  authors = [
9
9
  { name="Philipp Lösel"}, {email="philipp.loesel@anu.edu.au" },
10
10
  ]
@@ -1,15 +1,11 @@
1
1
  import os
2
- import sys
3
2
  import subprocess
4
3
 
5
4
  # from source base directory
6
5
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
7
6
 
8
- # pip base directory
9
- if not os.path.exists(os.path.join(BASE_DIR,'biomedisa_features')):
10
- BASE_DIR = os.path.dirname(os.path.abspath(__file__))
11
- # add BASE_DIR to PYTHONPATH for absolute imports
12
- sys.path.append(BASE_DIR)
7
+ # pip installation
8
+ if not os.path.exists(os.path.join(BASE_DIR,'biomedisa/settings.py')):
13
9
 
14
10
  # metadata
15
11
  import importlib_metadata
@@ -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,11 @@
27
27
  ## ##
28
28
  ##########################################################################
29
29
 
30
- import sys, os
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
- import biomedisa_features.crop_helper as ch
35
- from biomedisa_features.keras_helper import *
36
- from biomedisa_features.biomedisa_helper import _error_, unique_file_path
32
+ import biomedisa.features.crop_helper as ch
33
+ from biomedisa.features.keras_helper import *
34
+ from biomedisa.features.biomedisa_helper import _error_, unique_file_path
37
35
  from tensorflow.python.framework.errors_impl import ResourceExhaustedError
38
36
  import tensorflow as tf
39
37
  import numpy as np
@@ -43,6 +41,7 @@ import h5py
43
41
  import time
44
42
  import subprocess
45
43
  import glob
44
+ import tempfile
46
45
 
47
46
  class Biomedisa(object):
48
47
  pass
@@ -120,7 +119,7 @@ def deep_learning(img_data, label_data=None, val_img_data=None, val_label_data=N
120
119
  project = os.path.splitext(bm.shortfilename)[0]
121
120
 
122
121
  # path to model
123
- bm.path_to_model = BASE_DIR + f'/private_storage/images/{bm.username}/{project}.h5'
122
+ bm.path_to_model = biomedisa.BASE_DIR + f'/private_storage/images/{bm.username}/{project}.h5'
124
123
  if not bm.remote:
125
124
  bm.path_to_model = unique_file_path(bm.path_to_model)
126
125
 
@@ -128,7 +127,7 @@ def deep_learning(img_data, label_data=None, val_img_data=None, val_label_data=N
128
127
  project = os.path.splitext(os.path.basename(bm.path_to_model))[0]
129
128
 
130
129
  # create pid object
131
- from biomedisa_features.django_env import create_pid_object
130
+ from biomedisa.features.django_env import create_pid_object
132
131
  create_pid_object(os.getpid(), bm.remote, bm.queue, bm.img_id, (bm.path_to_model if bm.train else ''))
133
132
 
134
133
  # write in log file
@@ -227,81 +226,83 @@ def deep_learning(img_data, label_data=None, val_img_data=None, val_label_data=N
227
226
  crop_data = True if 'cropping_weights' in hf else False
228
227
  hf.close()
229
228
 
230
- # extract image files
231
- bm.tmp_dir = None
232
- if bm.path_to_images is not None and (os.path.splitext(bm.path_to_images)[1]=='.tar' or bm.path_to_images[-7:]=='.tar.gz'):
233
- path_to_dir = os.path.dirname(bm.path_to_images) + '/final.'+os.path.basename(bm.path_to_images)
234
- if path_to_dir[-3:]=='.gz':
235
- path_to_dir = path_to_dir[:-3]
236
- if bm.django_env and not bm.remote:
237
- path_to_dir = unique_file_path(path_to_dir)
238
- bm.tmp_dir = BASE_DIR + '/tmp/' + id_generator(40)
239
- tar = tarfile.open(bm.path_to_images)
240
- tar.extractall(path=bm.tmp_dir)
241
- tar.close()
242
- bm.path_to_images = bm.tmp_dir
243
- bm.save_cropped, bm.acwe = False, False
244
- bm.clean, bm.fill = None, None
245
-
246
- # list of images
247
- path_to_finals = []
248
- if bm.path_to_images is not None and os.path.isdir(bm.path_to_images):
249
- files = glob.glob(bm.path_to_images+'/**/*', recursive=True)
250
- bm.path_to_images = [f for f in files if os.path.isfile(f)]
251
- else:
252
- bm.path_to_images = [bm.path_to_images]
253
-
254
- # loop over all images
255
- for bm.path_to_image in bm.path_to_images:
256
-
257
- # create path_to_final
258
- if bm.path_to_image:
259
- filename = os.path.basename(bm.path_to_image)
260
- filename = os.path.splitext(filename)[0]
261
- if filename[-4:] == '.nii':
262
- filename = filename[:-4]
263
- bm.path_to_cropped_image = os.path.dirname(bm.path_to_image) + '/' + filename + '.cropped.tif'
264
- if bm.django_env and not bm.remote and not bm.tmp_dir:
265
- bm.path_to_cropped_image = unique_file_path(bm.path_to_cropped_image)
266
- filename = 'final.' + filename
267
- bm.path_to_final = os.path.dirname(bm.path_to_image) + '/' + filename + extension
268
- if bm.django_env and not bm.remote and not bm.tmp_dir:
269
- bm.path_to_final = unique_file_path(bm.path_to_final)
270
-
271
- # crop data
272
- region_of_interest, cropped_volume = None, None
273
- if crop_data:
274
- region_of_interest, cropped_volume = ch.crop_data(bm.path_to_image, bm.path_to_model, bm.path_to_cropped_image,
275
- bm.batch_size, bm.debug_cropping, bm.save_cropped, img_data, bm.x_range, bm.y_range, bm.z_range)
276
-
277
- # load prediction data
278
- img, img_header, z_shape, y_shape, x_shape, region_of_interest, img_data = load_prediction_data(bm.path_to_image,
279
- channels, bm.x_scale, bm.y_scale, bm.z_scale, bm.no_scaling, normalize, normalization_parameters,
280
- region_of_interest, img_data, img_header)
281
-
282
- # make prediction
283
- results, bm = predict_semantic_segmentation(bm, img, bm.path_to_model,
284
- bm.z_patch, bm.y_patch, bm.x_patch, z_shape, y_shape, x_shape, bm.compression, header,
285
- img_header, bm.stride_size, allLabels, bm.batch_size, region_of_interest,
286
- bm.no_scaling, extension, img_data)
287
-
288
- # results
289
- if cropped_volume is not None:
290
- results['cropped_volume'] = cropped_volume
291
-
292
- # path to results
293
- if bm.path_to_image:
294
- path_to_finals.append(bm.path_to_final)
295
-
296
- # write tar file and delete extracted image files
297
- if bm.tmp_dir is not None and os.path.exists(bm.tmp_dir):
298
- with tarfile.open(path_to_dir, 'w') as tar:
299
- for file_path in path_to_finals:
300
- file_name = os.path.basename(file_path)
301
- tar.add(file_path, arcname=file_name)
302
- shutil.rmtree(bm.tmp_dir)
303
- bm.path_to_final = path_to_dir
304
- bm.path_to_cropped_image = None
229
+ # make temporary directory
230
+ with tempfile.TemporaryDirectory() as temp_dir:
231
+
232
+ # extract image files from tar file
233
+ bm.tarfile = False
234
+ if bm.path_to_images is not None and (os.path.splitext(bm.path_to_images)[1]=='.tar' or bm.path_to_images[-7:]=='.tar.gz'):
235
+ bm.tarfile = True
236
+ path_to_result = os.path.dirname(bm.path_to_images) + '/final.'+os.path.basename(bm.path_to_images)
237
+ if path_to_result[-3:]=='.gz':
238
+ path_to_result = path_to_result[:-3]
239
+ if bm.django_env and not bm.remote:
240
+ path_to_result = unique_file_path(path_to_result)
241
+ tar = tarfile.open(bm.path_to_images)
242
+ tar.extractall(path=temp_dir)
243
+ tar.close()
244
+ bm.path_to_images = temp_dir
245
+ bm.save_cropped, bm.acwe = False, False
246
+ bm.clean, bm.fill = None, None
247
+
248
+ # list of images
249
+ path_to_finals = []
250
+ if bm.path_to_images is not None and os.path.isdir(bm.path_to_images):
251
+ files = glob.glob(bm.path_to_images+'/**/*', recursive=True)
252
+ bm.path_to_images = [f for f in files if os.path.isfile(f)]
253
+ else:
254
+ bm.path_to_images = [bm.path_to_images]
255
+
256
+ # loop over all images
257
+ for bm.path_to_image in bm.path_to_images:
258
+
259
+ # create path_to_final
260
+ if bm.path_to_image:
261
+ filename = os.path.basename(bm.path_to_image)
262
+ filename = os.path.splitext(filename)[0]
263
+ if filename[-4:] == '.nii':
264
+ filename = filename[:-4]
265
+ bm.path_to_cropped_image = os.path.dirname(bm.path_to_image) + '/' + filename + '.cropped.tif'
266
+ if bm.django_env and not bm.remote and not bm.tarfile:
267
+ bm.path_to_cropped_image = unique_file_path(bm.path_to_cropped_image)
268
+ filename = 'final.' + filename
269
+ bm.path_to_final = os.path.dirname(bm.path_to_image) + '/' + filename + extension
270
+ if bm.django_env and not bm.remote and not bm.tarfile:
271
+ bm.path_to_final = unique_file_path(bm.path_to_final)
272
+
273
+ # crop data
274
+ region_of_interest, cropped_volume = None, None
275
+ if crop_data:
276
+ region_of_interest, cropped_volume = ch.crop_data(bm.path_to_image, bm.path_to_model, bm.path_to_cropped_image,
277
+ bm.batch_size, bm.debug_cropping, bm.save_cropped, img_data, bm.x_range, bm.y_range, bm.z_range)
278
+
279
+ # load prediction data
280
+ img, img_header, z_shape, y_shape, x_shape, region_of_interest, img_data = load_prediction_data(bm.path_to_image,
281
+ channels, bm.x_scale, bm.y_scale, bm.z_scale, bm.no_scaling, normalize, normalization_parameters,
282
+ region_of_interest, img_data, img_header)
283
+
284
+ # make prediction
285
+ results, bm = predict_semantic_segmentation(bm, img, bm.path_to_model,
286
+ bm.z_patch, bm.y_patch, bm.x_patch, z_shape, y_shape, x_shape, bm.compression, header,
287
+ img_header, bm.stride_size, allLabels, bm.batch_size, region_of_interest,
288
+ bm.no_scaling, extension, img_data)
289
+
290
+ # results
291
+ if cropped_volume is not None:
292
+ results['cropped_volume'] = cropped_volume
293
+
294
+ # path to results
295
+ if bm.path_to_image:
296
+ path_to_finals.append(bm.path_to_final)
297
+
298
+ # write tar file and delete extracted image files
299
+ if bm.tarfile and os.path.exists(temp_dir):
300
+ with tarfile.open(path_to_result, 'w') as tar:
301
+ for file_path in path_to_finals:
302
+ file_name = os.path.basename(file_path)
303
+ tar.add(file_path, arcname=file_name)
304
+ bm.path_to_final = path_to_result
305
+ bm.path_to_cropped_image = None
305
306
 
306
307
  # computation time
307
308
  t = int(time.time() - TIC)
@@ -316,7 +317,7 @@ def deep_learning(img_data, label_data=None, val_img_data=None, val_label_data=N
316
317
  # django environment
317
318
  if bm.django_env:
318
319
  from biomedisa_app.config import config
319
- from biomedisa_features.django_env import post_processing
320
+ from biomedisa.features.django_env import post_processing
320
321
  validation=True if bm.validation_split or (bm.val_images is not None and bm.val_images[0] is not None) else False
321
322
  post_processing(bm.path_to_final, time_str, config['SERVER_ALIAS'], bm.remote, bm.queue,
322
323
  img_id=bm.img_id, label_id=bm.label_id, path_to_model=bm.path_to_model,
@@ -324,7 +325,7 @@ def deep_learning(img_data, label_data=None, val_img_data=None, val_label_data=N
324
325
  train=bm.train, predict=bm.predict, validation=validation)
325
326
 
326
327
  # write in log file
327
- path_to_time = BASE_DIR + '/log/time.txt'
328
+ path_to_time = biomedisa.BASE_DIR + '/log/time.txt'
328
329
  with open(path_to_time, 'a') as timefile:
329
330
  if predict:
330
331
  message = 'Successfully segmented ' + bm.shortfilename
@@ -487,7 +488,7 @@ if __name__ == '__main__':
487
488
  reference_image_path = bm.path_to_images
488
489
  bm.username = os.path.basename(os.path.dirname(reference_image_path))
489
490
  bm.shortfilename = os.path.basename(reference_image_path)
490
- bm.path_to_logfile = BASE_DIR + '/log/logfile.txt'
491
+ bm.path_to_logfile = biomedisa.BASE_DIR + '/log/logfile.txt'
491
492
  else:
492
493
  bm.django_env = False
493
494
 
@@ -497,13 +498,9 @@ if __name__ == '__main__':
497
498
  try:
498
499
  deep_learning(None, **kwargs)
499
500
  except InputError:
500
- if any(InputError.img_names):
501
- remove_extracted_data(InputError.img_names, InputError.label_names)
502
501
  print(traceback.format_exc())
503
502
  bm = _error_(bm, f'{InputError.message}')
504
503
  except ch.InputError:
505
- if any(ch.InputError.img_names):
506
- remove_extracted_data(ch.InputError.img_names, ch.InputError.label_names)
507
504
  print(traceback.format_exc())
508
505
  bm = _error_(bm, f'{ch.InputError.message}')
509
506
  except MemoryError:
@@ -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) 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) 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) 2022 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,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 sys, 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 biomedisa
35
- from biomedisa_features.curvop_numba import curvop, evolution
36
- from biomedisa_features.biomedisa_helper import (unique_file_path, load_data, save_data,
32
+ from biomedisa.features.curvop_numba import curvop, evolution
33
+ from biomedisa.features.biomedisa_helper import (unique_file_path, load_data, save_data,
37
34
  pre_processing, img_to_uint8, silent_remove)
38
35
  import numpy as np
39
36
  import numba
@@ -143,7 +140,7 @@ def activeContour(data, labelData, alpha=1.0, smooth=1, steps=3,
143
140
  if bm.django_env:
144
141
  bm.username = os.path.basename(os.path.dirname(bm.path_to_data))
145
142
  bm.shortfilename = os.path.basename(bm.path_to_data)
146
- bm.path_to_logfile = BASE_DIR + '/log/logfile.txt'
143
+ bm.path_to_logfile = biomedisa.BASE_DIR + '/log/logfile.txt'
147
144
 
148
145
  # pre-processing
149
146
  bm = pre_processing(bm)
@@ -234,13 +231,13 @@ def refinement(bm):
234
231
 
235
232
  def post_processing(path_to_acwe, image_id=None, friend_id=None, simple=False, remote=False):
236
233
  if remote:
237
- with open(BASE_DIR + '/log/config_4', 'w') as configfile:
234
+ with open(biomedisa.BASE_DIR + '/log/config_4', 'w') as configfile:
238
235
  print(path_to_acwe, 'phantom', file=configfile)
239
236
  else:
240
237
  import django
241
238
  django.setup()
242
239
  from biomedisa_app.models import Upload
243
- from biomedisa_features.create_slices import create_slices
240
+ from biomedisa.features.create_slices import create_slices
244
241
  from redis import Redis
245
242
  from rq import Queue
246
243
 
@@ -300,7 +297,7 @@ def init_active_contour(image_id, friend_id, label_id, simple=False):
300
297
 
301
298
  # get host information
302
299
  host = ''
303
- host_base = BASE_DIR
300
+ host_base = biomedisa.BASE_DIR
304
301
  subhost, qsub_pid = None, None
305
302
  if 'REMOTE_QUEUE_HOST' in config:
306
303
  host = config['REMOTE_QUEUE_HOST']
@@ -313,8 +310,8 @@ def init_active_contour(image_id, friend_id, label_id, simple=False):
313
310
  if host:
314
311
 
315
312
  # command
316
- cmd = ['python3', host_base+'/biomedisa_features/active_contour.py']
317
- cmd += [image.pic.path.replace(BASE_DIR,host_base), friend.pic.path.replace(BASE_DIR,host_base)]
313
+ cmd = ['python3', host_base+'/biomedisa/features/active_contour.py']
314
+ cmd += [image.pic.path.replace(biomedisa.BASE_DIR,host_base), friend.pic.path.replace(biomedisa.BASE_DIR,host_base)]
318
315
  cmd += [f'-iid={image.id}', f'-fid={friend.id}', '-r']
319
316
 
320
317
  # command (append only on demand)
@@ -338,8 +335,8 @@ def init_active_contour(image_id, friend_id, label_id, simple=False):
338
335
 
339
336
  # send data to host
340
337
  success=0
341
- success+=send_data_to_host(image.pic.path, host+':'+image.pic.path.replace(BASE_DIR,host_base))
342
- success+=send_data_to_host(friend.pic.path, host+':'+friend.pic.path.replace(BASE_DIR,host_base))
338
+ success+=send_data_to_host(image.pic.path, host+':'+image.pic.path.replace(biomedisa.BASE_DIR,host_base))
339
+ success+=send_data_to_host(friend.pic.path, host+':'+friend.pic.path.replace(biomedisa.BASE_DIR,host_base))
343
340
 
344
341
  if success==0:
345
342
 
@@ -355,14 +352,14 @@ def init_active_contour(image_id, friend_id, label_id, simple=False):
355
352
  subprocess.Popen(cmd).wait()
356
353
 
357
354
  # config
358
- success = subprocess.Popen(['scp', host+':'+host_base+'/log/config_4', BASE_DIR+'/log/config_4']).wait()
355
+ success = subprocess.Popen(['scp', host+':'+host_base+'/log/config_4', biomedisa.BASE_DIR+'/log/config_4']).wait()
359
356
 
360
357
  if success==0:
361
- with open(BASE_DIR + '/log/config_4', 'r') as configfile:
358
+ with open(biomedisa.BASE_DIR + '/log/config_4', 'r') as configfile:
362
359
  acwe_on_host, _ = configfile.read().split()
363
360
 
364
361
  # local file names
365
- path_to_acwe = unique_file_path(acwe_on_host.replace(host_base,BASE_DIR))
362
+ path_to_acwe = unique_file_path(acwe_on_host.replace(host_base,biomedisa.BASE_DIR))
366
363
 
367
364
  # get results
368
365
  subprocess.Popen(['scp', host+':'+acwe_on_host, path_to_acwe]).wait()