问题描述
我有一个原始DICOM文件,该文件具有DICOM标签BitsAllocated(0028 | 0100)= 16和Bitsstored(0028 | 0101)= 12。我使用SimpleITK来阅读该系列,对其进行修改,然后我想使用与上面指定的两个标签相同的值将其再次保存为DICOM系列。 修改数据集后,数据格式为uint16。
这是我使用的代码:
writer = sitk.ImageFileWriter()
writer.KeepOriginalImageUIDOn()
# copy relevant tags from the original Meta-data dictionary (private tags are also accessible).
tags_to_copy = ["0010|0010",# Patient Name
"0010|0020",# Patient ID
"0010|0030",# Patient Birth Date
"0020|000D",# Study Instance UID,for machine consumption
"0020|0010",# Study ID,for human consumption
"0008|0020",# Study Date
"0008|0030",# Study Time
"0008|0050",# Accession Number
"0008|0060" # Modality
]
modification_time = time.strftime("%H%M%s")
modification_date = time.strftime("%Y%m%d")
# copy some of the tags and add the relevant tags indicating the change.
# For the series instance UID (0020|000e),each of the components is a number,cannot start
# with zero,and separated by a '.' We create a unique series ID using the date and time.
# tags of interest:
direction = sitk_stack.GetDirection()
series_tag_values = [(k,rs.GetMetaData(0,k)) for k in tags_to_copy if rs.HasMetaDataKey(0,k)] + \
[("0008|0031",modification_time),# Series Time
("0008|0021",modification_date),# Series Date
("0008|0008","DERIVED\\SECONDARY"),# Image Type
("0020|000e","1.2.826.0.1.3680043.2.1125." + modification_date + ".1" + modification_time),# Series Instance UID
("0020|0037",'\\'.join(map(str,(direction[0],direction[3],direction[6],# Image Orientation (Patient)
direction[1],direction[4],direction[7])))),("0008|103e","0008|103e") + " Processed-SimpleITK"),("0028|0101",'12'),# gray values window
("0028|0102",'11'),# gray values window
("0028|0100",'16'),('0028|0103','0'),]
for i in range(sitk_stack.GetDepth()):
image_slice = sitk_stack[:,:,i]
# Tags shared by the series.
for tag,value in series_tag_values:
image_slice.SetMetaData(tag,value)
# Slice specific tags.
image_slice.SetMetaData("0008|0012",time.strftime("%Y%m%d")) # Instance Creation Date
image_slice.SetMetaData("0008|0013",time.strftime("%H%M%s")) # Instance Creation Time
image_slice.SetMetaData("0020|0032",sitk_stack.TransformIndexToPhysicalPoint((0,i))))) # Image Position (Patient)
image_slice.SetMetaData("0020,0013",str(i)) # Instance Number
# Write to the output directory and add the extension dcm,to force writing in DICOM format.
writer.SetFileName(os.path.join(output_dir,str(i) + '.dcm'))
writer.Execute(image_slice)
'''
当我随后使用MeVisLab查看图像时,我注意到BitsAlocated和Bitsstored都是16,而不是16和12。我在做什么错?可以仅使用12位存储图像吗?
解决方法
SimpleITK不支持12位像素,因此无法写入它们。因此,当读取12位像素的图像时,它会自动转换为16位。
我不知道支持写12位像素图像的python DICOM软件包。 SimpleITK将GDCM或DCMTK用于DICOM I / O。如果您直接使用这些库,虽然我不知道,但您也许可以做到。但是,通过SimpleITK不能。