Skip to content

Instantly share code, notes, and snippets.

@clementpoiret
Created April 29, 2022 17:10
Show Gist options
  • Save clementpoiret/b9e00327931af9e6d9b30938b57a334c to your computer and use it in GitHub Desktop.
Save clementpoiret/b9e00327931af9e6d9b30938b57a334c to your computer and use it in GitHub Desktop.
Quick toy example for segmentation
import torchio as tio
# Loading the data and the expected labels
subject = tio.Subject(
mri=tio.ScalarImage("./T2w_hires_right_hippocampus.nii.gz"),
label=tio.LabelMap("./T2w_hires_right_hippocampus_seg_crop.nii.gz"))
# Quick preprocessing to get the data in the right format for inference
preprocess = tio.Compose([
tio.ZNormalization(),
tio.EnsureShapeMultiple(8),
])
subject = preprocess(subject)
# Plot if needed
subject.plot()
model = dummy_model()
segmentation = model(subject.mri.data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment