All Projects → qsyao → cuda_spatial_deform

qsyao / cuda_spatial_deform

Licence: other
A fast tool to do image augmentation on GPU(especially elastic_deform), can be helpful to research on Medical Image.

Programming Languages

Cuda
1817 projects
python
139335 projects - #7 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to cuda spatial deform

clinicadl
Framework for the reproducible processing of neuroimaging data with deep learning methods
Stars: ✭ 114 (-0.87%)
Mutual labels:  medical-imaging
fuse-med-ml
A python framework accelerating ML based discovery in the medical field by encouraging code reuse. Batteries included :)
Stars: ✭ 66 (-42.61%)
Mutual labels:  medical-imaging
modelhub
A collection of deep learning models with a unified API.
Stars: ✭ 59 (-48.7%)
Mutual labels:  medical-imaging
NMRI
2D Fourier Transform of Nuclear Magnetic Resonance Imaging raw data
Stars: ✭ 13 (-88.7%)
Mutual labels:  medical-imaging
GMIC
An interpretable classifier for high-resolution breast cancer screening images utilizing weakly supervised localization
Stars: ✭ 106 (-7.83%)
Mutual labels:  medical-imaging
Brain-MRI-Segmentation
Smart India Hackathon 2019 project given by the Department of Atomic Energy
Stars: ✭ 29 (-74.78%)
Mutual labels:  medical-imaging
eye-tracker-setup
👀 Tobii Eye Tracker 4C Setup
Stars: ✭ 24 (-79.13%)
Mutual labels:  medical-imaging
Fundus Review
Official website of our paper: Applications of Deep Learning in Fundus Images: A Review. Newly-released datasets and recently-published papers will be updated regularly.
Stars: ✭ 64 (-44.35%)
Mutual labels:  medical-imaging
survey-computer-vision-2021
2021年计算机视觉技术综述分类汇总
Stars: ✭ 54 (-53.04%)
Mutual labels:  medical-imaging
clara-dicom-adapter
DICOM Adapter is a component of the Clara Deploy SDK which facilitates integration with DICOM compliant systems, enables ingestion of imaging data, helps triggering of jobs with configurable rules and offers pushing the output of jobs to PACS systems.
Stars: ✭ 31 (-73.04%)
Mutual labels:  medical-imaging
ITKSphinxExamples
Cookbook examples for the Insight Toolkit documented with Sphinx
Stars: ✭ 48 (-58.26%)
Mutual labels:  medical-imaging
medSeg
Medical Image Segmentation Toolkit based on PaddlePaddle - 基于paddle的医学影像分割框架
Stars: ✭ 88 (-23.48%)
Mutual labels:  medical-imaging
dwv-vue
Medical image viewer using DWV (DICOM Web Viewer) and Vue.js.
Stars: ✭ 66 (-42.61%)
Mutual labels:  medical-imaging
RNiftyReg
An R interface to the NiftyReg medical image registration library
Stars: ✭ 32 (-72.17%)
Mutual labels:  medical-imaging
discolight
discolight is a robust, flexible and infinitely hackable library for generating image augmentations ✨
Stars: ✭ 25 (-78.26%)
Mutual labels:  image-augmentation
2D-and-3D-Deep-Autoencoder
Convolutional AutoEncoder application on MRI images
Stars: ✭ 57 (-50.43%)
Mutual labels:  medical-imaging
dicomifier
A medical image converter
Stars: ✭ 22 (-80.87%)
Mutual labels:  medical-imaging
medical image segmentation
Medical image segmentation ( Eye vessel segmentation)
Stars: ✭ 90 (-21.74%)
Mutual labels:  medical-imaging
VNet
Prostate MR Image Segmentation 2012
Stars: ✭ 54 (-53.04%)
Mutual labels:  medical-imaging
angiodysplasia-segmentation
Wining solution and its further development for MICCAI 2017 Endoscopic Vision Challenge Angiodysplasia Detection and Localization
Stars: ✭ 76 (-33.91%)
Mutual labels:  medical-imaging

Cuda_Spatial_Deform

A fast tool to do image augmentation by CUDA on GPU(especially elastic deformation), can be helpful to research on Medical Image Analysis.

Motivation

  • When the size of image is too large, it takes a lot of time(much more than forward and backward computation say in U_Net), especially for 3D image(like CT).
  • Elastic deformation on CPU is too slow.
  • Doing Sptial_Deform by muti-processing consumes of too much CPU resources, to which most GPU servers(like 32 cores with 4 gpus) can not afford.

Implementation Overview

  • Doing Spation_Deform on GPU instead of CPU, greatly saving CPU resources.
  • Very Fast, speed up 25x for rotation, 45x for elastic_deformation.
  • Support many types of spatial deform: flip, rotate, scale, translate, elastic_deformation.
  • Support many rules of map_coordinates: mirror, constant, reflect, wrap, nearest.
  • Doing Spatial_Deform by doing calculations of coordinates, all transformations get combined before they are applied to the image
  • Implement map_coordinates by linear interpolation(for image) and the nearest interpolation(for labels).
  • Unit test passes when over 99% pixels has L1_loss < 1e-3.
  • Users can fetch coordinates from CUDA and do cubic interpolation at CPU by scipy.map_coordinates(order = 3)

Speed Test

Test on 3D image , shape = [48, 240, 240]

Time(ms) Rotate Elastic
CUDA 14 40
CPU 304 1821

Citation

If you use our code, please cite our paper:

Chao Huang, Hu Han, Qingsong Yao, Shankuan Zhu, S. Kevin Zhou. , 3D U2-Net: A 3D Universal U-Net for Multi-Domain Medical Image Segmentation, MICCAI 2019.

How to Use

CMake

cd cuda_backend
cmake -D CUDA_TOOLKIT_ROOT_DIR=/path/to/cuda .
make -j8

Set_Config

# Import cuda_spation_deform Handle
from cuda_spatial_deform import Cuda_Spatial_Deform

# Init Handle
cuda_handle = Cuda_Spatial_Deform(array_image.shape, mode="constant")
'''
    Shape: cuda_backend will malloc according to shape
    RGB: bool (Only Support 2D-RGB)
    mode: The rules of map_coordinates. Reference  to  https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html
    cval: default is 0.0. Only be useful when mode == 'constant'
    id_gpu: choose the number of GPU
'''

# Choose your Rules of spatial_deform

# cuda_handle.scale(0.5)
# cuda_handle.flip(do_y=True, do_x=True, do_z=True)
# cuda_handle.translate(100, 100, 20)
# cuda_handle.rotate(0.75 * np.pi, 0.75 * np.pi, 0.75 * np.pi)
cuda_handle.elastic(sigma=12., alpha=200., mode='constant')
cuda_handle.end_flag()

DO augmentation

Warning: The numpy array that python frontend deliverd to the cuda backend must be continuous and have the correct order of dimensions in the real memory. So if you want to use function(transpose) to change the shape of array, you must use array.transpose().copy(). Info: There are two step to do augmentation. You can lookup the functions in doc.md.

  1. Deform coordinates stored in cuda backend by computation flow definated above.
  2. Interpolate the input array with coordinates
  3. (optional) Reset the coordinates.
# The shape must be equal to cuda_handle.shape
array_image = load_np_array(data_pth)
output = cuda_handle.augment(array_image, order=1)
# done_list will list the translations actually done
done_list = output[1]
output_array = output[0]

Interpolate images with the same deformed coordinates

You can look up these functions in doc.md

  1. Define your computation flow
  2. call cuda_handle.deform_coords
  3. call cuda_handle.interpolate
# define your computation flow
labels = cuda_handle.deform_coords()
for img in imgs_list:
    output = cuda_handle.interpolate(img, order=1)

Example_Image

Flip

Flip

Rotate

Rotate

Translate

Translate

Scale

Scale

Elastic_Deform

Elastic_Deform

Reference

batchgenerators

scipy

The elastic deformation approach is described in

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].