2D support? #455
-
Hello, However, it's unclear to me to which extend this library supports 2D images. I work with both 2d and 3d data, and using one codebase and pipline for both 2d and 3d images is very important to me. The documentation of torchio only talks about 3D images, yet the Image class seems to have some support for 2d images as well. Can you please clarify to which extend I will be able to use torchio with 2d images? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
:D thanks @SteffenCzolbe.
The reason why there is not a lot of 2D talk in the docs is just that the main challenges that this library solves are related to volumetric data with corresponding spatial metadata. That being said, you can see a 4D image as a generalization of a 2D image, so everything should work fine. Here's some IPython code: !curl -o image2d.jpg https://thispersondoesnotexist.com/image
import torchio as tio
image = tio.ScalarImage('image2d.jpg')
image.plot()
image # prints: ScalarImage(shape: (3, 1024, 1024, 1); spacing: (1.00, 1.00, 1.00); orientation: LPS+; memory: 3.0 MiB; dtype: torch.ByteTensor)
add_noise = tio.RandomNoise(std=50)
noisy = add_noise(image)
noisy.plot()
elastic_transform = tio.RandomElasticDeformation(max_displacement=150)
deformed = elastic_transform(noisy)
deformed.plot() These images are shown (I have rotated them 90 degrees for visualization purposes). Loaded image: Noisy image: Deformed image: Note that you'll get a different face if you run that code, as the website generates face using a GAN. There are some more examples in the Transforms tutorial: Data preprocessing and augmentation using TorchIO: a tutorial. |
Beta Was this translation helpful? Give feedback.
:D thanks @SteffenCzolbe.
The reason why there is not a lot of 2D talk in the docs is just that the main challenges that this library solves are related to volumetric data with corresponding spatial metadata. That being said, you can see a 4D image as a generalization of a 2D image, so everything should work fine. Here's some IPython code: