I can save data into nii.gz file, but I find that the saved file do not include the dicom header information.
For example:
I load a mha
as following:
reader = sitk.ImageFileReader()
reader.SetFileName("C:\\Users\\MLoong\\Desktop\\test_cas\\tof.mha")
reader.LoadPrivateTagsOn()
reader.ReadImageInformation()
position = reader.GetMetaData("0020|0032")
print(position)
And the printed information is what I want:
-107.45459007851\34.52157503367019\81.0415926597073
Then, I save the image into nii.gz file:
sitk_img=reader.Execute()
sitk.WriteImage(sitk_img, fileName="test.nii.gz")
And it succeed.
Then, I load this nii.gz file, and want to print 0020|0032
information:
reader = sitk.ImageFileReader()
reader.SetFileName("test.nii.gz")
reader.LoadPrivateTagsOn()
reader.ReadImageInformation()
position = reader.GetMetaData("0020|0032")
print(position)
A bug is reported:
Traceback (most recent call last):
File "D:\Program Files\JetBrains\PyCharm Community Edition 2019.3.4\plugins\python-ce\helpers\pydev\pydevd.py", line 1434, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "D:\Program Files\JetBrains\PyCharm Community Edition 2019.3.4\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/MLoong/Desktop/medpro/Demo/test.py", line 19, in <module>
position = reader.GetMetaData("0020|0032")
File "D:\Anaconda3\envs\gitlab_medpro\lib\site-packages\SimpleITK\SimpleITK.py", line 5827, in GetMetaData
return _SimpleITK.ImageFileReader_GetMetaData(self, key)
RuntimeError: Exception thrown in SimpleITK ImageFileReader_GetMetaData: D:\a\1\sitk-build\ITK\Modules\Core\Common\src\itkMetaDataDictionary.cxx:77:
itk::ERROR: Key '0020|0032' does not exist
How can I save dicom header information into nii.gz file? Any suggestion is appreciated~~~