SynthShapes.shapes
Overview
The SynthShapes.shapes module provides a comprehensive toolkit for generating
geometric shapes and patterns, tailored for synthetic image generation in
biomedical imaging and beyond. This module supports a variety of 2D and 3D
shapes with customizable parameters, enabling users to create realistic and
diverse datasets for machine learning and computer vision applications.
Features
-
Shape Generators: Includes predefined methods for creating common geometric shapes like spheres, stars, toroids, rectangles, spheres, and cubes.
-
Customizability: Allows fine-tuning of parameters such as size, position, orientation, and intensity for each shape.
-
Multi-shape Compositions: Supports combining multiple shapes into a single image for more complex synthetic data.
-
Label Maps: Since texturized data is synthesized from semantic label maps, one-hot encoded labels are easily retreived for semantic segmentation workflows.
MultiLobedBlobConfig
dataclass
MultiLobedBlobConfig(axis_length=cc.RandInt.make(make_range(2, cc.RandInt(3, 6))), blob_density=cc.Fixed(0.05), n_blobs=cc.RandInt(10, 25), n_lobes=cc.RandInt(1, 5), sharpness=cc.Uniform(1, 3), jitter=cc.Uniform(0, 0.5), return_mask=True, device='cuda')
Configuration container for MultiLobedBlobBase.
| ATTRIBUTE | DESCRIPTION |
|---|---|
shape |
Size of the 3D volume (assumed to be cubic). Default is [128, 128, 128].
TYPE:
|
axis_length |
Range of the lengths for any given axis of the blob. Default is RandInt(3, 6).
TYPE:
|
blob_density |
Density of blobs in the volume. Default is Fixed(0.05).
TYPE:
|
n_blobs |
Maximum number of multi-lobed blobs. Default is RandInt(10, 25).
TYPE:
|
n_lobes |
Sampler range for the number of lobes per blob. Default is RandInt(1, 5).
TYPE:
|
sharpness |
Upper bound for factor controlling the squareness of the blobs. Note: +5 = mostly squares, 2 < sharpness < 4 = spheres, sharpness < 2 = stars. Default is Uniform(1, 3).
TYPE:
|
jitter |
Maximum amount of jitter/raggedness to apply to the shape. Default is Uniform(0, 0.5).
TYPE:
|
device |
Device to perform computations on. Default is 'cuda'.
TYPE:
|
MultiLobedBlobBase
Bases: Module
Base module for multi-lobed blob operations.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Configuration container for blob parameters.
TYPE:
|
Base module for multi-lobed blob operations.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Configuration container for blob parameters.
TYPE:
|
Source code in SynthShapes/shapes.py
sample_axis_lengths
Sample the axis lengths for all dimensions of a blob.
| RETURNS | DESCRIPTION |
|---|---|
axis_lengths
|
Axis lengths of the blob (D, H, W).
TYPE:
|
Source code in SynthShapes/shapes.py
sample_centroid_coords
Sample the coordinates of the blob's centroid.
| PARAMETER | DESCRIPTION |
|---|---|
axis_lengths
|
Axis lengths of the blob (depth, height, width).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
centroid_coords
|
Coordinates of the centroid (depth, height, width).
TYPE:
|
Source code in SynthShapes/shapes.py
check_overlap
Check if the newly sampled blob overlaps with existing blobs.
This function computes the euclidean distance between the centroid of the new blobs and those of the existing blobs. The distance is compared to the sum of the largest axes of the blob, to ensure it is larger, ensuring no overlap exists between the blobs.
| PARAMETER | DESCRIPTION |
|---|---|
axis_lengths
|
Axis lengths of the new blob (depth, height, width).
TYPE:
|
centroid_coords
|
Coordinates of the new blob's centroid (depth, height, width).
TYPE:
|
axes_list
|
A list of tuples representing the lengths of each axis for all blobs.
TYPE:
|
centroid_coords
|
A list of tuples representing the coordinates of the centroid of each existing blob.
TYPE:
|
Source code in SynthShapes/shapes.py
sample_nonoverlapping_geometries
Sample nonoverlapping bounding boxes by generating list of centers and axis lengths.
This method creates two lists (center coordinates and axes lengths) that will be used to describe the bounding boxes for each blob to be sampled.
| RETURNS | DESCRIPTION |
|---|---|
centers
|
List of tuples representing the centroid coordinates for each bounding box (centroid_coords)
TYPE:
|
axes_list
|
List of tuples representing the length of each 3 axes for each geometry
TYPE:
|
Source code in SynthShapes/shapes.py
make_shapes
Make shape labels.
| RETURNS | DESCRIPTION |
|---|---|
imprint_tensor
|
Blobs with unique integer labels.
TYPE:
|
Source code in SynthShapes/shapes.py
MultiLobedBlobSampler
Bases: MultiLobedBlobBase
PyTorch module to sample multi-lobed blob labels in a 3D tensor.
Inherits from MultiLobedBlobBase.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Configuration container for blob parameters.
TYPE:
|
PyTorch module to sample multi-lobed blob labels in a 3D tensor.
Inherits from MultiLobedBlobBase.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Configuration container for blob parameters.
TYPE:
|
Source code in SynthShapes/shapes.py
forward
Apply blob-sampling operation.
| RETURNS | DESCRIPTION |
|---|---|
shapes
|
Blobs with unique integer labels.
TYPE:
|
Source code in SynthShapes/shapes.py
MultiLobeBlobAugmentation
MultiLobeBlobAugmentation(config=MultiLobedBlobConfig, alpha=cc.Uniform(0.25, 0.75), intensity_shift=cc.Uniform(10, 20), augmentation=None, device='cuda')
Bases: MultiLobedBlobBase
PyTorch module to augment 3D data (C, D, H, W) by sampling and alpha-blending multi-lobed blobs.
Inherits from MultiLobedBlobBase.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Configuration container for blob parameters.
TYPE:
|
PyTorch module to augment 3D data (C, D, H, W) by sampling and alpha-blending multi-lobed blobs.
MultiLobedBlobBase.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Configuration container for blob parameters.
TYPE:
|
Source code in SynthShapes/shapes.py
forward
Apply blob augmentation to input tensor.
| PARAMETER | DESCRIPTION |
|---|---|
incoming_tensor
|
Background tensor to augment of shape (C, D, H, W)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
blended_blobs
|
Blobs alpha-blended into background.
TYPE:
|
Source code in SynthShapes/shapes.py
TorusBlobBase
TorusBlobBase(major_radius_range=[10, 20], minor_radius_range=[3, 6], n_blobs=cc.RandInt(10, 25), jitter=cc.Uniform(0, 0.5), device='cuda', shape=128)
Bases: Module
Base PyTorch module for torus blob operations.
| PARAMETER | DESCRIPTION |
|---|---|
major_radius_range
|
Range of lengths for the major radius of the torus. Default is [10, 20]
TYPE:
|
minor_radius_range
|
Range of lengths for the minor radius of the torus. Default is [3, 6].
TYPE:
|
n_blobs
|
Maximum number of tori to generate. Default is 10.
TYPE:
|
jitter
|
Maximum amount of jitter to apply to the shape. Default is 0.5.
TYPE:
|
device
|
Device to run the tensor operations ('cuda' or 'cpu'). Default is 'cuda'.
TYPE:
|
shape
|
Size of the 3D volume (assumed to be cubic). Default is 128.
TYPE:
|
Base PyTorch module for torus blob operations.
| PARAMETER | DESCRIPTION |
|---|---|
major_radius_range
|
Range of lengths for the major radius of the torus. Default is [10, 20]
TYPE:
|
minor_radius_range
|
Range of lengths for the minor radius of the torus. Default is [3, 6].
TYPE:
|
n_blobs
|
Maximum number of tori to generate. Default is 10.
TYPE:
|
jitter
|
Maximum amount of jitter to apply to the shape. Default is 0.5.
TYPE:
|
device
|
Device to run the tensor operations ('cuda' or 'cpu'). Default is 'cuda'.
TYPE:
|
shape
|
Size of the 3D volume (assumed to be cubic). Default is 128.
TYPE:
|
Source code in SynthShapes/shapes.py
sample_radii
Sample the major and minor axes radii.
| RETURNS | DESCRIPTION |
|---|---|
major_radius
|
The magnitude of the radius of the larger axis.
TYPE:
|
minor_radius
|
The magnitude of the radius of the smaller axis. |
Source code in SynthShapes/shapes.py
sample_centroid_coords
Sample the coordinates of the centroid.
| RETURNS | DESCRIPTION |
|---|---|
centroid_coords
|
Coordinates of the centroid (depth, height, width).
TYPE:
|
Source code in SynthShapes/shapes.py
check_overlap
Check if a newly sampled blob overlaps with existing blobs.
This function computes the euclidean distance between the centroid of a newly sampled blob, and the centroids of previously sampled blobs. It then checks if the distance is less than the sum of the radii, indicating an overlap between blobs.
| PARAMETER | DESCRIPTION |
|---|---|
major_radius
|
The radius of the largest dimension of the newly sampled blob.
TYPE:
|
centroid_coords
|
Coordinates of the centroid (depth, height, width).
TYPE:
|
radii_list
|
A list of tuples of the radii belonging to blobs that have already been sampled.
TYPE:
|
centers
|
A list of tuple of the centers belonging to blobs that have already been sampled.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
overlap_exists
|
Whether overlap exists.
TYPE:
|
Source code in SynthShapes/shapes.py
TorusBlobSampler
TorusBlobSampler(major_radius_range=[10, 20], minor_radius_range=[3, 6], n_blobs=cc.RandInt(10, 25), jitter=cc.Uniform(0, 0.5), device='cuda', shape=128, return_mask=True)
Bases: TorusBlobBase
PyTorch module to sample torus blob labels in a 3D tensor.
Inherits from TorusBlobBase.
| PARAMETER | DESCRIPTION |
|---|---|
major_radius_range
|
Range of lengths for the major radius of the torus. Default is [10, 20].
TYPE:
|
minor_radius_range
|
Range of lengths for the minor radius of the torus. Default is [3, 6].
TYPE:
|
n_blobs
|
Maximum number of tori to generate. Default is 10.
TYPE:
|
jitter
|
Maximum amount of jitter to apply to the shape. Default is 0.5.
TYPE:
|
device
|
Device to run the tensor operations ('cuda' or 'cpu'). Default is 'cuda'.
TYPE:
|
shape
|
Size of the 3D volume (assumed to be cubic). Default is 128.
TYPE:
|
PyTorch module to sample torus blob labels in a 3D tensor.
Inherits from TorusBlobBase.
| PARAMETER | DESCRIPTION |
|---|---|
major_radius_range
|
Range of lengths for the major radius of the torus. Default is [10, 20].
TYPE:
|
minor_radius_range
|
Range of lengths for the minor radius of the torus. Default is [3, 6].
TYPE:
|
n_blobs
|
Maximum number of tori to generate. Default is 10.
TYPE:
|
jitter
|
Maximum amount of jitter to apply to the shape. Default is 0.5.
TYPE:
|
device
|
Device to run the tensor operations ('cuda' or 'cpu'). Default is 'cuda'.
TYPE:
|
shape
|
Size of the 3D volume (assumed to be cubic). Default is 128.
TYPE:
|
Source code in SynthShapes/shapes.py
forward
Apply torus sampling operation.
| RETURNS | DESCRIPTION |
|---|---|
shapes
|
Tori with unique integer labels.
TYPE:
|
Source code in SynthShapes/shapes.py
TorusBlobAugmentation
TorusBlobAugmentation(shape=128, major_radius_range=[10, 20], minor_radius_range=[3, 6], n_blobs=cc.RandInt(10, 25), jitter=cc.Uniform(0, 0.5), return_mask=False, alpha=cc.Uniform(0.25, 0.75), intensity_shift=cc.Uniform(10, 20), augmentation=None, device='cuda')
Bases: TorusBlobBase
A module to augment 3D data (B, C, D, H, W) by sampling and alpha-blending tori.
Inherits from TorusBlobBase.
| PARAMETER | DESCRIPTION |
|---|---|
major_radius_range
|
Range of lengths for the major radius of the torus. Default is [10, 20].
TYPE:
|
minor_radius_range
|
Range of lengths for the minor radius of the torus. Default is [3, 6].
TYPE:
|
n_blobs
|
Maximum number of tori to generate. Default is 10.
TYPE:
|
jitter
|
Maximum amount of jitter to apply to the shape. Default is 0.5.
TYPE:
|
device
|
Device to run the tensor operations ('cuda' or 'cpu'). Default is 'cuda'.
TYPE:
|
shape
|
Size of the 3D volume (assumed to be cubic). Default is 128.
TYPE:
|
Source code in SynthShapes/shapes.py
forward
Apply torus augmentation to input tensor.
| PARAMETER | DESCRIPTION |
|---|---|
background_intensities
|
Background tensor to augment of shape (C, D, H, W)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
blended_tori
|
Tori alpha-blended into background.
TYPE:
|