biomedisa 24.8.7__py3-none-any.whl → 24.8.9__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/deeplearning.py CHANGED
@@ -95,6 +95,10 @@ def deep_learning(img_data, label_data=None, val_img_data=None, val_label_data=N
95
95
  # normalization
96
96
  bm.normalize = 1 if bm.normalization else 0
97
97
 
98
+ # patch normalization deactivates normalization of entire volume
99
+ if bm.patch_normalization:
100
+ bm.normalize = 0
101
+
98
102
  # use patch normalization instead of normalizing the entire volume
99
103
  if not bm.scaling:
100
104
  bm.normalize = 0
@@ -369,7 +373,7 @@ if __name__ == '__main__':
369
373
  parser.add_argument('path_to_images', type=str, metavar='PATH_TO_IMAGES',
370
374
  help='Location of image data (tarball, directory, or file)')
371
375
  parser.add_argument('path', type=str, metavar='PATH',
372
- help='Location of label data during training (tarball, directory, or file) or model for prediction (h5)')
376
+ help='Location of label data for training (tarball, directory, or file) or model for prediction (.h5)')
373
377
 
374
378
  # optional arguments
375
379
  g.add_argument('-p','--predict', action='store_true', default=False,
@@ -498,6 +502,8 @@ if __name__ == '__main__':
498
502
  help='Refine segmentation on full size data')
499
503
  parser.add_argument('-ext','--extension', type=str, default=None,
500
504
  help='Save data in formats like NRRD or TIFF using --extension=".nrrd"')
505
+ parser.add_argument('-ptm','--path_to_model', type=str, metavar='PATH', default=None,
506
+ help='Specify the model location for training')
501
507
  bm = parser.parse_args()
502
508
  bm.success = True
503
509
 
@@ -513,7 +519,8 @@ if __name__ == '__main__':
513
519
  bm.path_to_model = bm.path
514
520
  if bm.train:
515
521
  bm.path_to_labels = bm.path
516
- bm.path_to_model = bm.path_to_images + '.h5'
522
+ if bm.path_to_model is None:
523
+ bm.path_to_model = bm.path_to_images + '.h5'
517
524
 
518
525
  # django environment
519
526
  if bm.img_id is not None:
@@ -291,7 +291,7 @@ class DataGenerator(tf.keras.utils.Sequence):
291
291
 
292
292
  # patch normalization
293
293
  if self.patch_normalization:
294
- tmp_X = tmp_X.copy()
294
+ tmp_X = tmp_X.copy().astype(np.float32)
295
295
  for c in range(self.n_channels):
296
296
  tmp_X[:,:,:,c] -= np.mean(tmp_X[:,:,:,c])
297
297
  tmp_X[:,:,:,c] /= max(np.std(tmp_X[:,:,:,c]), 1e-6)
@@ -153,19 +153,26 @@ def load_cropping_training_data(normalize, img_list, label_list, x_scale, y_scal
153
153
  img = np.append(img_z,img_y,axis=0)
154
154
  img = np.append(img,img_x,axis=0)
155
155
 
156
- # normalize image data
156
+ # scale image data
157
157
  for c in range(channels):
158
158
  img[:,:,:,c] -= np.amin(img[:,:,:,c])
159
159
  img[:,:,:,c] /= np.amax(img[:,:,:,c])
160
- if normalization_parameters is None:
161
- normalization_parameters = np.zeros((2,channels))
162
- normalization_parameters[0,c] = np.mean(img[:,:,:,c])
163
- normalization_parameters[1,c] = np.std(img[:,:,:,c])
164
- elif normalize:
160
+
161
+ # normalize first validation image
162
+ if normalize and np.any(normalization_parameters):
163
+ for c in range(channels):
165
164
  mean, std = np.mean(img[:,:,:,c]), np.std(img[:,:,:,c])
166
165
  img[:,:,:,c] = (img[:,:,:,c] - mean) / std
167
166
  img[:,:,:,c] = img[:,:,:,c] * normalization_parameters[1,c] + normalization_parameters[0,c]
168
167
 
168
+ # get normalization parameters from first image
169
+ if normalization_parameters is None:
170
+ normalization_parameters = np.zeros((2,channels))
171
+ if normalize:
172
+ for c in range(channels):
173
+ normalization_parameters[0,c] = np.mean(img[:,:,:,c])
174
+ normalization_parameters[1,c] = np.std(img[:,:,:,c])
175
+
169
176
  # loop over list of images
170
177
  if any(img_list) or type(img_in) is list:
171
178
  number_of_images = len(img_names) if any(img_list) else len(img_in)
@@ -400,12 +400,6 @@ def load_training_data(bm, img_list, label_list, channels, img_in=None, label_in
400
400
  label = label_in
401
401
  label_names = ['label_1']
402
402
  label_dim = label.shape
403
- # no-scaling for list of images needs negative values as it encodes padded areas as -1
404
- label_dtype = label.dtype
405
- if label_dtype==np.uint8:
406
- label_dtype = np.int16
407
- elif label_dtype in [np.uint16, np.uint32]:
408
- label_dtype = np.int32
409
403
  label = set_labels_to_zero(label, bm.only, bm.ignore)
410
404
  if any([bm.x_range, bm.y_range, bm.z_range]):
411
405
  if len(label_names)>1:
@@ -461,28 +455,44 @@ def load_training_data(bm, img_list, label_list, channels, img_in=None, label_in
461
455
  if any([bm.x_range, bm.y_range, bm.z_range]) or bm.crop_data:
462
456
  img = img[argmin_z:argmax_z,argmin_y:argmax_y,argmin_x:argmax_x].copy()
463
457
 
464
- # scale/resize image data
465
- img = img.astype(np.float32)
458
+ # resize image data
466
459
  if bm.scaling:
460
+ img = img.astype(np.float32)
467
461
  img = img_resize(img, bm.z_scale, bm.y_scale, bm.x_scale)
468
462
 
469
- # normalize image data
470
- for c in range(channels):
471
- img[:,:,:,c] -= np.amin(img[:,:,:,c])
472
- img[:,:,:,c] /= np.amax(img[:,:,:,c])
473
- if normalization_parameters is None:
474
- normalization_parameters = np.zeros((2,channels))
475
- normalization_parameters[0,c] = np.mean(img[:,:,:,c])
476
- normalization_parameters[1,c] = np.std(img[:,:,:,c])
477
- elif bm.normalize:
463
+ # scale data to the range from 0 to 1
464
+ if not bm.patch_normalization:
465
+ img = img.astype(np.float32)
466
+ for c in range(channels):
467
+ img[:,:,:,c] -= np.amin(img[:,:,:,c])
468
+ img[:,:,:,c] /= np.amax(img[:,:,:,c])
469
+
470
+ # normalize first validation image
471
+ if bm.normalize and np.any(normalization_parameters):
472
+ img = img.astype(np.float32)
473
+ for c in range(channels):
478
474
  mean, std = np.mean(img[:,:,:,c]), np.std(img[:,:,:,c])
479
475
  img[:,:,:,c] = (img[:,:,:,c] - mean) / std
480
476
  img[:,:,:,c] = img[:,:,:,c] * normalization_parameters[1,c] + normalization_parameters[0,c]
481
477
 
478
+ # get normalization parameters from first image
479
+ if normalization_parameters is None:
480
+ normalization_parameters = np.zeros((2,channels))
481
+ if bm.normalize:
482
+ for c in range(channels):
483
+ normalization_parameters[0,c] = np.mean(img[:,:,:,c])
484
+ normalization_parameters[1,c] = np.std(img[:,:,:,c])
485
+
482
486
  # pad data
483
487
  if not bm.scaling:
484
488
  img_data_list = [img]
485
489
  label_data_list = [label]
490
+ # no-scaling for list of images needs negative values as it encodes padded areas as -1
491
+ label_dtype = label.dtype
492
+ if label_dtype==np.uint8:
493
+ label_dtype = np.int16
494
+ elif label_dtype in [np.uint16, np.uint32]:
495
+ label_dtype = np.int32
486
496
 
487
497
  # loop over list of images
488
498
  if any(img_list) or type(img_in) is list:
@@ -530,13 +540,17 @@ def load_training_data(bm, img_list, label_list, channels, img_in=None, label_in
530
540
  raise InputError()
531
541
  if bm.crop_data:
532
542
  a = np.copy(a[argmin_z:argmax_z,argmin_y:argmax_y,argmin_x:argmax_x], order='C')
533
- a = a.astype(np.float32)
534
543
  if bm.scaling:
544
+ a = a.astype(np.float32)
535
545
  a = img_resize(a, bm.z_scale, bm.y_scale, bm.x_scale)
536
- for c in range(channels):
537
- a[:,:,:,c] -= np.amin(a[:,:,:,c])
538
- a[:,:,:,c] /= np.amax(a[:,:,:,c])
539
- if bm.normalize:
546
+ if not bm.patch_normalization:
547
+ a = a.astype(np.float32)
548
+ for c in range(channels):
549
+ a[:,:,:,c] -= np.amin(a[:,:,:,c])
550
+ a[:,:,:,c] /= np.amax(a[:,:,:,c])
551
+ if bm.normalize:
552
+ a = a.astype(np.float32)
553
+ for c in range(channels):
540
554
  mean, std = np.mean(a[:,:,:,c]), np.std(a[:,:,:,c])
541
555
  a[:,:,:,c] = (a[:,:,:,c] - mean) / std
542
556
  a[:,:,:,c] = a[:,:,:,c] * normalization_parameters[1,c] + normalization_parameters[0,c]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: biomedisa
3
- Version: 24.8.7
3
+ Version: 24.8.9
4
4
  Summary: Segmentation of 3D volumetric image data
5
5
  Author: Philipp Lösel
6
6
  Author-email: philipp.loesel@anu.edu.au
@@ -23,7 +23,6 @@ License-File: LICENSE
23
23
  - [Installation (browser based)](#installation-browser-based)
24
24
  - [Download Data](#download-data)
25
25
  - [Revisions](#revisions)
26
- - [Quickstart](#quickstart)
27
26
  - [Smart Interpolation](#smart-interpolation)
28
27
  - [Deep Learning](#deep-learning)
29
28
  - [Mesh Generator](#mesh-generator)
@@ -37,41 +36,26 @@ License-File: LICENSE
37
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).
38
37
 
39
38
  ## Hardware Requirements
40
- + One or more NVIDIA GPUs.
39
+ + One or more NVIDIA GPUs
41
40
 
42
41
  ## Installation (command-line based)
43
42
  + [Ubuntu 22/24 + Smart Interpolation](https://github.com/biomedisa/biomedisa/blob/master/README/ubuntu_interpolation_cli.md)
44
43
  + [Ubuntu 22/24 + Deep Learning](https://github.com/biomedisa/biomedisa/blob/master/README/ubuntu_deeplearning_cli.md)
45
44
  + [Ubuntu 22/24 + Smart Interpolation + Deep Learning](https://github.com/biomedisa/biomedisa/blob/master/README/ubuntu_cli.md)
46
- + [Windows 10/11 + Smart Interpolation + Deep Learning](https://github.com/biomedisa/biomedisa/blob/master/README/windows10_cuda_gpu_cli.md)
47
- + [Windows (WSL) + Smart Interpolation + Deep Learning](https://github.com/biomedisa/biomedisa/blob/master/README/windows_wsl.md)
45
+ + [Windows 10/11 + Smart Interpolation + Deep Learning](https://github.com/biomedisa/biomedisa/blob/master/README/windows_wsl.md)
48
46
 
49
47
  ## Installation (3D Slicer extension)
50
- + [Ubuntu 22.04 + Smart Interpolation + Deep Learning](https://github.com/biomedisa/biomedisa/blob/master/README/ubuntu2204_cuda11.8_gpu_slicer.md)
51
- + [Windows 10/11 + Smart Interpolation](https://github.com/biomedisa/biomedisa/blob/master/README/windows10_cuda_gpu_slicer.md)
48
+ + [Ubuntu 22/24](https://github.com/biomedisa/biomedisa/blob/master/README/ubuntu_slicer.md)
49
+ + [Windows 10/11](https://github.com/biomedisa/biomedisa/blob/master/README/windows_slicer.md)
52
50
 
53
51
  ## Installation (browser based)
54
- + [Ubuntu 22.04](https://github.com/biomedisa/biomedisa/blob/master/README/ubuntu2204_cuda11.8.md)
52
+ + [Ubuntu 22/24](https://github.com/biomedisa/biomedisa/blob/master/README/ubuntu_browser.md)
55
53
 
56
54
  ## Download Data
57
55
  + Download test data from our [gallery](https://biomedisa.info/gallery/)
58
56
 
59
57
  ## Revisions
60
- 24.7.1
61
- + 3D Slicer extension
62
- + Prediction of large data block by block
63
-
64
- 24.5.22
65
- + Pip is the preferred installation method
66
- + Commands, module names and imports have been changed to conform to the Pip standard
67
- + For versions <=23.9.1 please check [README](https://github.com/biomedisa/biomedisa/blob/master/README/deprecated/README_2023.09.1.md)
68
-
69
- ## Quickstart
70
- Install the Biomedisa package from the [Python Package Index](https://pypi.org/project/biomedisa/):
71
- ```
72
- python -m pip install -U biomedisa
73
- ```
74
- For smart interpolation and deep Learning modules, follow the installation instructions above.
58
+ + [Revisions](https://github.com/biomedisa/biomedisa/blob/master/README/revisions.md)
75
59
 
76
60
  ## Smart Interpolation
77
61
  + [Parameters and Examples](https://github.com/biomedisa/biomedisa/blob/master/README/smart_interpolation.md)
@@ -1,9 +1,9 @@
1
1
  biomedisa/__init__.py,sha256=hw4mzEjGFXm-vxus2DBfKFW0nKoG0ibL5SH6ShfchrY,1526
2
2
  biomedisa/__main__.py,sha256=a1--8vhtztWEloHVtbM43FZLCfrFo4BELgdsgtWE8ls,536
3
- biomedisa/deeplearning.py,sha256=r4YzFUss_2u6I7clIg9QD4DDx7bq8AFUnUgU1TCwS1c,28273
3
+ biomedisa/deeplearning.py,sha256=xLVe8buzjKRgzQL1cYK8bpv73iIwDwsR7_qKGfy4KDc,28600
4
4
  biomedisa/interpolation.py,sha256=i10aqwEl-wsVU_nQ-zyubhAs27NSKF4ial7LyhaBLv0,17273
5
5
  biomedisa/mesh.py,sha256=8-iuVsrfW5JovaMrAez7qSxv1LCU3eiqOdik0s0DV1w,16062
6
- biomedisa/features/DataGenerator.py,sha256=m7vsKkLhRsVF1BE3Y8YGVx-xx0DWjbBw_inIdZBq6pQ,13111
6
+ biomedisa/features/DataGenerator.py,sha256=CEC-5VKdsuLjq-qMJWXn7wT6AJF-qWa4zEqLvi5GsVg,13130
7
7
  biomedisa/features/DataGeneratorCrop.py,sha256=KtGqNadghOd59wIU9hATM_5YgSks95rS1kJ2lsSSX7w,6612
8
8
  biomedisa/features/PredictDataGenerator.py,sha256=JH8SPGQm-Y7_Drec2fw3jBUupvpIkQ1FvkDXP7mUjDY,4074
9
9
  biomedisa/features/PredictDataGeneratorCrop.py,sha256=HF5tJbGtlJMHr7lMT9IiIdLG2CTjXstbKoOjlZJ93Is,3431
@@ -12,10 +12,10 @@ biomedisa/features/active_contour.py,sha256=FnPuvYck_KL4xYRFqwzm4Grdm288EdlcLFt8
12
12
  biomedisa/features/assd.py,sha256=q9NUQXEoA4Pi3d8b5fmys615CWu06Sm0N9-OGwJOFnw,6537
13
13
  biomedisa/features/biomedisa_helper.py,sha256=oIsOmIJ8xUQVwgbzMgw65dXcZmzwePpFQoIdbgLTnF8,32727
14
14
  biomedisa/features/create_slices.py,sha256=uSDH1OcEYc5BFPZHSy3UpS4P2DuoVnxOZ-l7wmyT_Po,13108
15
- biomedisa/features/crop_helper.py,sha256=wNVbb1c6qNmJFbDJ2jrjjvqJw-EMLkJt1HLjEolMwAA,24089
15
+ biomedisa/features/crop_helper.py,sha256=ng0zc7csK23n1rr07adzxCS5OHvchqn20OI0EeRLzs8,24343
16
16
  biomedisa/features/curvop_numba.py,sha256=AjKQJcUBoURTB8pq1HmugQYpBwBELthhcEu51_r_xPI,7049
17
17
  biomedisa/features/django_env.py,sha256=LNrZ6rBHZ5I0FaWa5xN8K-ASPgq0r5dGDEUI56HzJxE,8615
18
- biomedisa/features/keras_helper.py,sha256=r9Knb5GlJCU3nQ601wBJF_9pOpdTL20KUO-x0xRP6WM,68853
18
+ biomedisa/features/keras_helper.py,sha256=kwMgi0djdsI2XRFQkvYAu2PQLQ5Bq2CZL3fcBJ8QfUI,69507
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
@@ -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.8.7.dist-info/LICENSE,sha256=sehayP6UhydNnmstfL4yFR3genMRdpuUh6uZVWJN1H0,14152
41
- biomedisa-24.8.7.dist-info/METADATA,sha256=7qJuRtt6SHy4MnZDyn-lqgSPXIjjSTrFZYRbXMbW5Mc,10708
42
- biomedisa-24.8.7.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
43
- biomedisa-24.8.7.dist-info/top_level.txt,sha256=opsf1Eb4vCguPSxev4HHSeiUKCccT_C_RcUCdAYbHWQ,10
44
- biomedisa-24.8.7.dist-info/RECORD,,
40
+ biomedisa-24.8.9.dist-info/LICENSE,sha256=sehayP6UhydNnmstfL4yFR3genMRdpuUh6uZVWJN1H0,14152
41
+ biomedisa-24.8.9.dist-info/METADATA,sha256=zmQIQWvfxBXdgi9PPaYM3o4VBE8aAFcFzkVBD4g2ulc,9933
42
+ biomedisa-24.8.9.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
43
+ biomedisa-24.8.9.dist-info/top_level.txt,sha256=opsf1Eb4vCguPSxev4HHSeiUKCccT_C_RcUCdAYbHWQ,10
44
+ biomedisa-24.8.9.dist-info/RECORD,,