use dcmodify while maintaining 'ISO_IR 100' character set

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
flyingmozart
Posts: 3
Joined: Fri, 2013-05-17, 12:38

use dcmodify while maintaining 'ISO_IR 100' character set

#1 Post by flyingmozart »

Dear DCMTK community,

I am currently encountering difficulties with my coding-project related to specifying the desired encoding when using dcmodify. I have developed a simple Python script that updates values in specific DICOM tags. However, I am facing an issue when attempting to execute this modification with dcmodify:

1) the pre-existing DICOM file (dicomfile.dcm) is stored with special character set 'ISO_IR 100' (equal to 'latin-1' in python) with an outdated patientname (Maxi^MußtermannOld), please not the special character 'ß'
2) in python, the new patient name is stored in unicode in the string newPatientName="Maxi^MußtermannNew"
3) I want to update the dicomfile.dcm with the newPatientName value
4) when executing python code

Code: Select all

newPatientName="Maxi^MußtermannNew"
command = ['dcmodify', '-nb', '-m', f'(0010,0010)={newPatientName}', dicomfile.dcm]
subprocess.run(command,  stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) 
The special character 'ß' is stored in UTF8 format which is inconsistent to the remaining charset "ISO_IR 100" content within the dicomfile. Here some details:

output of original dicomfile:

Code: Select all

dcmdump +P 0010,0010 original_dicomfile.dcm
# output: Maxi^Mu?termannOld

dcmdump +U8 +P 0010,0010 original_dicomfile.dcm
# output: Maxi^MußtermannOld

dcmdump +P 0008,0005 original_dicomfile.dcm
# output ISO_IR 100
output of modified dicomfile

Code: Select all

dcmdump +P 0010,0010 dicomfile.dcm
# output: Maxi^MußtermannOld --> this should be Maxi^Mu?termannOld

dcmdump +U8 +P 0010,0010 dicomfile.dcm
# output: Maxi^MuÃtermannNew --> this should be  Maxi^MußtermannOld

dcmdump +P 0008,0005 dicomfile.dcm
# output ISO_IR 100
Is there a way to pass on the desired encoding to dcmodify? I tried encoding the newPatientName.encode('latin-1') to latin-1 byte representation, but that didn't work.
Any hits are appreciated :-)

J. Riesmeier
DCMTK Developer
Posts: 2549
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: use dcmodify while maintaining 'ISO_IR 100' character set

#2 Post by J. Riesmeier »

The dcmodify tool (as all DCMTK command line tools) takes the character string as you specify it. So, if you want to store a value in Latin-1 (ISO 8859-1) encoding, you have to provide the correct byte sequence.
Alternatively, you could change the encoding of the DICOM dataset to UTF-8 (ISO_IR 192) and then pass your modified UTF-8 encoded character string to dcmodify.

Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest