Data Agumentation in 3D images

username: 887574002
cooked: <p>Hi all<br>
I have a question regarding data augmentation in 3D images in PyTorch. I found nice methods like Colorjitter, RandomResziedCrop, and RandomGrayscale in documentations of PyTorch, and I am interested in using them for 3D images. As far as I understood these methods can be applied only on 2D images (correct me if I am wrong). So, if I want to use them in 3D setting, one solution is converting 3D images to Numpy arrays and then writing custom transformation in PyTorch using skimage or scipy am I right? I would appreciate it if you can help me with your ideas.</p>
<p>Best</p>

username: ptrblck
cooked: <p><a href="https://github.com/Project-MONAI/MONAI/tree/master/monai/transforms">MONAI</a> as well as <a href="https://github.com/fepegar/torchio">torchio</a> provide some transformations for 3D images from the medical domain (where these types of images are often used).</p>
<p>CC <a class="mention" href="/u/monai">@MONAI</a> and  <a class="mention" href="/u/fepegar">@fepegar</a> for more information on these libs.</p>
<aside class="quote no-group" data-username="887574002" data-post="1" data-topic="86289">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/887574002/48/35835_2.png" class="avatar"> 887574002:</div>
<blockquote>
<p>one solution is converting 3D images to Numpy arrays and then writing custom transformation in PyTorch using skimage or scipy am I right?</p>
</blockquote>
</aside>
<p>This would work, if <code>skimage</code> and <code>scipy</code> support 3D images (I’m not familiar with 3D data processing using these libs, so you would have to double check it).</p>

username: fepegar
cooked: <p>Hi Mjavan, thanks for the heads-up, <a class="mention" href="/u/ptrblck">@ptrblck</a>.</p>
<p><a href="https://torchio.readthedocs.io/transforms/transforms.html#transforms-api" rel="nofollow noopener">Here’s a list of the transforms included in TorchIO</a>. I’m happy to add some more transforms that you may need. Are you working with 3D grayscale images or RGB?</p>
<p>You can do some low-level stuff with <code>skimage</code> and <code>scipy</code>, but I think you’d be better off using a higher-level library. In <a href="https://github.com/scikit-image/scikit-image/pull/4535#issuecomment-605652562" rel="nofollow noopener">this <code>skimage</code> issue</a>, a member of the developers team points a user to TorchIO.</p>
<p>I’m working with the MONAI team so that TorchIO transforms can be used within their library, but this is not ready yet.</p>

username: 887574002
cooked: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a> and thank you <a class="mention" href="/u/fepegar">@fepegar</a>.<br>
I am working with 3D medical images that are Grayscale.<br>
I looked at TorchIO and your nice effort there.  I need RandomResizedCrop, that gives me the original size of the image after cropping. This transformation in PyTorch crops the image with an aspect ratio [0.08,1].  I found <code>Crop</code> in TorchIO without resizing to the original image, or the capability of accepting any aspect ratio. I googled it in the net and I found that it is difficult to define aspect ratio in 3D space. Would it be possible to add these two parameters to <code>Crop</code> in TorchIO. I have also a question about the type of inputs for transformations in TorchIO. Dose it support both 4D Torch tensor and Numpy? Would it be possible that in TorchIO we have Colorjitter like transformation that we have in pytorch. I am not sure how much difference it may make as images here are Grayscale, but still I like to try it.<br>
Thanks again for your help.</p>

username: fepegar
cooked: <p>I think it’s best to move this to the TorchIO GitHub, I hope that’s ok: <a href="https://github.com/fepegar/torchio/issues/205" rel="nofollow noopener">https://github.com/fepegar/torchio/issues/205</a></p>

username: fepegar
cooked: <p>(I’ve replied to all your questions on GitHub.)</p>

username: 887574002
cooked: <p>Thank you so much <a class="mention" href="/u/fepegar">@fepegar</a>.</p>