Created
January 13, 2015 22:22
-
-
Save jrkerns/eab5f5da2335572a3f0f to your computer and use it in GitHub Desktop.
pixel array example
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
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