I have an equally-sized DICOM series whose images I crop using Otsu thresholding and contouring. This cropping leads to smaller images with various sizes (width, height). These cropped images are represented as 2D grayscale numpy arrays in my code. Currently, I am able to convert each image to a Nifti1Image using code resembling the piece below.
# Inspired by https://stackoverflow.com/a/28331076
import nibabel as nib
import numpy as np
data = np.arange(4*4).reshape(4,4) # This is the cropped image data
new_image = nib.Nifti1Image(data, affine=np.eye(4))
I am curious if there's a way to write these Nifti1Image objects, all containing differently sized image data, to a single "nii.gz" file.
EDIT: I would like to preserve the image sizes of these Nifti1Image objects too.
I have an equally-sized DICOM series whose images I crop using Otsu thresholding and contouring. This cropping leads to smaller images with various sizes (width, height). These cropped images are represented as 2D grayscale numpy arrays in my code. Currently, I am able to convert each image to a
Nifti1Image
using code resembling the piece below.I am curious if there's a way to write these
Nifti1Image
objects, all containing differently sized image data, to a single "nii.gz" file.EDIT: I would like to preserve the image sizes of these
Nifti1Image
objects too.