Skip to content
Snippets Groups Projects

Synthetic collection generation

+ 14
8
@@ -197,6 +197,7 @@ def collection(
# Initialize the 3D array for the shape
collection = np.zeros((collection_shape[0], collection_shape[1], collection_shape[2]), dtype=np.uint8)
labels = np.zeros_like(collection)
# Fill the 3D array with synthetic blobs
@@ -225,10 +226,11 @@ def collection(
angle = rng.uniform(low = 0, high = max_rotation_degrees) # Sample rotation angle
axes = rng.choice([(0, 1), (0, 2), (1, 2)]) # Sample the two axes to rotate around
blob = scipy.ndimage.rotate(blob, angle, axes)
blob = scipy.ndimage.rotate(blob, angle, axes, order=0)
# Place synthetic object into the collection
# If positions are specified, place blob at one of the specified positions
collection_before = collection.copy()
if positions:
collection, placed, positions = specific_placement(collection, blob, positions)
@@ -237,17 +239,21 @@ def collection(
collection, placed = random_placement(collection, blob, rng)
# Break if blob could not be placed
if not placed:
if not placed:
break
# Update labels
new_labels = np.where(collection > collection_before, i, 0).astype(labels.dtype)
labels += new_labels
if not placed:
# Log error if not all num_objects could be placed (this line of code has to be here, otherwise it will interfere with tqdm progress bar)
log.error(f"Object #{i+1} could not be placed in the collection, so no more blobs are added. Collection contains {i}/{num_objects} objects.")
# Compute binary mask of collection based on Li thresholding
mask = collection > threshold_li(collection)
# # Compute binary mask of collection based on Li thresholding
# mask = collection > threshold_li(collection)
# Find connected components in the mask
CC = get_3d_cc(mask)
# # Find connected components in the mask
# CC = get_3d_cc(mask)
return collection, CC
\ No newline at end of file
return collection, labels
\ No newline at end of file
Loading