Last active
November 14, 2021 11:13
-
-
Save fepegar/a015944da46d4e147a4362e63ec51019 to your computer and use it in GitHub Desktop.
Script to create the GIF shown in https://twitter.com/TorchIOLib/status/1459841764576141315
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import torchio as tio | |
from einops import rearrange | |
rows = 16 | |
cols = 28 | |
dataset = tio.datasets.OrganMNIST3D('train') | |
batch_size = rows * cols | |
loader = torch.utils.data.DataLoader(dataset, batch_size=batch_size, shuffle=True) | |
batch = tio.utils.get_first_item(loader) | |
tensor = batch['image'][tio.DATA] | |
pattern = '(b1 b2) c x y z -> c x (b1 y) (b2 z)' | |
tensor = rearrange(tensor, pattern, b1=cols, b2=rows) | |
image = tio.ScalarImage(tensor=tensor) | |
image.to_gif(0, 2, f'/tmp/{dataset.__class__.__name__}.gif') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment