dicomfo-dicom

How to write Chinese value into Institution Name with fo-dicom?


I was trying to write into DICOM tag (0008,0080) with Chinese words by fo-dicom. But found the Tag value just show the messy code in the result file. Please help to review it .

The C# code is below:

var file = DicomFile.Open(@"C:\Users\Administrator\Desktop\20D08F04"); 

//file.Dataset.Add(DicomTag.SpecificCharacterSet, "GB18030");
//file.Dataset.Add(DicomTag.SpecificCharacterSet, "ISO_IR 192");
//I already tried to specified the 0008,0005 with GBK and Utf-8. but it doesn't work. 
file.Dataset.Add(DicomTag.InstitutionName, "测试");

file.Save(@"C:\Users\Administrator\Desktop\test123.dcm");

The resulting file looks like blew in the DCMTK editor.

May anyone of you can help me?

enter image description here

I am sure the DVTK Dicom file editor support the Chinese character set. Because there is another attribute Patient's Name's value is Chinese. And can be viewed properly.

enter image description here


Solution

  • The default encoding in .NET fo-dicom is US-ASCII. It does not help if you set the Specific Character Set after you have opened the DICOM file, parsing is done in the open operation. Specific Character Set only applies if it already set in the DICOM file.

    What you can do is to set the "fallback encoding" to be used if Specific Character Set is not specified in the DICOM file, in the argument list of DicomFile.Open.

    Try this for example:

    var file = DicomFile.Open(fileName, DicomEncoding.GetEncoding("GB18030"));
    

    And as @johnelemans pointed out in the comments, also verify that your viewer is capable of displaying the Chinese character set.