biomedisa 24.5.23__py3-none-any.whl → 24.8.1__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.
@@ -143,7 +143,7 @@ def fill(image, threshold=0.9):
143
143
  return image_i
144
144
 
145
145
  def main_helper(path_to_labels, img_id=None, friend_id=None, fill_holes=True,
146
- clean_threshold=0.1, fill_threshold=0.9, remote=False, no_compression=False):
146
+ clean_threshold=0.1, fill_threshold=0.9, remote=False, compression=True):
147
147
 
148
148
  # django environment
149
149
  if img_id is not None:
@@ -151,12 +151,6 @@ def main_helper(path_to_labels, img_id=None, friend_id=None, fill_holes=True,
151
151
  else:
152
152
  django_env = False
153
153
 
154
- # compression
155
- if no_compression:
156
- compression = False
157
- else:
158
- compression = True
159
-
160
154
  # final filenames
161
155
  filename, extension = os.path.splitext(path_to_labels)
162
156
  if extension == '.gz':
@@ -350,7 +344,7 @@ def init_remove_outlier(image_id, final_id, label_id, fill_holes=True):
350
344
  try:
351
345
  main_helper(final.pic.path, img_id=image_id, friend_id=final.friend,
352
346
  fill_holes=fill_holes, clean_threshold=label.delete_outliers, fill_threshold=label.fill_holes, remote=False,
353
- no_compression=(False if label.compression else True))
347
+ compression=label.compression)
354
348
  except Exception as e:
355
349
  print(traceback.format_exc())
356
350
 
@@ -377,7 +371,7 @@ if __name__ == '__main__':
377
371
  help='Remove outliers, e.g. 0.5 means that objects smaller than 50 percent of the size of the largest object will be removed')
378
372
  parser.add_argument('-f', '--fill_threshold', type=float, default=0.9,
379
373
  help='Fill holes, e.g. 0.5 means that all holes smaller than 50 percent of the entire label will be filled')
380
- parser.add_argument('-nc', '--no_compression', action='store_true', default=False,
374
+ parser.add_argument('-nc', '--no-compression', dest='compression', action='store_false',
381
375
  help='Disable compression of segmentation results')
382
376
  parser.add_argument('-iid','--img_id', type=str, default=None,
383
377
  help='Image ID within django environment/browser version')
@@ -42,7 +42,7 @@ class Biomedisa(object):
42
42
 
43
43
  def smart_interpolation(data, labelData, nbrw=10, sorw=4000, acwe=False, acwe_alpha=1.0, acwe_smooth=1, acwe_steps=3,
44
44
  path_to_data=None, path_to_labels=None, denoise=False, uncertainty=False, platform=None,
45
- allaxis=False, ignore='none', only='all', smooth=0, no_compression=False, return_hits=False,
45
+ allaxis=False, ignore='none', only='all', smooth=0, compression=True, return_hits=False,
46
46
  img_id=None, label_id=None, remote=False, queue=0, clean=None, fill=None):
47
47
 
48
48
  freeze_support()
@@ -73,12 +73,6 @@ def smart_interpolation(data, labelData, nbrw=10, sorw=4000, acwe=False, acwe_al
73
73
  else:
74
74
  bm.django_env = False
75
75
 
76
- # compression
77
- if no_compression:
78
- bm.compression = False
79
- else:
80
- bm.compression = True
81
-
82
76
  # disable file saving when called as a function
83
77
  if bm.data is not None:
84
78
  bm.path_to_data = None
@@ -149,19 +143,19 @@ def smart_interpolation(data, labelData, nbrw=10, sorw=4000, acwe=False, acwe_al
149
143
  bm.path_to_acwe = filename + '.acwe' + bm.final_image_type
150
144
  bm.path_to_uq = filename + '.uncertainty.tif'
151
145
 
152
- # data type
153
- if bm.data.dtype == 'uint8':
154
- pass
155
- elif bm.data.dtype == 'int8':
146
+ # data types
147
+ if bm.data.dtype == 'int8':
156
148
  bm.data = bm.data.astype(np.int16)
157
149
  bm.data += 128
158
150
  bm.data = bm.data.astype(np.uint8)
159
- else:
160
- bm.data = bm.data.astype(float)
151
+ elif bm.data.dtype != 'uint8':
152
+ bm.data = bm.data.astype(np.float32)
161
153
  bm.data -= np.amin(bm.data)
162
154
  bm.data /= np.amax(bm.data)
163
155
  bm.data *= 255.0
164
- bm.data = bm.data.astype(np.float32)
156
+ if bm.labelData.dtype in ['uint32','int64','uint64']:
157
+ print(f'Warning: Potential label loss during conversion from {bm.labelData.dtype} to int32.')
158
+ bm.labelData = bm.labelData.astype(np.int32)
165
159
 
166
160
  # denoise image data
167
161
  if bm.denoise:
@@ -332,7 +326,7 @@ if __name__ == '__main__':
332
326
  help='Smoothing steps of active contour')
333
327
  parser.add_argument('--acwe_steps', metavar='STEPS', type=int, default=3,
334
328
  help='Iterations of active contour')
335
- parser.add_argument('-nc', '--no_compression', action='store_true', default=False,
329
+ parser.add_argument('-nc', '--no-compression', dest='compression', action='store_false',
336
330
  help='Disable compression of segmentation results')
337
331
  parser.add_argument('-allx', '--allaxis', action='store_true', default=False,
338
332
  help='If pre-segmentation is not exlusively in xy-plane')
biomedisa/mesh.py CHANGED
@@ -29,6 +29,7 @@
29
29
 
30
30
  import os
31
31
  import numpy as np
32
+ import biomedisa
32
33
  from biomedisa.features.biomedisa_helper import load_data, unique_file_path
33
34
  from biomedisa.features.django_env import create_pid_object
34
35
  from vtk.util.numpy_support import vtk_to_numpy, numpy_to_vtk
@@ -167,8 +168,7 @@ def save_mesh(path_to_result, labels, x_res=1, y_res=1, z_res=1,
167
168
  mesh_final.attr[start:stop,0] = i+1
168
169
  mesh_final.save(path_to_result)
169
170
 
170
- def get_voxel_spacing(header, data, extension):
171
-
171
+ def get_voxel_spacing(header, extension):
172
172
  if extension == '.am':
173
173
  # read header as string
174
174
  b = header[0].tobytes()
@@ -176,21 +176,23 @@ def get_voxel_spacing(header, data, extension):
176
176
  s = b.decode("utf-8")
177
177
  except:
178
178
  s = b.decode("latin1")
179
-
180
179
  # get physical size from image header
180
+ lattice = re.search('define Lattice (.*)\n', s)
181
181
  bounding_box = re.search('BoundingBox (.*),\n', s)
182
- if bounding_box:
182
+ if bounding_box and lattice:
183
+ # get number of voxels
184
+ lattice = lattice.group(1)
185
+ xsh, ysh, zsh = lattice.split(' ')
186
+ xsh, ysh, zsh = float(xsh), float(ysh), float(zsh)
187
+ # get bounding box
183
188
  bounding_box = bounding_box.group(1)
184
189
  i0, i1, i2, i3, i4, i5 = bounding_box.split(' ')
185
-
186
- # voxel spacing
187
- zsh, ysh, xsh = data.shape
190
+ # calculate voxel spacing
188
191
  xres = (float(i1)-float(i0)) / xsh
189
192
  yres = (float(i3)-float(i2)) / ysh
190
193
  zres = (float(i5)-float(i4)) / zsh
191
194
  else:
192
195
  xres, yres, zres = 1, 1, 1
193
-
194
196
  elif extension in ['.hdr', '.mhd', '.mha', '.nrrd', '.nii', '.nii.gz']:
195
197
  xres, yres, zres = header.GetSpacing()
196
198
  elif extension == '.zip':
@@ -203,7 +205,6 @@ def get_voxel_spacing(header, data, extension):
203
205
  else:
204
206
  print('Warning: could not get voxel spacing. Using x_spacing, y_spacing, z_spacing = 1, 1, 1 instead.')
205
207
  xres, yres, zres = 1, 1, 1
206
-
207
208
  return xres, yres, zres
208
209
 
209
210
  def init_create_mesh(id):
@@ -324,7 +325,7 @@ def init_create_mesh(id):
324
325
  log=1, imageType=None, shortfilename='Invalid label data.')
325
326
  else:
326
327
  # get voxel spacing
327
- xres, yres, zres = get_voxel_spacing(header, data, extension)
328
+ xres, yres, zres = get_voxel_spacing(header, extension)
328
329
  print(f'Voxel spacing: x_spacing, y_spacing, z_spacing = {xres}, {yres}, {zres}')
329
330
 
330
331
  # create stl file
@@ -386,7 +387,7 @@ if __name__ == "__main__":
386
387
 
387
388
  # get voxel spacing
388
389
  if not all([bm.x_res, bm.y_res, bm.z_res]):
389
- x_res, y_res, z_res = get_voxel_spacing(header, bm.labels, extension)
390
+ x_res, y_res, z_res = get_voxel_spacing(header, extension)
390
391
  if not bm.x_res:
391
392
  bm.x_res = x_res
392
393
  if not bm.y_res:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: biomedisa
3
- Version: 24.5.23
3
+ Version: 24.8.1
4
4
  Summary: Segmentation of 3D volumetric image data
5
5
  Author: Philipp Lösel
6
6
  Author-email: philipp.loesel@anu.edu.au
@@ -33,17 +33,20 @@ License-File: LICENSE
33
33
  - [License](#license)
34
34
 
35
35
  ## Overview
36
- Biomedisa (https://biomedisa.info) is a free and easy-to-use open-source application for segmenting large volumetric images, e.g. CT and MRI scans, developed at [The Australian National University CTLab](https://ctlab.anu.edu.au/). Biomedisa's semi-automated segmentation is based on a smart interpolation of sparsely pre-segmented slices, taking into account the complete underlying image data. In addition, Biomedisa enables deep learning for the fully automated segmentation of series of similar samples. It can be used in combination with segmentation tools such as Amira/Avizo, ImageJ/Fiji and 3D Slicer. If you are using Biomedisa or the data for your research please cite: Lösel, P.D. et al. [Introducing Biomedisa as an open-source online platform for biomedical image segmentation.](https://www.nature.com/articles/s41467-020-19303-w) *Nat. Commun.* **11**, 5577 (2020).
36
+ Biomedisa (https://biomedisa.info) is a free and easy-to-use open-source application for segmenting large 3D volumetric images such as CT and MRI scans, developed at [The Australian National University CTLab](https://ctlab.anu.edu.au/). Biomedisa's smart interpolation of sparsely pre-segmented slices enables accurate semi-automated segmentation by considering the complete underlying image data. Additionally, Biomedisa enables deep learning for fully automated segmentation across similar samples and structures. It is compatible with segmentation tools like Amira/Avizo, ImageJ/Fiji and 3D Slicer. If you are using Biomedisa or the data for your research please cite: Lösel, P.D. et al. [Introducing Biomedisa as an open-source online platform for biomedical image segmentation.](https://www.nature.com/articles/s41467-020-19303-w) *Nat. Commun.* **11**, 5577 (2020).
37
37
 
38
38
  ## Hardware Requirements
39
- + One or more NVIDIA GPUs with compute capability 3.0 or higher or an Intel CPU
39
+ + One or more NVIDIA GPUs with compute capability 3.0 or higher.
40
40
 
41
41
  ## Installation (command-line based)
42
- + [Ubuntu 22.04 + CUDA + GPU (recommended)](https://github.com/biomedisa/biomedisa/blob/master/README/ubuntu2204_cuda11.8_gpu_cli.md)
43
- + [Ubuntu 22.04 + OpenCL + CPU (smart interpolation only and very slow)](https://github.com/biomedisa/biomedisa/blob/master/README/ubuntu2204_opencl_cpu_cli.md)
44
- + [Windows 10 + CUDA + GPU (recommended)](https://github.com/biomedisa/biomedisa/blob/master/README/windows10_cuda_gpu_cli.md)
45
- + [Windows 10 + OpenCL + GPU (easy to install but lacks features like allaxis, smoothing, uncertainty, optimized GPU memory usage)](https://github.com/biomedisa/biomedisa/blob/master/README/windows10_opencl_gpu_cli.md)
46
- + [Windows 10 + OpenCL + CPU (very slow)](https://github.com/biomedisa/biomedisa/blob/master/README/windows10_opencl_cpu_cli.md)
42
+ + [Ubuntu 22.04 + Smart Interpolation](https://github.com/biomedisa/biomedisa/blob/master/README/ubuntu2204_interpolation_cli.md)
43
+ + [Ubuntu 22.04 + Smart Interpolation + Deep Learning](https://github.com/biomedisa/biomedisa/blob/master/README/ubuntu2204_cuda11.8_gpu_cli.md)
44
+ + [Windows 10 + Smart Interpolation + Deep Learning](https://github.com/biomedisa/biomedisa/blob/master/README/windows10_cuda_gpu_cli.md)
45
+ + [Windows (WSL) + Smart Interpolation + Deep Learning](https://github.com/biomedisa/biomedisa/blob/master/README/windows_wsl.md)
46
+
47
+ ## Installation (3D Slicer extension)
48
+ + [Ubuntu 22.04 + Smart Interpolation + Deep Learning](https://github.com/biomedisa/biomedisa/blob/master/README/ubuntu2204_cuda11.8_gpu_slicer.md)
49
+ + [Windows 10 + Smart Interpolation](https://github.com/biomedisa/biomedisa/blob/master/README/windows10_cuda_gpu_slicer.md)
47
50
 
48
51
  ## Installation (browser based)
49
52
  + [Ubuntu 22.04](https://github.com/biomedisa/biomedisa/blob/master/README/ubuntu2204_cuda11.8.md)
@@ -52,6 +55,10 @@ Biomedisa (https://biomedisa.info) is a free and easy-to-use open-source applica
52
55
  + Download test data from our [gallery](https://biomedisa.info/gallery/)
53
56
 
54
57
  ## Revisions
58
+ 24.7.1
59
+ + 3D Slicer extension
60
+ + Prediction of large data block by block
61
+
55
62
  24.5.22
56
63
  + Pip is the preferred installation method
57
64
  + Commands, module names and imports have been changed to conform to the Pip standard
@@ -131,15 +138,14 @@ deep_learning(img_data, label_data, train=True, batch_size=12,
131
138
  ```
132
139
 
133
140
  #### Command-line based (training)
134
- Start training with a batch size of 12:
135
141
  ```
136
- python -m biomedisa.deeplearning C:\Users\%USERNAME%\Downloads\training_heart C:\Users\%USERNAME%\Downloads\training_heart_labels -t -bs=12
142
+ python -m biomedisa.deeplearning C:\Users\%USERNAME%\Downloads\training_heart C:\Users\%USERNAME%\Downloads\training_heart_labels -t
137
143
  ```
138
144
  Monitor training progress using validation data:
139
145
  ```
140
146
  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
141
147
  ```
142
- If running into ResourceExhaustedError due to out of memory (OOM), try to use a smaller batch size.
148
+ If running into ResourceExhaustedError due to out of memory (OOM), try to use a smaller batch size (e.g. -bs=12).
143
149
 
144
150
  #### Python example (prediction)
145
151
  ```python
@@ -175,7 +181,7 @@ from biomedisa.mesh import get_voxel_spacing, save_mesh
175
181
  data, header, extension = load_data('final.Head5.am', return_extension=True)
176
182
 
177
183
  # get voxel spacing
178
- x_res, y_res, z_res = get_voxel_spacing(header, data, extension)
184
+ x_res, y_res, z_res = get_voxel_spacing(header, extension)
179
185
  print(f'Voxel spacing: x_spacing, y_spacing, z_spacing = {x_res}, {y_res}, {z_res}')
180
186
 
181
187
  # save stl file
@@ -1,26 +1,26 @@
1
1
  biomedisa/__init__.py,sha256=hw4mzEjGFXm-vxus2DBfKFW0nKoG0ibL5SH6ShfchrY,1526
2
2
  biomedisa/__main__.py,sha256=a1--8vhtztWEloHVtbM43FZLCfrFo4BELgdsgtWE8ls,536
3
- biomedisa/deeplearning.py,sha256=UG5baX58CrO8YXe9pU6_Bp2OOvbC74LQw4S33HqM2iA,27828
4
- biomedisa/interpolation.py,sha256=R8UbBWt7vOuiQCPSeNIpEY0_yfQUg1oBfhAjXi91Hl4,17253
5
- biomedisa/mesh.py,sha256=glvpTN0PPByb5j2IbLCdWQtc5O4VT-Pwu3en8EaYyTo,15819
6
- biomedisa/features/DataGenerator.py,sha256=bGys6UZ0bnKb_k1Y3Spo6MNPk_goSAmptdZnI39smaw,12770
3
+ biomedisa/deeplearning.py,sha256=Tfi1iSpsYi9RetgJpff_-mHx_VxlDybHZqTBJURwTBM,27970
4
+ biomedisa/interpolation.py,sha256=i10aqwEl-wsVU_nQ-zyubhAs27NSKF4ial7LyhaBLv0,17273
5
+ biomedisa/mesh.py,sha256=8-iuVsrfW5JovaMrAez7qSxv1LCU3eiqOdik0s0DV1w,16062
6
+ biomedisa/features/DataGenerator.py,sha256=MYPSY9-ssMwPx9UOI_ZfE7_5rddOSn4aHbVQ0HtYQVA,12757
7
7
  biomedisa/features/DataGeneratorCrop.py,sha256=23R4Z-8tB1CsjYTYfhHGovlJpAny_q9OV9hq8kc2GJg,5454
8
8
  biomedisa/features/PredictDataGenerator.py,sha256=JH8SPGQm-Y7_Drec2fw3jBUupvpIkQ1FvkDXP7mUjDY,4074
9
9
  biomedisa/features/PredictDataGeneratorCrop.py,sha256=HF5tJbGtlJMHr7lMT9IiIdLG2CTjXstbKoOjlZJ93Is,3431
10
10
  biomedisa/features/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- biomedisa/features/active_contour.py,sha256=n5_vAD8jvQjU6fQ6A9hxjSmtkLLo_1fl0S5q1H2pmVg,18096
11
+ biomedisa/features/active_contour.py,sha256=FnPuvYck_KL4xYRFqwzm4Grdm288EdlcLFt88E0OtqA,17938
12
12
  biomedisa/features/assd.py,sha256=q9NUQXEoA4Pi3d8b5fmys615CWu06Sm0N9-OGwJOFnw,6537
13
- biomedisa/features/biomedisa_helper.py,sha256=iLbt4RpCU3EK51uiMefkM0321AgBdeLgrT-X4d--YJY,32250
14
- biomedisa/features/create_slices.py,sha256=tLDJmuJFN8teTiCYvMauExfVzT2ZUF28VcPXpo4sOsE,13001
15
- biomedisa/features/crop_helper.py,sha256=si72n9Q-C7U0cXYOD9Ux2UqIbZdXbZSOARBYDeqRggI,24533
13
+ biomedisa/features/biomedisa_helper.py,sha256=oIsOmIJ8xUQVwgbzMgw65dXcZmzwePpFQoIdbgLTnF8,32727
14
+ biomedisa/features/create_slices.py,sha256=uSDH1OcEYc5BFPZHSy3UpS4P2DuoVnxOZ-l7wmyT_Po,13108
15
+ biomedisa/features/crop_helper.py,sha256=5do03z_DT13qWRR6IGtkFn4BNaw0mWmUXgg3Lk-U6QY,24597
16
16
  biomedisa/features/curvop_numba.py,sha256=AjKQJcUBoURTB8pq1HmugQYpBwBELthhcEu51_r_xPI,7049
17
17
  biomedisa/features/django_env.py,sha256=pdiPcBpqu1BWuyvh-palIGVwHFaY-leQ4Gatlbm8hIg,8942
18
- biomedisa/features/keras_helper.py,sha256=muPwb_W7O63exzWACJ4oLdAc-AQitcxLeNwgHvxyhuE,50488
18
+ biomedisa/features/keras_helper.py,sha256=Y48N8VizQ2F7yrFzdUPOIFS19wm8fFWguQJqVFLVHWA,57637
19
19
  biomedisa/features/nc_reader.py,sha256=RoRMwu3ELSNfoV3qZtaT2OWACnXb2EhNFu_DAF1T93o,7406
20
20
  biomedisa/features/pid.py,sha256=Jmn1VIp0fBlgBrqZ-yUIQVVb5-NAxNBdibXALVr2PPI,2545
21
21
  biomedisa/features/process_image.py,sha256=VtS3fGDvglqJiiJLPK1toe76J58j914NJ8XQKg3CRwo,11091
22
22
  biomedisa/features/pycuda_test.py,sha256=UGAGIz_dgcCJkzjyCqnMlflp-WJPzpCtFQmE9C5DwIo,3275
23
- biomedisa/features/remove_outlier.py,sha256=XhbFPkazMmEUZiP0FERdCkrXaLhwO095x4wcn-B3SdU,16756
23
+ biomedisa/features/remove_outlier.py,sha256=C2m-Wsw-n3q8Ft21SGNwEd3wDU_T1ghqQ5hldwU_rqI,16627
24
24
  biomedisa/features/split_volume.py,sha256=UgMpHhZPvH90xFo-mJ0Oc0tBXbrf8FQF0kzVySAlO8g,8917
25
25
  biomedisa/features/amira_to_np/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
26
  biomedisa/features/amira_to_np/amira_data_stream.py,sha256=JrZTyKP01CKDFB5d9BlGtSFwBgoAo0AJeAmn3pADH88,32618
@@ -37,8 +37,8 @@ biomedisa/features/random_walk/pyopencl_large.py,sha256=q79AxG3p3qFjxfiAZfUK9I5B
37
37
  biomedisa/features/random_walk/pyopencl_small.py,sha256=opNlS-qzOa9qWafBNJdvf6r1aRAFf7_JXf6ISDnkdXE,17068
38
38
  biomedisa/features/random_walk/rw_large.py,sha256=ZnITvk00Y11ZZlGuBRaJO1EwU0wYBdEwdpj9vvXCqF4,19805
39
39
  biomedisa/features/random_walk/rw_small.py,sha256=RPzZe24YrEwYelJukDjvqaoD_SyhgdriEi7uV3kZGXI,14881
40
- biomedisa-24.5.23.dist-info/LICENSE,sha256=sehayP6UhydNnmstfL4yFR3genMRdpuUh6uZVWJN1H0,14152
41
- biomedisa-24.5.23.dist-info/METADATA,sha256=XIEKdnTY54QTALYPtNambyN7NP7_e76S2Mo99Ubifv8,10475
42
- biomedisa-24.5.23.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
43
- biomedisa-24.5.23.dist-info/top_level.txt,sha256=opsf1Eb4vCguPSxev4HHSeiUKCccT_C_RcUCdAYbHWQ,10
44
- biomedisa-24.5.23.dist-info/RECORD,,
40
+ biomedisa-24.8.1.dist-info/LICENSE,sha256=sehayP6UhydNnmstfL4yFR3genMRdpuUh6uZVWJN1H0,14152
41
+ biomedisa-24.8.1.dist-info/METADATA,sha256=GRHftPc4P9kZG5mgWe0KYpu-QMYWYBg2mSJqKuVitiE,10569
42
+ biomedisa-24.8.1.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
43
+ biomedisa-24.8.1.dist-info/top_level.txt,sha256=opsf1Eb4vCguPSxev4HHSeiUKCccT_C_RcUCdAYbHWQ,10
44
+ biomedisa-24.8.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (73.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5