Skip to content
Discussion options

You must be logged in to vote

it's possible in v0.9.1 and newer versions with the metatensor, and SpatialCropd does the slicing:

from monai.transforms import Compose, EnsureTyped, LoadImaged, Orientationd, EnsureChannelFirstd, SaveImaged, SpatialCropd
import numpy as np

def toLoadNiiFile(path):
     trans = Compose([ LoadImaged(keys=['img'], meta_keys='meta'), EnsureChannelFirstd(keys="img"), Orientationd('img', "RAS"), EnsureTyped(keys=['img'])])
     return trans({'img':path})

data = toLoadNiiFile('NPC_AI_Detection_01 _SUVconversion.nii')
data = SpatialCropd(keys="img", roi_start=30, roi_end=80)(data)
saver = SaveImaged(keys="img", output_dir='new', output_postfix='', resample=False)
saver(data)

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Minxiangliu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants