[Neuroimaging] [Nibabel] Crop image volume?

Michael Waskom mwaskom at nyu.edu
Fri Aug 18 11:00:01 EDT 2017


Hi Matthew,

Is there a nibabel function to crop a 3D image? I want to resample data to
match my anatomical, but to save space I want to crop the anatomical on the
xyz dimensions to a tight box around the brain volume.

In other words I want to take:

>>> img.shape
--> (256, 256, 256)
>>> cropped_img = nib.crop_image(img, [(50, 200), (50, 200), (50, 200)])
>>> cropped_img.shape
--> (150, 150, 150)

If there isn't a function to do this, could you share a recipe for what I'd
need to do? My sense is I'd need to a) pass a cropped data array (easy) b)
change the data shape information in the header (easy) c) change the fourth
column of the affine matrix (tricky!)

Thanks,
Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20170818/28558680/attachment.html>


More information about the Neuroimaging mailing list