Skip to content

Instantly share code, notes, and snippets.

@takuya-murao
Created September 20, 2018 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takuya-murao/4c291ca7a4d3b005a510c6dd435987c9 to your computer and use it in GitHub Desktop.
Save takuya-murao/4c291ca7a4d3b005a510c6dd435987c9 to your computer and use it in GitHub Desktop.
pydicom で DICOM タグの編集をする

pydicom で DICOM タグの編集をする

$ python3
>>> import pydicom

DICOM ファイルを読み込む

>>> ds = pydicom.read_file('/path/to/input.dcm')

DataSet を更新する

>>> ds.update({ 'PatientName': 'John,Doe', 'PatientID': '12345678' })

引数の dict のキーは、pydicom/_dicom_dict.py at master から変更したい DICOM タグがキーとなっている箇所を探し、値の最後 (5番目) の要素にある文字列を用いる

更新した DataSet を保存する

>>> ds.save_as('/path/to/output.dcm')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment