Skip to content

Instantly share code, notes, and snippets.

@jrkerns
Created January 13, 2015 22:22
Show Gist options
  • Save jrkerns/eab5f5da2335572a3f0f to your computer and use it in GitHub Desktop.
Save jrkerns/eab5f5da2335572a3f0f to your computer and use it in GitHub Desktop.
pixel array example
import os.path as osp
from pydicom import read_file
import numpy as np
import matplotlib.pyplot as plt
# use sample file; cd is in pydicom root folder
test_file = osp.join(osp.dirname(osp.abspath(__file__)), 'tests', 'test_files', 'CT_small.dcm')
dcm = read_file(test_file)
# show pixel array
plt.imshow(dcm.pixel_array)
plt.show()
new_array = np.ones(dcm.pixel_array.shape, dtype=dcm.pixel_array.dtype)
# try to replace pixel array
dcm.pixel_array = new_array
# will show no change
plt.imshow(dcm.pixel_array)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment