我正在尝试替换给定示例图像中的像素数据。我的代码:
import matplotlib.pyplot as plt
from pydicom import dcmread
from pydicom.data import get_testdata_file
fpath = get_testdata_file('CT_small.dcm')
ds = dcmread(fpath)
# replacing rows and columens with new values
ds.Rows = 200
ds.Columns = 200
# replacing pixel data with new image (type: numpy.ndarray)
ds.pixel_array = data[layer].tobytes()
...
我收到以下错误信息:
AttributeError: can't set attribute
更新
好的,如果我使用
ds.PixelData = data[layer].tobytes()
取代
ds.pixel_array = data[layer].tobytes()
我得到了一张图片,但它看起来与原始图片(data[layer])完全不同。我错过了什么?