A package for 3D volume augmentation with configurable parameters
Project description
Deformaug3d
Deformaug3d is a Python package for performing 3D volume augmentation with configurable parameters. Designed with simplicity and flexibility in mind, it allows you to augment 3D masks and volumes easily, making it a great choice for machine learning and data augmentation pipelines.
Features
- Configurable Augmentation Parameters: Define your own augmentation ranges or use sensible defaults.
- GPU Support: Leverage CUDA-enabled GPUs for efficient processing via PyTorch.
- Modular Design: Easily integrate with your existing code and extend functionality.
Installation
Requirements
- Python 3.6+
- PyTorch (with CUDA support if available)
Installing from PyPI
(Once published on PyPI, you can install MyPackage using pip)
pip install deformaug3d
Installing Locally
Clone the repository and install in editable mode:
git clone https://github.com/haifangong/deformaug3d.git
cd deformaug3d
pip install -e .
Usage
The package provides functions augmentation and aug_mask_and_img to perform and manage 3D augmentation. Here is an example of how to use these functions:
import torch
from mypackage.augmentation import aug_mask_and_img
# Create dummy data for demonstration
dummy_mask = torch.zeros((1, 1, 128, 128, 128))
dummy_img = torch.ones((1, 1, 128, 128, 128))
# Custom augmentation parameters (optional)
custom_aug_parameters = {
"rot_range_x": (-10.0, 10.0),
"rot_range_y": (-8.0, 8.0),
"rot_range_z": (-8.0, 8.0),
"scale_range_x": (0.95, 1.00),
"scale_range_y": (0.95, 1.00),
"scale_range_z": (0.95, 1.00),
"shift_range_x": (-0.02, 0.02),
"shift_range_y": (-0.02, 0.02),
"shift_range_z": (-0.02, 0.02),
"contrast": (1.0, 1.0),
"gray_shift": (0.0, 0.0),
"flip_x": False,
"flip_y": False,
"flip_z": False,
"elastic_alpha": [3.0, 3.0, 3.0], # For x, y, z axis
"smooth_num": 4,
"field_size": [10, 10, 10], # For x, y, z axis
"size_o": (128, 128, 128)
}
# Augment the dummy mask and image using the custom parameters
augmented_mask, augmented_img = aug_mask_and_img(
dummy_mask, dummy_img, aug_parameters=custom_aug_parameters
)
print("Augmentation complete!")
API Reference
aug_mask_and_img(mask, img, aug_parameters=None)
- mask: Input mask tensor.
- img: Input image/volume tensor.
- aug_parameters (dict, optional): Dictionary of augmentation parameters. If not provided, the default parameters are used.
- Returns: A tuple containing the augmented mask and image/volume as tensors.
augmentation(mask, vol, aug_model)
- mask: Input mask tensor.
- vol: Input volume tensor.
- aug_model: An instance of the augmentation model that applies transformations.
- Returns: A tuple
(mask_aug, vol_aug)containing the augmented mask and volume.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deformaug3d-0.1.1.tar.gz.
File metadata
- Download URL: deformaug3d-0.1.1.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dedad71b5804c1dfc73f05f83d75d97b7de510d6bebf7beffd5e9fe8ca2302b
|
|
| MD5 |
5b9b025f35fefde833bb8b2a32357d3d
|
|
| BLAKE2b-256 |
ae010674fe73c60a1975387be57c30b8439466a57e687fc010da207d08f62d1e
|
File details
Details for the file deformaug3d-0.1.1-py3-none-any.whl.
File metadata
- Download URL: deformaug3d-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc4ba033a9acc15ac4f629989bff792ffbbdd3cdddef7db37f17887de1ebe88a
|
|
| MD5 |
656f4825a3442db32c41fbf6fa24f5f2
|
|
| BLAKE2b-256 |
2e2162696e03d01e30d1bab852eeb59d0ab0de95b7624281364f6b23977871e3
|