Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return_slicer=False)
seg_data = pad_patch(seg_data, self.patch_shape,
return_slicer=False)
# Run data augmentation
if data_aug:
img_data, seg_data = self.data_augmentation.run(img_data,
seg_data)
# If skipping blank is not active -> random crop
else:
# Access image and segmentation data
img = sample.img_data
seg = sample.seg_data
# If no data augmentation should be performed
# -> create Data Augmentation instance without augmentation methods
if not data_aug or self.data_augmentation is None:
cropping_data_aug = Data_Augmentation(cycles=1,
scaling=False, rotations=False,
elastic_deform=False, mirror=False,
brightness=False, contrast=False,
gamma=False, gaussian_noise=False)
else : cropping_data_aug = self.data_augmentation
# Configure the Data Augmentation instance to cropping
cropping_data_aug.cropping = True
cropping_data_aug.cropping_patch_shape = self.patch_shape
# Expand image dimension to simulate a batch with one image
img_data = np.expand_dims(img, axis=0)
seg_data = np.expand_dims(seg, axis=0)
# Run data augmentation and cropping
img_data, seg_data = cropping_data_aug.run(img_data, seg_data)
# Create tuple of preprocessed data
ready_data = list(zip(img_data, seg_data))
# Return preprocessed data tuple
def __init__(self, data_io, batch_size, subfunctions=[],
data_aug=Data_Augmentation(), prepare_subfunctions=False,
prepare_batches=False, analysis="patchwise-crop",
patch_shape=None):
# Parse Data Augmentation
if isinstance(data_aug, Data_Augmentation):
self.data_augmentation = data_aug
else:
self.data_augmentation = None
# Exception: Analysis parameter check
analysis_types = ["patchwise-crop", "patchwise-grid", "fullimage"]
if not isinstance(analysis, str) or analysis not in analysis_types:
raise ValueError('Non existent analysis type in preprocessing.')
# Exception: Patch-shape parameter check
if (analysis == "patchwise-crop" or analysis == "patchwise-grid") and \
not isinstance(patch_shape, tuple):
raise ValueError("Missing or wrong patch shape parameter for " + \
"patchwise analysis.")
def __init__(self, data_io, batch_size, subfunctions=[],
data_aug=Data_Augmentation(), prepare_subfunctions=False,
prepare_batches=False, analysis="patchwise-crop",
patch_shape=None):
# Parse Data Augmentation
if isinstance(data_aug, Data_Augmentation):
self.data_augmentation = data_aug
else:
self.data_augmentation = None
# Exception: Analysis parameter check
analysis_types = ["patchwise-crop", "patchwise-grid", "fullimage"]
if not isinstance(analysis, str) or analysis not in analysis_types:
raise ValueError('Non existent analysis type in preprocessing.')
# Exception: Patch-shape parameter check
if (analysis == "patchwise-crop" or analysis == "patchwise-grid") and \
not isinstance(patch_shape, tuple):
raise ValueError("Missing or wrong patch shape parameter for " + \
"patchwise analysis.")
# Parse parameter
self.data_io = data_io
self.batch_size = batch_size
self.subfunctions = subfunctions