biomedisa 2024.5.17__tar.gz → 2024.5.19__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 (48) hide show
  1. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/PKG-INFO +25 -55
  2. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/README.md +24 -54
  3. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/pyproject.toml +1 -1
  4. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/biomedisa_helper.py +100 -110
  5. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/create_slices.py +49 -56
  6. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/crop_helper.py +107 -112
  7. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/keras_helper.py +137 -163
  8. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/deeplearning.py +78 -79
  9. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa.egg-info/PKG-INFO +25 -55
  10. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/LICENSE +0 -0
  11. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/setup.cfg +0 -0
  12. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/__init__.py +0 -0
  13. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/__main__.py +0 -0
  14. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/DataGenerator.py +0 -0
  15. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/DataGeneratorCrop.py +0 -0
  16. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/PredictDataGenerator.py +0 -0
  17. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/PredictDataGeneratorCrop.py +0 -0
  18. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/__init__.py +0 -0
  19. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/active_contour.py +0 -0
  20. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/amira_to_np/__init__.py +0 -0
  21. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/amira_to_np/amira_data_stream.py +0 -0
  22. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/amira_to_np/amira_grammar.py +0 -0
  23. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/amira_to_np/amira_header.py +0 -0
  24. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/amira_to_np/amira_helper.py +0 -0
  25. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/assd.py +0 -0
  26. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/curvop_numba.py +0 -0
  27. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/django_env.py +0 -0
  28. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/nc_reader.py +0 -0
  29. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/pid.py +0 -0
  30. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/process_image.py +0 -0
  31. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/pycuda_test.py +0 -0
  32. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/random_walk/__init__.py +0 -0
  33. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/random_walk/gpu_kernels.py +0 -0
  34. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/random_walk/pycuda_large.py +0 -0
  35. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/random_walk/pycuda_large_allx.py +0 -0
  36. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/random_walk/pycuda_small.py +0 -0
  37. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/random_walk/pycuda_small_allx.py +0 -0
  38. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/random_walk/pyopencl_large.py +0 -0
  39. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/random_walk/pyopencl_small.py +0 -0
  40. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/random_walk/rw_large.py +0 -0
  41. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/random_walk/rw_small.py +0 -0
  42. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/remove_outlier.py +0 -0
  43. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/biomedisa_features/split_volume.py +0 -0
  44. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/interpolation.py +0 -0
  45. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa/mesh.py +0 -0
  46. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa.egg-info/SOURCES.txt +0 -0
  47. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/src/biomedisa.egg-info/dependency_links.txt +0 -0
  48. {biomedisa-2024.5.17 → biomedisa-2024.5.19}/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.17
3
+ Version: 2024.5.19
4
4
  Summary: Segmentation of 3D volumetric image data
5
5
  Author: Philipp Lösel
6
6
  Author-email: philipp.loesel@anu.edu.au
@@ -55,13 +55,8 @@ Biomedisa (https://biomedisa.info) is a free and easy-to-use open-source applica
55
55
 
56
56
  #### Python example
57
57
  ```python
58
- # change this line to your biomedisa directory
59
- path_to_biomedisa = '/home/<user>/git/biomedisa'
60
-
61
- import sys
62
- sys.path.append(path_to_biomedisa)
63
- from biomedisa_features.biomedisa_helper import load_data, save_data
64
- from biomedisa_features.biomedisa_interpolation import smart_interpolation
58
+ from biomedisa.biomedisa_features.biomedisa_helper import load_data, save_data
59
+ from biomedisa.interpolation import smart_interpolation
65
60
 
66
61
  # load data
67
62
  img, _ = load_data('Downloads/trigonopterus.tif')
@@ -81,11 +76,7 @@ save_data('Downloads/final.trigonopterus.smooth.am', smooth_result, header=heade
81
76
 
82
77
  #### Command-line based
83
78
  ```
84
- # change to the features directory
85
- cd git/biomedisa/biomedisa_features/
86
-
87
- # start smart interpolation
88
- python biomedisa_interpolation.py C:\Users\%USERNAME%\Downloads\tumor.tif C:\Users\%USERNAME%\Downloads\labels.tumor.tif
79
+ python -m biomedisa.interpolation C:\Users\%USERNAME%\Downloads\tumor.tif C:\Users\%USERNAME%\Downloads\labels.tumor.tif
89
80
  ```
90
81
 
91
82
  # Deep Learning
@@ -93,14 +84,8 @@ python biomedisa_interpolation.py C:\Users\%USERNAME%\Downloads\tumor.tif C:\Use
93
84
 
94
85
  #### Python example (training)
95
86
  ```python
96
- # change this line to your biomedisa directory
97
- path_to_biomedisa = '/home/<user>/git/biomedisa'
98
-
99
- # load libraries
100
- import sys
101
- sys.path.append(path_to_biomedisa)
102
- from biomedisa_features.biomedisa_helper import load_data
103
- from biomedisa_features.biomedisa_deeplearning import deep_learning
87
+ from biomedisa.biomedisa_features.biomedisa_helper import load_data
88
+ from biomedisa.deeplearning import deep_learning
104
89
 
105
90
  # load image data
106
91
  img1, _ = load_data('Head1.am')
@@ -129,27 +114,18 @@ deep_learning(img_data, label_data, train=True, batch_size=12,
129
114
 
130
115
  #### Command-line based (training)
131
116
  ```
132
- # change to the features directory
133
- cd git/biomedisa/biomedisa_features/
134
-
135
117
  # start training with a batch size of 12
136
- python biomedisa_deeplearning.py C:\Users\%USERNAME%\Downloads\training_heart C:\Users\%USERNAME%\Downloads\training_heart_labels -t -bs 12
118
+ python -m biomedisa.deeplearning C:\Users\%USERNAME%\Downloads\training_heart C:\Users\%USERNAME%\Downloads\training_heart_labels -t -bs 12
137
119
 
138
120
  # validation (optional)
139
- python biomedisa_deeplearning.py C:\Users\%USERNAME%\Downloads\training_heart C:\Users\%USERNAME%\Downloads\training_heart_labels -t -vi C:\Users\%USERNAME%\Downloads\val_img -vl C:\Users\%USERNAME%\Downloads\val_labels
121
+ python -m biomedisa.deeplearning C:\Users\%USERNAME%\Downloads\training_heart C:\Users\%USERNAME%\Downloads\training_heart_labels -t -vi C:\Users\%USERNAME%\Downloads\val_img -vl C:\Users\%USERNAME%\Downloads\val_labels
140
122
  ```
141
123
  If running into ResourceExhaustedError due to out of memory (OOM), try to use smaller batch size.
142
124
 
143
125
  #### Python example (prediction)
144
126
  ```python
145
- # change this line to your biomedisa directory
146
- path_to_biomedisa = '/home/<user>/git/biomedisa'
147
-
148
- # load libraries
149
- import sys
150
- sys.path.append(path_to_biomedisa)
151
- from biomedisa_features.biomedisa_helper import load_data, save_data
152
- from biomedisa_features.biomedisa_deeplearning import deep_learning
127
+ from biomedisa.biomedisa_features.biomedisa_helper import load_data, save_data
128
+ from biomedisa.deeplearning import deep_learning
153
129
 
154
130
  # load data
155
131
  img, _ = load_data('Head5.am')
@@ -164,20 +140,14 @@ save_data('final.Head5.am', results['regular'], results['header'])
164
140
 
165
141
  #### Command-line based (prediction)
166
142
  ```
167
- # change to the features directory
168
- cd git/biomedisa/biomedisa_features/
169
-
170
- # start prediction with a batch size of 6
171
- python biomedisa_deeplearning.py 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
172
144
  ```
173
145
 
174
146
  # Biomedisa Features
175
147
 
176
148
  #### Load and save data (such as Amira Mesh, TIFF, NRRD, NIfTI or DICOM)
177
149
  ```python
178
- import sys
179
- sys.path.append(path_to_biomedisa) # e.g. '/home/<user>/git/biomedisa'
180
- from biomedisa_features.biomedisa_helper import load_data, save_data
150
+ from biomedisa.biomedisa_features.biomedisa_helper import load_data, save_data
181
151
 
182
152
  # load data as numpy array
183
153
  # for DICOM, PNG files, or similar formats, 'path_to_data' must reference
@@ -190,10 +160,8 @@ save_data(path_to_data, data, header)
190
160
 
191
161
  #### Create STL mesh from segmentation (label values are saved as attributes)
192
162
  ```python
193
- import os, sys
194
- sys.path.append(path_to_biomedisa) # e.g. '/home/<user>/git/biomedisa'
195
- from biomedisa_features.biomedisa_helper import load_data, save_data
196
- from biomedisa_features.create_mesh import get_voxel_spacing, save_mesh
163
+ from biomedisa.biomedisa_features.biomedisa_helper import load_data, save_data
164
+ from biomedisa.mesh import get_voxel_spacing, save_mesh
197
165
 
198
166
  # load segmentation
199
167
  data, header, extension = load_data(path_to_data, return_extension=True)
@@ -209,7 +177,7 @@ save_mesh(path_to_data, data, x_res, y_res, z_res, poly_reduction=0.9, smoothing
209
177
 
210
178
  #### Create mesh directly
211
179
  ```
212
- python git/biomedisa/biomedisa_features/create_mesh.py <path_to_data>
180
+ python -m biomedisa.mesh <path_to_data>
213
181
  ```
214
182
 
215
183
  #### Options
@@ -225,9 +193,7 @@ python git/biomedisa/biomedisa_features/create_mesh.py <path_to_data>
225
193
 
226
194
  #### Resize data
227
195
  ```python
228
- import os, sys
229
- sys.path.append(path_to_biomedisa) # e.g. '/home/<user>/git/biomedisa'
230
- from biomedisa_features.biomedisa_helper import img_resize
196
+ from biomedisa.biomedisa_features.biomedisa_helper import img_resize
231
197
 
232
198
  # resize image data
233
199
  zsh, ysh, xsh = data.shape
@@ -240,7 +206,7 @@ label_data = img_resize(label_data, new_zsh, new_ysh, new_xsh, labels=True)
240
206
 
241
207
  #### Remove outliers and fill holes
242
208
  ```python
243
- from biomedisa_features.biomedisa_helper import clean, fill
209
+ from biomedisa.biomedisa_features.biomedisa_helper import clean, fill
244
210
 
245
211
  # delete outliers smaller than 90% of the segment
246
212
  label_data = clean(label_data, 0.9)
@@ -251,24 +217,28 @@ label_data = fill(label_data, 0.9)
251
217
 
252
218
  #### Accuracy assessment
253
219
  ```python
254
- from biomedisa_features.biomedisa_helper import Dice_score, ASSD
220
+ from biomedisa.biomedisa_features.biomedisa_helper import Dice_score, ASSD
255
221
  dice = Dice_score(ground_truth, result)
256
222
  assd = ASSD(ground_truth, result)
257
223
  ```
258
224
 
259
225
  # Update Biomedisa
260
- If you have used `git clone`, change to the Biomedisa directory and make a pull request.
226
+ If you installed Biomedisa via Pip
227
+ ```
228
+ pip install --upgrade biomedisa
229
+ ```
230
+ If you used `git clone`, change to the Biomedisa directory and make a pull request
261
231
  ```
262
232
  cd git/biomedisa
263
233
  git pull
264
234
  ```
265
235
 
266
- If you have 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
267
237
  ```
268
238
  python manage.py migrate
269
239
  ```
270
240
 
271
- If you have 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
272
242
  ```
273
243
  sudo service apache2 restart
274
244
  ```
@@ -39,13 +39,8 @@ Biomedisa (https://biomedisa.info) is a free and easy-to-use open-source applica
39
39
 
40
40
  #### Python example
41
41
  ```python
42
- # change this line to your biomedisa directory
43
- path_to_biomedisa = '/home/<user>/git/biomedisa'
44
-
45
- import sys
46
- sys.path.append(path_to_biomedisa)
47
- from biomedisa_features.biomedisa_helper import load_data, save_data
48
- from biomedisa_features.biomedisa_interpolation import smart_interpolation
42
+ from biomedisa.biomedisa_features.biomedisa_helper import load_data, save_data
43
+ from biomedisa.interpolation import smart_interpolation
49
44
 
50
45
  # load data
51
46
  img, _ = load_data('Downloads/trigonopterus.tif')
@@ -65,11 +60,7 @@ save_data('Downloads/final.trigonopterus.smooth.am', smooth_result, header=heade
65
60
 
66
61
  #### Command-line based
67
62
  ```
68
- # change to the features directory
69
- cd git/biomedisa/biomedisa_features/
70
-
71
- # start smart interpolation
72
- python biomedisa_interpolation.py C:\Users\%USERNAME%\Downloads\tumor.tif C:\Users\%USERNAME%\Downloads\labels.tumor.tif
63
+ python -m biomedisa.interpolation C:\Users\%USERNAME%\Downloads\tumor.tif C:\Users\%USERNAME%\Downloads\labels.tumor.tif
73
64
  ```
74
65
 
75
66
  # Deep Learning
@@ -77,14 +68,8 @@ python biomedisa_interpolation.py C:\Users\%USERNAME%\Downloads\tumor.tif C:\Use
77
68
 
78
69
  #### Python example (training)
79
70
  ```python
80
- # change this line to your biomedisa directory
81
- path_to_biomedisa = '/home/<user>/git/biomedisa'
82
-
83
- # load libraries
84
- import sys
85
- sys.path.append(path_to_biomedisa)
86
- from biomedisa_features.biomedisa_helper import load_data
87
- from biomedisa_features.biomedisa_deeplearning import deep_learning
71
+ from biomedisa.biomedisa_features.biomedisa_helper import load_data
72
+ from biomedisa.deeplearning import deep_learning
88
73
 
89
74
  # load image data
90
75
  img1, _ = load_data('Head1.am')
@@ -113,27 +98,18 @@ deep_learning(img_data, label_data, train=True, batch_size=12,
113
98
 
114
99
  #### Command-line based (training)
115
100
  ```
116
- # change to the features directory
117
- cd git/biomedisa/biomedisa_features/
118
-
119
101
  # start training with a batch size of 12
120
- python biomedisa_deeplearning.py C:\Users\%USERNAME%\Downloads\training_heart C:\Users\%USERNAME%\Downloads\training_heart_labels -t -bs 12
102
+ python -m biomedisa.deeplearning C:\Users\%USERNAME%\Downloads\training_heart C:\Users\%USERNAME%\Downloads\training_heart_labels -t -bs 12
121
103
 
122
104
  # validation (optional)
123
- python biomedisa_deeplearning.py C:\Users\%USERNAME%\Downloads\training_heart C:\Users\%USERNAME%\Downloads\training_heart_labels -t -vi C:\Users\%USERNAME%\Downloads\val_img -vl C:\Users\%USERNAME%\Downloads\val_labels
105
+ python -m biomedisa.deeplearning C:\Users\%USERNAME%\Downloads\training_heart C:\Users\%USERNAME%\Downloads\training_heart_labels -t -vi C:\Users\%USERNAME%\Downloads\val_img -vl C:\Users\%USERNAME%\Downloads\val_labels
124
106
  ```
125
107
  If running into ResourceExhaustedError due to out of memory (OOM), try to use smaller batch size.
126
108
 
127
109
  #### Python example (prediction)
128
110
  ```python
129
- # change this line to your biomedisa directory
130
- path_to_biomedisa = '/home/<user>/git/biomedisa'
131
-
132
- # load libraries
133
- import sys
134
- sys.path.append(path_to_biomedisa)
135
- from biomedisa_features.biomedisa_helper import load_data, save_data
136
- from biomedisa_features.biomedisa_deeplearning import deep_learning
111
+ from biomedisa.biomedisa_features.biomedisa_helper import load_data, save_data
112
+ from biomedisa.deeplearning import deep_learning
137
113
 
138
114
  # load data
139
115
  img, _ = load_data('Head5.am')
@@ -148,20 +124,14 @@ save_data('final.Head5.am', results['regular'], results['header'])
148
124
 
149
125
  #### Command-line based (prediction)
150
126
  ```
151
- # change to the features directory
152
- cd git/biomedisa/biomedisa_features/
153
-
154
- # start prediction with a batch size of 6
155
- python biomedisa_deeplearning.py 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
156
128
  ```
157
129
 
158
130
  # Biomedisa Features
159
131
 
160
132
  #### Load and save data (such as Amira Mesh, TIFF, NRRD, NIfTI or DICOM)
161
133
  ```python
162
- import sys
163
- sys.path.append(path_to_biomedisa) # e.g. '/home/<user>/git/biomedisa'
164
- from biomedisa_features.biomedisa_helper import load_data, save_data
134
+ from biomedisa.biomedisa_features.biomedisa_helper import load_data, save_data
165
135
 
166
136
  # load data as numpy array
167
137
  # for DICOM, PNG files, or similar formats, 'path_to_data' must reference
@@ -174,10 +144,8 @@ save_data(path_to_data, data, header)
174
144
 
175
145
  #### Create STL mesh from segmentation (label values are saved as attributes)
176
146
  ```python
177
- import os, sys
178
- sys.path.append(path_to_biomedisa) # e.g. '/home/<user>/git/biomedisa'
179
- from biomedisa_features.biomedisa_helper import load_data, save_data
180
- from biomedisa_features.create_mesh import get_voxel_spacing, save_mesh
147
+ from biomedisa.biomedisa_features.biomedisa_helper import load_data, save_data
148
+ from biomedisa.mesh import get_voxel_spacing, save_mesh
181
149
 
182
150
  # load segmentation
183
151
  data, header, extension = load_data(path_to_data, return_extension=True)
@@ -193,7 +161,7 @@ save_mesh(path_to_data, data, x_res, y_res, z_res, poly_reduction=0.9, smoothing
193
161
 
194
162
  #### Create mesh directly
195
163
  ```
196
- python git/biomedisa/biomedisa_features/create_mesh.py <path_to_data>
164
+ python -m biomedisa.mesh <path_to_data>
197
165
  ```
198
166
 
199
167
  #### Options
@@ -209,9 +177,7 @@ python git/biomedisa/biomedisa_features/create_mesh.py <path_to_data>
209
177
 
210
178
  #### Resize data
211
179
  ```python
212
- import os, sys
213
- sys.path.append(path_to_biomedisa) # e.g. '/home/<user>/git/biomedisa'
214
- from biomedisa_features.biomedisa_helper import img_resize
180
+ from biomedisa.biomedisa_features.biomedisa_helper import img_resize
215
181
 
216
182
  # resize image data
217
183
  zsh, ysh, xsh = data.shape
@@ -224,7 +190,7 @@ label_data = img_resize(label_data, new_zsh, new_ysh, new_xsh, labels=True)
224
190
 
225
191
  #### Remove outliers and fill holes
226
192
  ```python
227
- from biomedisa_features.biomedisa_helper import clean, fill
193
+ from biomedisa.biomedisa_features.biomedisa_helper import clean, fill
228
194
 
229
195
  # delete outliers smaller than 90% of the segment
230
196
  label_data = clean(label_data, 0.9)
@@ -235,24 +201,28 @@ label_data = fill(label_data, 0.9)
235
201
 
236
202
  #### Accuracy assessment
237
203
  ```python
238
- from biomedisa_features.biomedisa_helper import Dice_score, ASSD
204
+ from biomedisa.biomedisa_features.biomedisa_helper import Dice_score, ASSD
239
205
  dice = Dice_score(ground_truth, result)
240
206
  assd = ASSD(ground_truth, result)
241
207
  ```
242
208
 
243
209
  # Update Biomedisa
244
- If you have used `git clone`, change to the Biomedisa directory and make a pull request.
210
+ If you installed Biomedisa via Pip
211
+ ```
212
+ pip install --upgrade biomedisa
213
+ ```
214
+ If you used `git clone`, change to the Biomedisa directory and make a pull request
245
215
  ```
246
216
  cd git/biomedisa
247
217
  git pull
248
218
  ```
249
219
 
250
- If you have 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
251
221
  ```
252
222
  python manage.py migrate
253
223
  ```
254
224
 
255
- If you have 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
256
226
  ```
257
227
  sudo service apache2 restart
258
228
  ```
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "biomedisa"
7
- version = "2024.5.17"
7
+ version = "2024.5.19"
8
8
  authors = [
9
9
  { name="Philipp Lösel"}, {email="philipp.loesel@anu.edu.au" },
10
10
  ]
@@ -41,10 +41,10 @@ import cv2
41
41
  import time
42
42
  import zipfile
43
43
  import numba
44
- import shutil
45
44
  import subprocess
46
45
  import re
47
46
  import math
47
+ import tempfile
48
48
 
49
49
  def silent_remove(filename):
50
50
  try:
@@ -280,92 +280,85 @@ def load_data(path_to_data, process='None', return_extension=False):
280
280
  data, header = None, None
281
281
 
282
282
  elif extension == '.zip' or os.path.isdir(path_to_data):
283
- # extract files
284
- if extension=='.zip':
285
- path_to_dir = BASE_DIR + '/tmp/' + id_generator(40)
286
- try:
287
- zip_ref = zipfile.ZipFile(path_to_data, 'r')
288
- zip_ref.extractall(path=path_to_dir)
289
- zip_ref.close()
290
- except Exception as e:
291
- print(e)
292
- print('Using unzip package...')
293
- try:
294
- success = subprocess.Popen(['unzip',path_to_data,'-d',path_to_dir]).wait()
295
- if success != 0:
296
- if os.path.isdir(path_to_dir):
297
- shutil.rmtree(path_to_dir)
298
- data, header = None, None
299
- except Exception as e:
300
- print(e)
301
- if os.path.isdir(path_to_dir):
302
- shutil.rmtree(path_to_dir)
303
- data, header = None, None
304
- path_to_data = path_to_dir
305
-
306
- # load files
307
- if os.path.isdir(path_to_data):
308
- files = []
309
- for data_type in ['.[pP][nN][gG]','.[tT][iI][fF]','.[tT][iI][fF][fF]','.[dD][cC][mM]','.[dD][iI][cC][oO][mM]','.[bB][mM][pP]','.[jJ][pP][gG]','.[jJ][pP][eE][gG]','.nc','.nc.bz2']:
310
- files += [file for file in glob.glob(path_to_data+'/**/*'+data_type, recursive=True) if not os.path.basename(file).startswith('.')]
311
- nc_extension = False
312
- for file in files:
313
- if os.path.splitext(file)[1] == '.nc' or os.path.splitext(os.path.splitext(file)[0])[1] == '.nc':
314
- nc_extension = True
315
- if nc_extension:
283
+ with tempfile.TemporaryDirectory() as temp_dir:
284
+
285
+ # extract files
286
+ if extension=='.zip':
316
287
  try:
317
- data, header = nc_to_np(path_to_data)
288
+ zip_ref = zipfile.ZipFile(path_to_data, 'r')
289
+ zip_ref.extractall(path=temp_dir)
290
+ zip_ref.close()
318
291
  except Exception as e:
319
292
  print(e)
320
- data, header = None, None
321
- else:
322
- try:
323
- # remove unreadable files or directories
324
- for name in files:
325
- if os.path.isfile(name):
326
- try:
327
- img, _ = load(name)
328
- except:
293
+ print('Using unzip package...')
294
+ try:
295
+ success = subprocess.Popen(['unzip',path_to_data,'-d',temp_dir]).wait()
296
+ if success != 0:
297
+ data, header = None, None
298
+ except Exception as e:
299
+ print(e)
300
+ data, header = None, None
301
+ path_to_data = temp_dir
302
+
303
+ # load files
304
+ if os.path.isdir(path_to_data):
305
+ files = []
306
+ for data_type in ['.[pP][nN][gG]','.[tT][iI][fF]','.[tT][iI][fF][fF]','.[dD][cC][mM]','.[dD][iI][cC][oO][mM]','.[bB][mM][pP]','.[jJ][pP][gG]','.[jJ][pP][eE][gG]','.nc','.nc.bz2']:
307
+ files += [file for file in glob.glob(path_to_data+'/**/*'+data_type, recursive=True) if not os.path.basename(file).startswith('.')]
308
+ nc_extension = False
309
+ for file in files:
310
+ if os.path.splitext(file)[1] == '.nc' or os.path.splitext(os.path.splitext(file)[0])[1] == '.nc':
311
+ nc_extension = True
312
+ if nc_extension:
313
+ try:
314
+ data, header = nc_to_np(path_to_data)
315
+ except Exception as e:
316
+ print(e)
317
+ data, header = None, None
318
+ else:
319
+ try:
320
+ # remove unreadable files or directories
321
+ for name in files:
322
+ if os.path.isfile(name):
323
+ try:
324
+ img, _ = load(name)
325
+ except:
326
+ files.remove(name)
327
+ else:
329
328
  files.remove(name)
329
+ files.sort()
330
+
331
+ # get data size
332
+ img, _ = load(files[0])
333
+ if len(img.shape)==3:
334
+ ysh, xsh, csh = img.shape[0], img.shape[1], img.shape[2]
335
+ channel = 'last'
336
+ if ysh < csh:
337
+ csh, ysh, xsh = img.shape[0], img.shape[1], img.shape[2]
338
+ channel = 'first'
330
339
  else:
331
- files.remove(name)
332
- files.sort()
333
-
334
- # get data size
335
- img, _ = load(files[0])
336
- if len(img.shape)==3:
337
- ysh, xsh, csh = img.shape[0], img.shape[1], img.shape[2]
338
- channel = 'last'
339
- if ysh < csh:
340
- csh, ysh, xsh = img.shape[0], img.shape[1], img.shape[2]
341
- channel = 'first'
342
- else:
343
- ysh, xsh = img.shape[0], img.shape[1]
344
- csh, channel = 0, None
345
-
346
- # load data slice by slice
347
- data = np.empty((len(files), ysh, xsh), dtype=img.dtype)
348
- header, image_data_shape = [], []
349
- for k, file_name in enumerate(files):
350
- img, img_header = load(file_name)
351
- if csh==3:
352
- img = rgb2gray(img, channel)
353
- elif csh==1 and channel=='last':
354
- img = img[:,:,0]
355
- elif csh==1 and channel=='first':
356
- img = img[0,:,:]
357
- data[k] = img
358
- header.append(img_header)
359
- header = [header, files, data.dtype]
360
- data = np.swapaxes(data, 1, 2)
361
- data = np.copy(data, order='C')
362
- except Exception as e:
363
- print(e)
364
- data, header = None, None
365
-
366
- # remove extracted files
367
- if extension=='.zip' and os.path.isdir(path_to_data):
368
- shutil.rmtree(path_to_data)
340
+ ysh, xsh = img.shape[0], img.shape[1]
341
+ csh, channel = 0, None
342
+
343
+ # load data slice by slice
344
+ data = np.empty((len(files), ysh, xsh), dtype=img.dtype)
345
+ header, image_data_shape = [], []
346
+ for k, file_name in enumerate(files):
347
+ img, img_header = load(file_name)
348
+ if csh==3:
349
+ img = rgb2gray(img, channel)
350
+ elif csh==1 and channel=='last':
351
+ img = img[:,:,0]
352
+ elif csh==1 and channel=='first':
353
+ img = img[0,:,:]
354
+ data[k] = img
355
+ header.append(img_header)
356
+ header = [header, files, data.dtype]
357
+ data = np.swapaxes(data, 1, 2)
358
+ data = np.copy(data, order='C')
359
+ except Exception as e:
360
+ print(e)
361
+ data, header = None, None
369
362
 
370
363
  elif extension == '.mrc':
371
364
  try:
@@ -495,34 +488,31 @@ def save_data(path_to_final, final, header=None, final_image_type=None, compress
495
488
  simg.CopyInformation(header)
496
489
  sitk.WriteImage(simg, path_to_final, useCompression=compress)
497
490
  elif final_image_type in ['.zip', 'directory', '']:
498
- # make results directory
499
- if final_image_type == '.zip':
500
- results_dir = BASE_DIR + '/tmp/' + id_generator(40)
501
- os.makedirs(results_dir)
502
- os.chmod(results_dir, 0o770)
503
- else:
504
- results_dir = path_to_final
505
- if not os.path.isdir(results_dir):
506
- os.makedirs(results_dir)
507
- os.chmod(results_dir, 0o770)
508
- # save data as NC blocks
509
- if os.path.splitext(header[1][0])[1] == '.nc':
510
- np_to_nc(results_dir, final, header)
511
- file_names = header[1]
512
- # save data as PNG, TIF, DICOM slices
513
- else:
514
- header, file_names, final_dtype = header[0], header[1], header[2]
515
- final = final.astype(final_dtype)
516
- final = np.swapaxes(final, 2, 1)
517
- for k, file in enumerate(file_names):
518
- save(final[k], results_dir + '/' + os.path.basename(file), header[k])
519
- # zip data
520
- if final_image_type == '.zip':
521
- with zipfile.ZipFile(path_to_final, 'w') as zip:
522
- for file in file_names:
523
- zip.write(results_dir + '/' + os.path.basename(file), os.path.basename(file))
524
- if os.path.isdir(results_dir):
525
- shutil.rmtree(results_dir)
491
+ with tempfile.TemporaryDirectory() as temp_dir:
492
+ # make results directory
493
+ if final_image_type == '.zip':
494
+ results_dir = temp_dir
495
+ else:
496
+ results_dir = path_to_final
497
+ if not os.path.isdir(results_dir):
498
+ os.makedirs(results_dir)
499
+ os.chmod(results_dir, 0o770)
500
+ # save data as NC blocks
501
+ if os.path.splitext(header[1][0])[1] == '.nc':
502
+ np_to_nc(results_dir, final, header)
503
+ file_names = header[1]
504
+ # save data as PNG, TIF, DICOM slices
505
+ else:
506
+ header, file_names, final_dtype = header[0], header[1], header[2]
507
+ final = final.astype(final_dtype)
508
+ final = np.swapaxes(final, 2, 1)
509
+ for k, file in enumerate(file_names):
510
+ save(final[k], results_dir + '/' + os.path.basename(file), header[k])
511
+ # zip data
512
+ if final_image_type == '.zip':
513
+ with zipfile.ZipFile(path_to_final, 'w') as zip:
514
+ for file in file_names:
515
+ zip.write(results_dir + '/' + os.path.basename(file), os.path.basename(file))
526
516
  else:
527
517
  imageSize = int(final.nbytes * 10e-7)
528
518
  bigtiff = True if imageSize > 2000 else False