biomedisa 2024.5.18__py3-none-any.whl → 2024.5.20__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. biomedisa/__init__.py +2 -6
  2. biomedisa/deeplearning.py +88 -91
  3. biomedisa/{biomedisa_features → features}/DataGenerator.py +1 -1
  4. biomedisa/{biomedisa_features → features}/DataGeneratorCrop.py +1 -1
  5. biomedisa/{biomedisa_features → features}/PredictDataGenerator.py +1 -1
  6. biomedisa/{biomedisa_features → features}/PredictDataGeneratorCrop.py +1 -1
  7. biomedisa/{biomedisa_features → features}/active_contour.py +15 -18
  8. biomedisa/{biomedisa_features → features}/assd.py +1 -1
  9. biomedisa/{biomedisa_features → features}/biomedisa_helper.py +107 -117
  10. biomedisa/{biomedisa_features → features}/create_slices.py +51 -60
  11. biomedisa/{biomedisa_features → features}/crop_helper.py +111 -116
  12. biomedisa/{biomedisa_features → features}/curvop_numba.py +1 -1
  13. biomedisa/{biomedisa_features → features}/django_env.py +9 -10
  14. biomedisa/{biomedisa_features → features}/keras_helper.py +143 -170
  15. biomedisa/{biomedisa_features → features}/nc_reader.py +1 -1
  16. biomedisa/{biomedisa_features → features}/pid.py +2 -2
  17. biomedisa/{biomedisa_features → features}/process_image.py +12 -14
  18. biomedisa/{biomedisa_features → features}/pycuda_test.py +2 -1
  19. biomedisa/{biomedisa_features → features}/random_walk/gpu_kernels.py +2 -1
  20. biomedisa/{biomedisa_features → features}/random_walk/pycuda_large.py +2 -2
  21. biomedisa/{biomedisa_features → features}/random_walk/pycuda_large_allx.py +2 -2
  22. biomedisa/{biomedisa_features → features}/random_walk/pycuda_small.py +2 -2
  23. biomedisa/{biomedisa_features → features}/random_walk/pycuda_small_allx.py +2 -2
  24. biomedisa/{biomedisa_features → features}/random_walk/pyopencl_large.py +1 -1
  25. biomedisa/{biomedisa_features → features}/random_walk/pyopencl_small.py +1 -1
  26. biomedisa/{biomedisa_features → features}/random_walk/rw_large.py +11 -11
  27. biomedisa/{biomedisa_features → features}/random_walk/rw_small.py +12 -12
  28. biomedisa/{biomedisa_features → features}/remove_outlier.py +13 -16
  29. biomedisa/features/split_volume.py +167 -0
  30. biomedisa/interpolation.py +10 -12
  31. biomedisa/mesh.py +9 -12
  32. {biomedisa-2024.5.18.dist-info → biomedisa-2024.5.20.dist-info}/METADATA +15 -16
  33. biomedisa-2024.5.20.dist-info/RECORD +44 -0
  34. biomedisa/biomedisa_features/split_volume.py +0 -274
  35. biomedisa-2024.5.18.dist-info/RECORD +0 -44
  36. /biomedisa/{biomedisa_features → features}/__init__.py +0 -0
  37. /biomedisa/{biomedisa_features → features}/amira_to_np/__init__.py +0 -0
  38. /biomedisa/{biomedisa_features → features}/amira_to_np/amira_data_stream.py +0 -0
  39. /biomedisa/{biomedisa_features → features}/amira_to_np/amira_grammar.py +0 -0
  40. /biomedisa/{biomedisa_features → features}/amira_to_np/amira_header.py +0 -0
  41. /biomedisa/{biomedisa_features → features}/amira_to_np/amira_helper.py +0 -0
  42. /biomedisa/{biomedisa_features → features}/random_walk/__init__.py +0 -0
  43. {biomedisa-2024.5.18.dist-info → biomedisa-2024.5.20.dist-info}/LICENSE +0 -0
  44. {biomedisa-2024.5.18.dist-info → biomedisa-2024.5.20.dist-info}/WHEEL +0 -0
  45. {biomedisa-2024.5.18.dist-info → biomedisa-2024.5.20.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  ##########################################################################
2
2
  ## ##
3
- ## Copyright (c) 2024 Philipp Lösel. All rights reserved. ##
3
+ ## Copyright (c) 2019-2024 Philipp Lösel. All rights reserved. ##
4
4
  ## ##
5
5
  ## This file is part of the open source project biomedisa. ##
6
6
  ## ##
@@ -27,7 +27,6 @@
27
27
  ##########################################################################
28
28
 
29
29
  import os
30
- BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
31
30
  try:
32
31
  from tensorflow.keras.optimizers.legacy import SGD
33
32
  except:
@@ -40,12 +39,12 @@ from tensorflow.keras.layers import (
40
39
  from tensorflow.keras import backend as K
41
40
  from tensorflow.keras.utils import to_categorical
42
41
  from tensorflow.keras.callbacks import Callback, ModelCheckpoint, EarlyStopping
43
- from biomedisa_features.DataGenerator import DataGenerator
44
- from biomedisa_features.PredictDataGenerator import PredictDataGenerator
45
- from biomedisa_features.biomedisa_helper import (
42
+ from biomedisa.features.DataGenerator import DataGenerator
43
+ from biomedisa.features.PredictDataGenerator import PredictDataGenerator
44
+ from biomedisa.features.biomedisa_helper import (
46
45
  img_resize, load_data, save_data, set_labels_to_zero, id_generator, unique_file_path)
47
- from biomedisa_features.remove_outlier import clean, fill
48
- from biomedisa_features.active_contour import activeContour
46
+ from biomedisa.features.remove_outlier import clean, fill
47
+ from biomedisa.features.active_contour import activeContour
49
48
  import matplotlib.pyplot as plt
50
49
  import SimpleITK as sitk
51
50
  import tensorflow as tf
@@ -60,13 +59,11 @@ import re
60
59
  import time
61
60
  import h5py
62
61
  import atexit
63
- import shutil
62
+ import tempfile
64
63
 
65
64
  class InputError(Exception):
66
- def __init__(self, message=None, img_names=[], label_names=[]):
65
+ def __init__(self, message=None):
67
66
  self.message = message
68
- self.img_names = img_names
69
- self.label_names = label_names
70
67
 
71
68
  def save_history(history, path_to_model, val_dice, train_dice):
72
69
  # summarize history for accuracy
@@ -307,37 +304,33 @@ def get_labels(arr, allLabels):
307
304
  final[arr == k] = allLabels[k]
308
305
  return final
309
306
 
310
- def read_img_list(img_list, label_list):
307
+ def read_img_list(img_list, label_list, temp_img_dir, temp_label_dir):
311
308
  # read filenames
312
- InputError.img_names = []
313
- InputError.label_names = []
314
309
  img_names, label_names = [], []
315
310
  for img_name, label_name in zip(img_list, label_list):
316
311
 
317
312
  # check for tarball
318
313
  img_dir, img_ext = os.path.splitext(img_name)
319
314
  if img_ext == '.gz':
320
- img_dir, img_ext = os.path.splitext(img_dir)
315
+ img_ext = os.path.splitext(img_dir)[1]
321
316
 
322
317
  label_dir, label_ext = os.path.splitext(label_name)
323
318
  if label_ext == '.gz':
324
- label_dir, label_ext = os.path.splitext(label_dir)
319
+ label_ext = os.path.splitext(label_dir)[1]
325
320
 
326
321
  if (img_ext == '.tar' and label_ext == '.tar') or (os.path.isdir(img_name) and os.path.isdir(label_name)):
327
322
 
328
323
  # extract files
329
324
  if img_ext == '.tar':
330
- img_dir = BASE_DIR + '/tmp/' + id_generator(40)
331
325
  tar = tarfile.open(img_name)
332
- tar.extractall(path=img_dir)
326
+ tar.extractall(path=temp_img_dir)
333
327
  tar.close()
334
- img_name = img_dir
328
+ img_name = temp_img_dir
335
329
  if label_ext == '.tar':
336
- label_dir = BASE_DIR + '/tmp/' + id_generator(40)
337
330
  tar = tarfile.open(label_name)
338
- tar.extractall(path=label_dir)
331
+ tar.extractall(path=temp_label_dir)
339
332
  tar.close()
340
- label_name = label_dir
333
+ label_name = temp_label_dir
341
334
 
342
335
  for data_type in ['.am','.tif','.tiff','.hdr','.mhd','.mha','.nrrd','.nii','.nii.gz','.zip','.mrc']:
343
336
  img_names += [file for file in glob.glob(img_name+'/**/*'+data_type, recursive=True) if not os.path.basename(file).startswith('.')]
@@ -345,15 +338,11 @@ def read_img_list(img_list, label_list):
345
338
  img_names = sorted(img_names)
346
339
  label_names = sorted(label_names)
347
340
  if len(img_names)==0 or len(label_names)==0 or len(img_names)!=len(label_names):
348
- if img_ext == '.tar' and os.path.exists(img_name):
349
- shutil.rmtree(img_name)
350
- if label_ext == '.tar' and os.path.exists(label_name):
351
- shutil.rmtree(label_name)
352
341
  if len(img_names)!=len(label_names):
353
342
  InputError.message = 'Number of image and label files must be the same'
354
- elif img_ext == '.tar':
343
+ elif img_ext == '.tar' and len(img_names)==0:
355
344
  InputError.message = 'Invalid image TAR file'
356
- elif label_ext == '.tar':
345
+ elif label_ext == '.tar' and len(label_names)==0:
357
346
  InputError.message = 'Invalid label TAR file'
358
347
  elif len(img_names)==0:
359
348
  InputError.message = 'Invalid image data'
@@ -365,165 +354,151 @@ def read_img_list(img_list, label_list):
365
354
  label_names.append(label_name)
366
355
  return img_names, label_names
367
356
 
368
- def remove_extracted_data(img_list, label_list):
369
- for img_name in img_list:
370
- if BASE_DIR + '/tmp/' in img_name:
371
- img_dir = img_name[:len(BASE_DIR + '/tmp/') + 40]
372
- if os.path.exists(img_dir):
373
- shutil.rmtree(img_dir)
374
- for label_name in label_list:
375
- if BASE_DIR + '/tmp/' in label_name:
376
- label_dir = label_name[:len(BASE_DIR + '/tmp/') + 40]
377
- if os.path.exists(label_dir):
378
- shutil.rmtree(label_dir)
379
-
380
357
  def load_training_data(normalize, img_list, label_list, channels, x_scale, y_scale, z_scale, no_scaling,
381
358
  crop_data, labels_to_compute, labels_to_remove, img_in=None, label_in=None,
382
359
  normalization_parameters=None, allLabels=None, header=None, extension='.tif',
383
360
  x_puffer=25, y_puffer=25, z_puffer=25):
384
361
 
385
- # read image lists
386
- if any(img_list):
387
- img_names, label_names = read_img_list(img_list, label_list)
388
- InputError.img_names = img_names
389
- InputError.label_names = label_names
390
-
391
- # load first label
392
- if any(img_list):
393
- label, header, extension = load_data(label_names[0], 'first_queue', True)
394
- if label is None:
395
- InputError.message = f'Invalid label data "{os.path.basename(label_names[0])}"'
396
- raise InputError()
397
- elif type(label_in) is list:
398
- label = label_in[0]
399
- else:
400
- label = label_in
401
- label_dim = label.shape
402
- label = set_labels_to_zero(label, labels_to_compute, labels_to_remove)
403
- label_values, counts = np.unique(label, return_counts=True)
404
- print(f'{os.path.basename(label_names[0])}:', 'Labels:', label_values[1:], 'Sizes:', counts[1:])
405
- if crop_data:
406
- argmin_z,argmax_z,argmin_y,argmax_y,argmin_x,argmax_x = predict_blocksize(label, x_puffer, y_puffer, z_puffer)
407
- label = np.copy(label[argmin_z:argmax_z,argmin_y:argmax_y,argmin_x:argmax_x], order='C')
408
- if not no_scaling:
409
- label = img_resize(label, z_scale, y_scale, x_scale, labels=True)
410
-
411
- # if header is not single data stream Amira Mesh falling back to Multi-TIFF
412
- if extension != '.am':
413
- if extension != '.tif':
414
- print(f'Warning! Please use -hf or --header_file="path_to_training_label{extension}" for prediction to save your result as "{extension}"')
415
- extension, header = '.tif', None
416
- elif len(header) > 1:
417
- print('Warning! Multiple data streams are not supported. Falling back to TIFF.')
418
- extension, header = '.tif', None
419
- else:
420
- header = header[0]
421
-
422
- # load first img
423
- if any(img_list):
424
- img, _ = load_data(img_names[0], 'first_queue')
425
- if img is None:
426
- InputError.message = f'Invalid image data "{os.path.basename(img_names[0])}"'
427
- raise InputError()
428
- elif type(img_in) is list:
429
- img = img_in[0]
430
- else:
431
- img = img_in
432
- if label_dim != img.shape:
433
- InputError.message = f'Dimensions of "{os.path.basename(img_names[0])}" and "{os.path.basename(label_names[0])}" do not match'
434
- raise InputError()
435
-
436
- # ensure images have channels >=1
437
- if len(img.shape)==3:
438
- z_shape, y_shape, x_shape = img.shape
439
- img = img.reshape(z_shape, y_shape, x_shape, 1)
440
- if channels is None:
441
- channels = img.shape[3]
442
- if channels != img.shape[3]:
443
- InputError.message = f'Number of channels must be {channels} for "{os.path.basename(img_names[0])}"'
444
- raise InputError()
445
-
446
- # crop data
447
- if crop_data:
448
- img = np.copy(img[argmin_z:argmax_z,argmin_y:argmax_y,argmin_x:argmax_x], order='C')
362
+ # make temporary directories
363
+ with tempfile.TemporaryDirectory() as temp_img_dir:
364
+ with tempfile.TemporaryDirectory() as temp_label_dir:
449
365
 
450
- # scale/resize image data
451
- img = img.astype(np.float32)
452
- if not no_scaling:
453
- img = img_resize(img, z_scale, y_scale, x_scale)
454
-
455
- # normalize image data
456
- for c in range(channels):
457
- img[:,:,:,c] -= np.amin(img[:,:,:,c])
458
- img[:,:,:,c] /= np.amax(img[:,:,:,c])
459
- if normalization_parameters is None:
460
- normalization_parameters = np.zeros((2,channels))
461
- normalization_parameters[0,c] = np.mean(img[:,:,:,c])
462
- normalization_parameters[1,c] = np.std(img[:,:,:,c])
463
- elif normalize:
464
- mean, std = np.mean(img[:,:,:,c]), np.std(img[:,:,:,c])
465
- img[:,:,:,c] = (img[:,:,:,c] - mean) / std
466
- img[:,:,:,c] = img[:,:,:,c] * normalization_parameters[1,c] + normalization_parameters[0,c]
467
-
468
- # loop over list of images
469
- if any(img_list) or type(img_in) is list:
470
- number_of_images = len(img_names) if any(img_list) else len(img_in)
471
-
472
- for k in range(1, number_of_images):
366
+ # read image lists
367
+ if any(img_list):
368
+ img_names, label_names = read_img_list(img_list, label_list, temp_img_dir, temp_label_dir)
473
369
 
474
- # append label
475
- if any(label_list):
476
- a, _ = load_data(label_names[k], 'first_queue')
477
- if a is None:
478
- InputError.message = f'Invalid label data "{os.path.basename(label_names[k])}"'
370
+ # load first label
371
+ if any(img_list):
372
+ label, header, extension = load_data(label_names[0], 'first_queue', True)
373
+ if label is None:
374
+ InputError.message = f'Invalid label data "{os.path.basename(label_names[0])}"'
479
375
  raise InputError()
376
+ elif type(label_in) is list:
377
+ label = label_in[0]
480
378
  else:
481
- a = label_in[k]
482
- label_dim = a.shape
483
- a = set_labels_to_zero(a, labels_to_compute, labels_to_remove)
484
- label_values, counts = np.unique(a, return_counts=True)
485
- print(f'{os.path.basename(label_names[k])}:', 'Labels:', label_values[1:], 'Sizes:', counts[1:])
379
+ label = label_in
380
+ label_dim = label.shape
381
+ label = set_labels_to_zero(label, labels_to_compute, labels_to_remove)
382
+ label_values, counts = np.unique(label, return_counts=True)
383
+ print(f'{os.path.basename(label_names[0])}:', 'Labels:', label_values[1:], 'Sizes:', counts[1:])
486
384
  if crop_data:
487
- argmin_z,argmax_z,argmin_y,argmax_y,argmin_x,argmax_x = predict_blocksize(a, x_puffer, y_puffer, z_puffer)
488
- a = np.copy(a[argmin_z:argmax_z,argmin_y:argmax_y,argmin_x:argmax_x], order='C')
385
+ argmin_z,argmax_z,argmin_y,argmax_y,argmin_x,argmax_x = predict_blocksize(label, x_puffer, y_puffer, z_puffer)
386
+ label = np.copy(label[argmin_z:argmax_z,argmin_y:argmax_y,argmin_x:argmax_x], order='C')
489
387
  if not no_scaling:
490
- a = img_resize(a, z_scale, y_scale, x_scale, labels=True)
491
- label = np.append(label, a, axis=0)
388
+ label = img_resize(label, z_scale, y_scale, x_scale, labels=True)
389
+
390
+ # if header is not single data stream Amira Mesh falling back to Multi-TIFF
391
+ if extension != '.am':
392
+ if extension != '.tif':
393
+ print(f'Warning! Please use -hf or --header_file="path_to_training_label{extension}" for prediction to save your result as "{extension}"')
394
+ extension, header = '.tif', None
395
+ elif len(header) > 1:
396
+ print('Warning! Multiple data streams are not supported. Falling back to TIFF.')
397
+ extension, header = '.tif', None
398
+ else:
399
+ header = header[0]
492
400
 
493
- # append image
401
+ # load first img
494
402
  if any(img_list):
495
- a, _ = load_data(img_names[k], 'first_queue')
496
- if a is None:
497
- InputError.message = f'Invalid image data "{os.path.basename(img_names[k])}"'
403
+ img, _ = load_data(img_names[0], 'first_queue')
404
+ if img is None:
405
+ InputError.message = f'Invalid image data "{os.path.basename(img_names[0])}"'
498
406
  raise InputError()
407
+ elif type(img_in) is list:
408
+ img = img_in[0]
499
409
  else:
500
- a = img_in[k]
501
- if label_dim != a.shape:
502
- InputError.message = f'Dimensions of "{os.path.basename(img_names[k])}" and "{os.path.basename(label_names[k])}" do not match'
410
+ img = img_in
411
+ if label_dim != img.shape:
412
+ InputError.message = f'Dimensions of "{os.path.basename(img_names[0])}" and "{os.path.basename(label_names[0])}" do not match'
503
413
  raise InputError()
504
- if len(a.shape)==3:
505
- z_shape, y_shape, x_shape = a.shape
506
- a = a.reshape(z_shape, y_shape, x_shape, 1)
507
- if a.shape[3] != channels:
508
- InputError.message = f'Number of channels must be {channels} for "{os.path.basename(img_names[k])}"'
414
+
415
+ # ensure images have channels >=1
416
+ if len(img.shape)==3:
417
+ z_shape, y_shape, x_shape = img.shape
418
+ img = img.reshape(z_shape, y_shape, x_shape, 1)
419
+ if channels is None:
420
+ channels = img.shape[3]
421
+ if channels != img.shape[3]:
422
+ InputError.message = f'Number of channels must be {channels} for "{os.path.basename(img_names[0])}"'
509
423
  raise InputError()
424
+
425
+ # crop data
510
426
  if crop_data:
511
- a = np.copy(a[argmin_z:argmax_z,argmin_y:argmax_y,argmin_x:argmax_x], order='C')
512
- a = a.astype(np.float32)
427
+ img = np.copy(img[argmin_z:argmax_z,argmin_y:argmax_y,argmin_x:argmax_x], order='C')
428
+
429
+ # scale/resize image data
430
+ img = img.astype(np.float32)
513
431
  if not no_scaling:
514
- a = img_resize(a, z_scale, y_scale, x_scale)
432
+ img = img_resize(img, z_scale, y_scale, x_scale)
433
+
434
+ # normalize image data
515
435
  for c in range(channels):
516
- a[:,:,:,c] -= np.amin(a[:,:,:,c])
517
- a[:,:,:,c] /= np.amax(a[:,:,:,c])
518
- if normalize:
519
- mean, std = np.mean(a[:,:,:,c]), np.std(a[:,:,:,c])
520
- a[:,:,:,c] = (a[:,:,:,c] - mean) / std
521
- a[:,:,:,c] = a[:,:,:,c] * normalization_parameters[1,c] + normalization_parameters[0,c]
522
- img = np.append(img, a, axis=0)
523
-
524
- # remove extracted data
525
- if any(img_list):
526
- remove_extracted_data(img_names, label_names)
436
+ img[:,:,:,c] -= np.amin(img[:,:,:,c])
437
+ img[:,:,:,c] /= np.amax(img[:,:,:,c])
438
+ if normalization_parameters is None:
439
+ normalization_parameters = np.zeros((2,channels))
440
+ normalization_parameters[0,c] = np.mean(img[:,:,:,c])
441
+ normalization_parameters[1,c] = np.std(img[:,:,:,c])
442
+ elif normalize:
443
+ mean, std = np.mean(img[:,:,:,c]), np.std(img[:,:,:,c])
444
+ img[:,:,:,c] = (img[:,:,:,c] - mean) / std
445
+ img[:,:,:,c] = img[:,:,:,c] * normalization_parameters[1,c] + normalization_parameters[0,c]
446
+
447
+ # loop over list of images
448
+ if any(img_list) or type(img_in) is list:
449
+ number_of_images = len(img_names) if any(img_list) else len(img_in)
450
+
451
+ for k in range(1, number_of_images):
452
+
453
+ # append label
454
+ if any(label_list):
455
+ a, _ = load_data(label_names[k], 'first_queue')
456
+ if a is None:
457
+ InputError.message = f'Invalid label data "{os.path.basename(label_names[k])}"'
458
+ raise InputError()
459
+ else:
460
+ a = label_in[k]
461
+ label_dim = a.shape
462
+ a = set_labels_to_zero(a, labels_to_compute, labels_to_remove)
463
+ label_values, counts = np.unique(a, return_counts=True)
464
+ print(f'{os.path.basename(label_names[k])}:', 'Labels:', label_values[1:], 'Sizes:', counts[1:])
465
+ if crop_data:
466
+ argmin_z,argmax_z,argmin_y,argmax_y,argmin_x,argmax_x = predict_blocksize(a, x_puffer, y_puffer, z_puffer)
467
+ a = np.copy(a[argmin_z:argmax_z,argmin_y:argmax_y,argmin_x:argmax_x], order='C')
468
+ if not no_scaling:
469
+ a = img_resize(a, z_scale, y_scale, x_scale, labels=True)
470
+ label = np.append(label, a, axis=0)
471
+
472
+ # append image
473
+ if any(img_list):
474
+ a, _ = load_data(img_names[k], 'first_queue')
475
+ if a is None:
476
+ InputError.message = f'Invalid image data "{os.path.basename(img_names[k])}"'
477
+ raise InputError()
478
+ else:
479
+ a = img_in[k]
480
+ if label_dim != a.shape:
481
+ InputError.message = f'Dimensions of "{os.path.basename(img_names[k])}" and "{os.path.basename(label_names[k])}" do not match'
482
+ raise InputError()
483
+ if len(a.shape)==3:
484
+ z_shape, y_shape, x_shape = a.shape
485
+ a = a.reshape(z_shape, y_shape, x_shape, 1)
486
+ if a.shape[3] != channels:
487
+ InputError.message = f'Number of channels must be {channels} for "{os.path.basename(img_names[k])}"'
488
+ raise InputError()
489
+ if crop_data:
490
+ a = np.copy(a[argmin_z:argmax_z,argmin_y:argmax_y,argmin_x:argmax_x], order='C')
491
+ a = a.astype(np.float32)
492
+ if not no_scaling:
493
+ a = img_resize(a, z_scale, y_scale, x_scale)
494
+ for c in range(channels):
495
+ a[:,:,:,c] -= np.amin(a[:,:,:,c])
496
+ a[:,:,:,c] /= np.amax(a[:,:,:,c])
497
+ if normalize:
498
+ mean, std = np.mean(a[:,:,:,c]), np.std(a[:,:,:,c])
499
+ a[:,:,:,c] = (a[:,:,:,c] - mean) / std
500
+ a[:,:,:,c] = a[:,:,:,c] * normalization_parameters[1,c] + normalization_parameters[0,c]
501
+ img = np.append(img, a, axis=0)
527
502
 
528
503
  # limit intensity range
529
504
  img[img<0] = 0
@@ -973,8 +948,6 @@ def load_prediction_data(path_to_img, channels, x_scale, y_scale, z_scale,
973
948
  # read image data
974
949
  if img is None:
975
950
  img, img_header = load_data(path_to_img, 'first_queue')
976
- InputError.img_names = [path_to_img]
977
- InputError.label_names = []
978
951
 
979
952
  # verify validity
980
953
  if img is None:
@@ -1147,7 +1120,7 @@ def predict_semantic_segmentation(bm, img, path_to_model,
1147
1120
  if extension == '.gz':
1148
1121
  extension = '.nii.gz'
1149
1122
  bm.path_to_final = os.path.splitext(bm.path_to_final)[0] + extension
1150
- if bm.django_env and not bm.remote and not bm.tmp_dir:
1123
+ if bm.django_env and not bm.remote and not bm.tarfile:
1151
1124
  bm.path_to_final = unique_file_path(bm.path_to_final)
1152
1125
 
1153
1126
  # handle amira header
@@ -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) 2023 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
  ## ##
@@ -34,7 +34,7 @@ if __name__ == "__main__":
34
34
  queue = sys.argv[1]
35
35
 
36
36
  # path to biomedisa
37
- BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
37
+ BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
38
38
 
39
39
  # wait for pid
40
40
  while not os.path.exists(BASE_DIR + f'/log/pid_{queue}'):
@@ -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,15 +27,13 @@
27
27
  ## ##
28
28
  ##########################################################################
29
29
 
30
- import os, sys
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)
34
- import numpy as np
35
- from biomedisa_features.biomedisa_helper import (load_data, save_data, unique_file_path,
30
+ import os
31
+ import biomedisa
32
+ from biomedisa.features.biomedisa_helper import (load_data, save_data, unique_file_path,
36
33
  img_to_uint8, smooth_img_3x3)
37
- from biomedisa_features.create_slices import create_slices
34
+ from biomedisa.features.create_slices import create_slices
38
35
  from shutil import copytree
36
+ import numpy as np
39
37
  import argparse
40
38
  import traceback
41
39
  import subprocess
@@ -61,7 +59,7 @@ def init_process_image(id, process=None):
61
59
 
62
60
  # get host information
63
61
  host = ''
64
- host_base = BASE_DIR
62
+ host_base = biomedisa.BASE_DIR
65
63
  subhost, qsub_pid = None, None
66
64
  if 'REMOTE_QUEUE_HOST' in config:
67
65
  host = config['REMOTE_QUEUE_HOST']
@@ -99,7 +97,7 @@ def init_process_image(id, process=None):
99
97
  if host:
100
98
 
101
99
  # command
102
- cmd = ['python3', host_base+'/biomedisa_features/process_image.py', img.pic.path.replace(BASE_DIR,host_base)]
100
+ cmd = ['python3', host_base+'/biomedisa/features/process_image.py', img.pic.path.replace(biomedisa.BASE_DIR,host_base)]
103
101
  cmd += [f'-iid={img.id}', '-r']
104
102
  if process == 'convert':
105
103
  cmd += ['-c']
@@ -110,7 +108,7 @@ def init_process_image(id, process=None):
110
108
  subprocess.Popen(['ssh', host, 'mkdir', '-p', host_base+'/private_storage/images/'+img.user.username]).wait()
111
109
 
112
110
  # send data to host
113
- success = send_data_to_host(img.pic.path, host+':'+img.pic.path.replace(BASE_DIR,host_base))
111
+ success = send_data_to_host(img.pic.path, host+':'+img.pic.path.replace(biomedisa.BASE_DIR,host_base))
114
112
 
115
113
  # qsub start
116
114
  if 'REMOTE_QUEUE_QSUB' in config and config['REMOTE_QUEUE_QSUB']:
@@ -133,14 +131,14 @@ def init_process_image(id, process=None):
133
131
  subprocess.Popen(cmd).wait()
134
132
 
135
133
  # check if aborted
136
- success = subprocess.Popen(['scp', host+':'+host_base+f'/log/pid_5', BASE_DIR+f'/log/pid_5']).wait()
134
+ success = subprocess.Popen(['scp', host+':'+host_base+f'/log/pid_5', biomedisa.BASE_DIR+f'/log/pid_5']).wait()
137
135
 
138
136
  # get result
139
137
  if success==0:
140
138
  # remove pid file
141
139
  subprocess.Popen(['ssh', host, 'rm', host_base+f'/log/pid_5']).wait()
142
140
 
143
- result_on_host = img.pic.path.replace(BASE_DIR,host_base)
141
+ result_on_host = img.pic.path.replace(biomedisa.BASE_DIR,host_base)
144
142
  result_on_host = result_on_host.replace(os.path.splitext(result_on_host)[1], suffix)
145
143
  success = subprocess.Popen(['scp', host+':'+result_on_host, path_to_result]).wait()
146
144
 
@@ -226,7 +224,7 @@ if __name__ == "__main__":
226
224
 
227
225
  # set pid
228
226
  if bm.remote:
229
- from biomedisa_features.django_env import create_pid_object
227
+ from biomedisa.features.django_env import create_pid_object
230
228
  create_pid_object(os.getpid(), True, 5, bm.img_id)
231
229
 
232
230
  # load data
@@ -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
  ## ##
@@ -82,3 +82,4 @@ if __name__ == "__main__":
82
82
 
83
83
  ctx.pop()
84
84
  del ctx
85
+
@@ -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
  ## ##
@@ -181,3 +181,4 @@ def _build_curvature_gpu():
181
181
  mod = SourceModule(code)
182
182
  kernel = mod.get_function("Funktion")
183
183
  return kernel
184
+
@@ -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
  ## ##
@@ -32,7 +32,7 @@ import numpy as np
32
32
  import pycuda.driver as cuda
33
33
  import pycuda.gpuarray as gpuarray
34
34
  from pycuda.compiler import SourceModule
35
- from biomedisa_features.random_walk.gpu_kernels import (_build_kernel_uncertainty,
35
+ from biomedisa.features.random_walk.gpu_kernels import (_build_kernel_uncertainty,
36
36
  _build_kernel_max, _build_kernel_fill, _build_update_gpu, _build_curvature_gpu)
37
37
 
38
38
  def reduceBlocksize(slices):
@@ -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
  ## ##
@@ -32,7 +32,7 @@ import numpy as np
32
32
  import pycuda.driver as cuda
33
33
  import pycuda.gpuarray as gpuarray
34
34
  from pycuda.compiler import SourceModule
35
- from biomedisa_features.random_walk.gpu_kernels import (_build_kernel_uncertainty,
35
+ from biomedisa.features.random_walk.gpu_kernels import (_build_kernel_uncertainty,
36
36
  _build_kernel_max, _build_kernel_fill, _build_update_gpu, _build_curvature_gpu)
37
37
 
38
38
  def reduceBlocksize(slices):
@@ -1,6 +1,6 @@
1
1
  ##########################################################################
2
2
  ## ##
3
- ## Copyright (c) 2023 Philipp Lösel. All rights reserved. ##
3
+ ## Copyright (c) 20019-2024 Philipp Lösel. All rights reserved. ##
4
4
  ## ##
5
5
  ## This file is part of the open source project biomedisa. ##
6
6
  ## ##
@@ -30,7 +30,7 @@ import numpy as np
30
30
  import pycuda.driver as cuda
31
31
  import pycuda.gpuarray as gpuarray
32
32
  from pycuda.compiler import SourceModule
33
- from biomedisa_features.random_walk.gpu_kernels import _build_kernel_fill
33
+ from biomedisa.features.random_walk.gpu_kernels import _build_kernel_fill
34
34
 
35
35
  def walk(data, slices, indices, indices_child, nbrw, sorw, name, ctx, queue):
36
36
 
@@ -1,6 +1,6 @@
1
1
  ##########################################################################
2
2
  ## ##
3
- ## Copyright (c) 2023 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
  ## ##
@@ -30,7 +30,7 @@ import numpy as np
30
30
  import pycuda.driver as cuda
31
31
  import pycuda.gpuarray as gpuarray
32
32
  from pycuda.compiler import SourceModule
33
- from biomedisa_features.random_walk.gpu_kernels import _build_kernel_fill
33
+ from biomedisa.features.random_walk.gpu_kernels import _build_kernel_fill
34
34
  import numba
35
35
 
36
36
  def walk(data, slices, indices_all, indices_child, nbrw, sorw, name, ctx, queue):
@@ -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) 2023 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
  ## ##