Created
August 5, 2021 16:14
-
-
Save reesehaywood/6094543fec3dff375e6840ab72c27af6 to your computer and use it in GitHub Desktop.
Example of reading multiple images into numpy 3d array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NOTE original code uses previous version of pydicom | |
# Below may not be exact in newer versions i.e. 2.0 and above | |
# read in the first CT file to define arrays | |
ds=dicom.read_file(CTfiles[0]) | |
npix3d=np.zeros((ds.Columns,ds.Rows,len(CTfiles)),dtype=np.intc) | |
#loop over all images and add to numpy array | |
for i in xrange(len(CTfiles)): | |
#read in all files to the array | |
ds=dicom.read_file(CTfiles[i]) | |
npix3d[:,:,i]=ds.pixel_array*int(ds.RescaleSlope)+int(ds.RescaleIntercept) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment