CUDA Spatial Deform by Qingsong Yao

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

Authors:Qingsong Yao worked as an intern in system group of Microsoft research Asia for one year, practicing CUDA programming.


  1. 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).
  2. Elastic deformation on CPU is too slow.
  3. 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

  1. Doing Spation_Deform on GPU instead of CPU, greatly saving CPU resources.
  2. Very Fast, speed up 25x for rotation, 45x for elastic_deformation.
  3. Support many types of spatial deform: flip, rotate, scale, translate, elastic_deformation.
  4. Support many rules of map_coordinates: mirror, constant, reflect, wrap, nearest.
  5. Doing Spatial_Deform by doing calculations of coordinates, all transformations get combined before they are applied to the image
  6. Implement map_coordinates by linear interpolation(for image) and the nearest interpolation(for labels).
  7. Users can fetch coordinates from CUDA and do cubic interpolation at CPU by scipy.map_coordinates(order = 3)


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.