Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rahulremanan/fd4b636ee553a03306ba1c4a1e8b9168 to your computer and use it in GitHub Desktop.
Save rahulremanan/fd4b636ee553a03306ba1c4a1e8b9168 to your computer and use it in GitHub Desktop.
A DICOM reader helper function
def read_dicom(inp):
dicom = pydicom.dcmread(file_path)
image = dicom.pixel_array
if image.max() - image.min() > 0:
image = (image - image.min()) / (image.max() - image.min())
if dicom.PhotometricInterpretation == 'MONOCHROME1':
image = 1 - image
image = (image * 255).astype(np.uint8)
image = np.nan_to_num(image)
image_arr[:,:,0] = image//3
image_arr[:,:,1] = image//3
image_arr[:,:,2] = image//3
del image
image_arr = np.asarray(image_arr, dtype=np.uint8)
return image_arr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment