# Data augmentation library for 3D (US) medical images

**URL:** https://discourse.slicer.org/t/data-augmentation-library-for-3d-us-medical-images/8125
**Category:** Development
**Created:** [August 21, 2019, 5:29pm UTC](https://discourse.slicer.org/t/data-augmentation-library-for-3d-us-medical-images/8125 "2019-08-21T17:29:53Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![che85](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/che85/32/636_2.png) [@che85](https://discourse.slicer.org/u/che85)
#### Post date: [August 21, 2019, 5:29pm UTC](https://discourse.slicer.org/t/data-augmentation-library-for-3d-us-medical-images/8125/1 "2019-08-21T17:29:53Z")

</div>

Hi everyone,

we are working on some DeepLearning networks and we would like to do some data augmentation when exporting data from Slicer.

Do you guys have any plans for creating a library for supporting this kind of matter or does anyone know a good library or code chunks to start?

We are mainly interested in doing `affine` and `elastic` deformations as well as `intensity shift`.

P.S. We are using pytorch for training

I am thankful for any help.

Best  
Christian

---

<div class="post-metadata">

### Author: ![Prashant\_Pandey](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@Prashant\_Pandey](https://discourse.slicer.org/u/Prashant_Pandey)
#### Post date: [August 21, 2019, 8:27pm UTC](https://discourse.slicer.org/t/data-augmentation-library-for-3d-us-medical-images/8125/2 "2019-08-21T20:27:16Z")

</div>

I would check out Albumentations: [https://github.com/albu/albumentations](https://github.com/albu/albumentations)  
Haven’t used it myself but it does elastic and affine transformations.

Intensity shifts should be easily implementable in Pytorch using the basic Dataset classes: [https://pytorch.org/tutorials/beginner/data\_loading\_tutorial.html](https://pytorch.org/tutorials/beginner/data_loading_tutorial.html)

---

<div class="post-metadata">

### Author: ![JanWitowski](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/janwitowski/32/4512_2.png) [@JanWitowski](https://discourse.slicer.org/u/JanWitowski)
#### Post date: [August 22, 2019, 1:26am UTC](https://discourse.slicer.org/t/data-augmentation-library-for-3d-us-medical-images/8125/3 "2019-08-22T01:26:51Z")

</div>

As @Prashant_Pandey suggested, albumentations are a good choice. I have used them with success. Alternatively, if you want to implement elastic transformations yourself, this is a good starting point: [https://www.kaggle.com/bguberfain/elastic-transform-for-data-augmentation](https://www.kaggle.com/bguberfain/elastic-transform-for-data-augmentation)

Affine transformations (along with other standard are also part of default torchvision transforms: [https://pytorch.org/docs/stable/torchvision/transforms.html](https://pytorch.org/docs/stable/torchvision/transforms.html)

Also, as above, I wouldn’t augment data via exporting new datasets through Slicer, but rather dynamically and randomly augmenting them through pytorch DataLoader transforms. This way you can even implement e.g. adaptive histogram equalization with randomly assigned parameters from skimage, or other interesting solutions.

---

<div class="post-metadata">

### Author: ![che85](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/che85/32/636_2.png) [@che85](https://discourse.slicer.org/u/che85)
#### Post date: [August 22, 2019, 2:06pm UTC](https://discourse.slicer.org/t/data-augmentation-library-for-3d-us-medical-images/8125/4 "2019-08-22T14:06:06Z")

</div>

@Prashant_Pandey, @JanWitowski Thanks for your quick response. If I am not wrong, Albumentations doesn’t seem to do data augmentation on 3D volumetric data.

---

<div class="post-metadata">

### Author: ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)
#### Post date: [August 22, 2019, 2:28pm UTC](https://discourse.slicer.org/t/data-augmentation-library-for-3d-us-medical-images/8125/5 "2019-08-22T14:28:35Z")

</div>

> [@che85](#):
>
> Albumentations doesn’t seem to do data augmentation on 3D volumetric data.

Yes, that’s what it looks like to me as well. Perhaps the architecture is such that we could plug in a 3D augmentation path? If not, perhaps follow the general style but with a 3D approach in mind (or maybe ND for that matter).

> [@JanWitowski](#):
>
> Also, as above, I wouldn’t augment data via exporting new datasets through Slicer, but rather dynamically and randomly augmenting them through pytorch DataLoader transforms.

Yes, for sure it would be good to follow this approach.

---

<div class="post-metadata">

### Author: ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)
#### Post date: [March 19, 2021, 10:44am UTC](https://discourse.slicer.org/t/data-augmentation-library-for-3d-us-medical-images/8125/6 "2021-03-19T10:44:34Z")

</div>

This probably comes in very late, but in case someone needs this, you can use [TorchIO](https://torchio.readthedocs.io/).
