Hi, please help.
I cannot write correctly dicom.
I did following step,
# load
L40t1 = "path/to/dcm image dir"
series_IDsT1 = sitk.ImageSeriesReader.GetGDCMSeriesIDs(L40t1)
if not series_IDsT1:
print("ERROR: given directory does not contain a DICOM series.")
series_file_namesT1 = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(L40t1, series_IDsT1[0])
series_readerT1 = sitk.ImageSeriesReader()
series_readerT1.SetFileNames(series_file_namesT1)
series_readerT1.MetaDataDictionaryArrayUpdateOn()
series_readerT1.LoadPrivateTagsOn()
t1volume = series_readerT1.Execute()
then save it,
writer = sitk.ImageFileWriter()
writer.KeepOriginalImageUIDOn()
print("save images...", t1volume.GetDepth())
for i in range(t1volume.GetDepth()):
image_slice = t1volume[:,:,i]
# Tags shared by the series.
for j,key in enumerate(series_readerT1.GetMetaDataKeys(i)):
image_slice.SetMetaData(key, series_readerT1.GetMetaData(i,key))
# Write to the output directory and add the extension dcm, to force writing in DICOM format.
writer.SetFileName(os.path.join(outdir,str(i)+'.dcm'))
writer.Execute(image_slice)
print(("~" * 50) + " Done.")
then, check pixel spacing of saved image
# check pixel spacing
print("original",t1volume.GetSpacing())
# data test using 0.dcm
image = sitk.ReadImage(os.path.join(outdir,str(0)+'.dcm'))
print("saved image",image.GetSpacing())
I got result of pixel spacing are,
original (0.78125, 0.78125, 7.000051021575928)
saved image (0.78125, 0.78125, 1.0) # Odd…
Why I cannot save SpacingBetweenSlices correctly ??
Where is wrong/lack of my code ??
But, this behavior occurred by only using ImageSeriesReader. (in my case).
When I use ReadImage(path2dcm-instance), I can save SpacingBetweenSlices correctly.
tatsuaki