我想从一个创建两个 pydicom 文件。但我无法使用带注释的 *.dcm 格式保存文件。
import pydicom
from pydicom.data import get_testdata_files
# read the dicom file
ds = pydicom.dcmread(test_image_fps[0])
# find the shape of your pixel data
shape = ds.pixel_array.shape
# get the half of the x dimension. For the y dimension use shape[0]
half_x = int(shape[1] / 2)
# slice the halves
# [first_axis, second_axis] so [:,:half_x] means slice all from first axis, slice 0 to half_x from second axis
data = ds.pixel_array[:, :half_x]
print('The image has {} x {}'.format(data.shape[0],
data.shape[1]))
# print the image information given in the dataset
print(data)
data.save_as("/my/path/after.dcm")
'numpy.ndarray' object has no attribute 'save_as