Processor functions for images
as_closest_canonical(img[, enforce_diag]) | Return img with data reordered to be closest to canonical |
concat_images(images[, check_affines, axis]) | Concatenate images in list to single image, along specified dimension |
four_to_three(img) | Create 3D images from 4D image by slicing over last axis |
squeeze_image(img) | Return image, remove axes length 1 at end of image shape |
Return img with data reordered to be closest to canonical
Canonical order is the ordering of the output axes.
Parameters: | img : spatialimage enforce_diag : {False, True}, optional
|
---|---|
Returns: | canonical_img : spatialimage
|
Concatenate images in list to single image, along specified dimension
Parameters: | images : sequence
check_affines : {True, False}, optional
axis : None or int, optional
Returns : ——- : concat_img : SpatialImage
|
---|
Create 3D images from 4D image by slicing over last axis
Parameters: | img : image
|
---|---|
Returns: | imgs : list
|
Return image, remove axes length 1 at end of image shape
For example, an image may have shape (10,20,30,1,1). In this case squeeze will result in an image with shape (10,20,30). See doctests for further description of behavior.
Parameters: | img : SpatialImage |
---|---|
Returns: | squeezed_img : SpatialImage
|
Examples
>>> import nibabel as nf
>>> shape = (10,20,30,1,1)
>>> data = np.arange(np.prod(shape)).reshape(shape)
>>> affine = np.eye(4)
>>> img = nf.Nifti1Image(data, affine)
>>> img.shape == (10, 20, 30, 1, 1)
True
>>> img2 = squeeze_image(img)
>>> img2.shape == (10, 20, 30)
True
If the data are 3D then last dimensions of 1 are ignored
>>> shape = (10,1,1)
>>> data = np.arange(np.prod(shape)).reshape(shape)
>>> img = nf.ni1.Nifti1Image(data, affine)
>>> img.shape == (10, 1, 1)
True
>>> img2 = squeeze_image(img)
>>> img2.shape == (10, 1, 1)
True
Only final dimensions of 1 are squeezed
>>> shape = (1, 1, 5, 1, 2, 1, 1)
>>> data = data.reshape(shape)
>>> img = nf.ni1.Nifti1Image(data, affine)
>>> img.shape == (1, 1, 5, 1, 2, 1, 1)
True
>>> img2 = squeeze_image(img)
>>> img2.shape == (1, 1, 5, 1, 2)
True