How to fix "LookupError: unknown encoding: ISO_IR 149"
How to fix "LookupError: unknown encoding: ISO_IR 149"
我正在使用 pydicom 改变 dicom headers。
PatientName 包含韩文,所以我将 PatientName 修改为英文。
之后,尝试保存时输出 ISO_IR_149 错误。
我在charset.py中查找与ISO_IR_149相关的部分,但我无法解决这个问题。
我们如何解决这个问题?
谢谢
import pydicom
import os
import tempfile
import datetime
from pydicom.dataset import Dataset, FileDataset
suffix = '.dcm'
filename_little_endian = tempfile.NamedTemporaryFile(suffix=suffix).name
filename_big_endian = tempfile.NamedTemporaryFile(suffix=suffix).name
#print(ds.PatientSex)
ds = pydicom.filereader.dcmread("003.dcm")
ds.PatientName = "Patient1"
print(ds.PatientName)
print("Writing test file", filename_little_endian)
ds.save_as(filename_little_endian)
print("File saved.")
# Write as a different transfer syntax XXX shouldn't need this but pydicom
# 0.9.5 bug not recognizing transfer syntax
ds.file_meta.TransferSyntaxUID = pydicom.uid.ExplicitVRBigEndian
ds.is_little_endian = False
ds.is_implicit_VR = False
print("Writing test file as Big Endian Explicit VR", filename_big_endian)
ds.save_as(filename_big_endian)
# reopen the data just for checking
for filename in (filename_little_endian, filename_big_endian):
print('Load file {} ...'.format(filename))
ds = pydicom.dcmread(filename)
print(ds)
# remove the created file
print('Remove file {} ...'.format(filename))
os.remove(filename)
报错信息如下
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/admin/PycharmProjects/Cylinder/OpenHeader-dicom.py", line 15, in <module>
ds.save_as(filename_little_endian)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\dataset.py", line 1108, in save_as
pydicom.dcmwrite(filename, self, write_like_original)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\filewriter.py", line 888, in dcmwrite
write_dataset(fp, get_item(dataset, slice(0x00010000, None)))
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\filewriter.py", line 521, in write_dataset
write_data_element(fp, dataset.get_item(tag), dataset_encoding)
File "C:\ProgramData\Anaconda3\lib\contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\tag.py", line 37, in tag_in_exception
raise type(ex)(msg)
LookupError: With tag (0010, 0010) got exception: unknown encoding: ISO_IR 149
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\tag.py", line 30, in tag_in_exception
yield
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\filewriter.py", line 521, in write_dataset
write_data_element(fp, dataset.get_item(tag), dataset_encoding)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\filewriter.py", line 464, in write_data_element
writer_function(buffer, data_element, encodings=encodings)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\filewriter.py", line 264, in write_PN
val = [elem.encode(encodings) for elem in val]
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\filewriter.py", line 264, in <listcomp>
val = [elem.encode(encodings) for elem in val]
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\valuerep.py", line 763, in encode
return _encode_personname(self.components, encodings)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\valuerep.py", line 594, in _encode_personname
for group in comp.split('^')]
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\valuerep.py", line 594, in <listcomp>
for group in comp.split('^')]
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\charset.py", line 274, in encode_string
encoded = value.encode(encoding)
LookupError: unknown encoding: ISO_IR 149
答案很简单,但可能令人不满意:DICOM 不直接支持 ISO_IR 149。它确实支持带有韩语代码扩展技术的字符集。 DICOM 中韩文字符的定义术语是:"ISO 2022 IR 149"。也许使用 UTF-8 (ISO_IR 192) 是您的另一种选择?
我正在使用 pydicom 改变 dicom headers。 PatientName 包含韩文,所以我将 PatientName 修改为英文。 之后,尝试保存时输出 ISO_IR_149 错误。 我在charset.py中查找与ISO_IR_149相关的部分,但我无法解决这个问题。 我们如何解决这个问题? 谢谢
import pydicom
import os
import tempfile
import datetime
from pydicom.dataset import Dataset, FileDataset
suffix = '.dcm'
filename_little_endian = tempfile.NamedTemporaryFile(suffix=suffix).name
filename_big_endian = tempfile.NamedTemporaryFile(suffix=suffix).name
#print(ds.PatientSex)
ds = pydicom.filereader.dcmread("003.dcm")
ds.PatientName = "Patient1"
print(ds.PatientName)
print("Writing test file", filename_little_endian)
ds.save_as(filename_little_endian)
print("File saved.")
# Write as a different transfer syntax XXX shouldn't need this but pydicom
# 0.9.5 bug not recognizing transfer syntax
ds.file_meta.TransferSyntaxUID = pydicom.uid.ExplicitVRBigEndian
ds.is_little_endian = False
ds.is_implicit_VR = False
print("Writing test file as Big Endian Explicit VR", filename_big_endian)
ds.save_as(filename_big_endian)
# reopen the data just for checking
for filename in (filename_little_endian, filename_big_endian):
print('Load file {} ...'.format(filename))
ds = pydicom.dcmread(filename)
print(ds)
# remove the created file
print('Remove file {} ...'.format(filename))
os.remove(filename)
报错信息如下
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/admin/PycharmProjects/Cylinder/OpenHeader-dicom.py", line 15, in <module>
ds.save_as(filename_little_endian)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\dataset.py", line 1108, in save_as
pydicom.dcmwrite(filename, self, write_like_original)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\filewriter.py", line 888, in dcmwrite
write_dataset(fp, get_item(dataset, slice(0x00010000, None)))
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\filewriter.py", line 521, in write_dataset
write_data_element(fp, dataset.get_item(tag), dataset_encoding)
File "C:\ProgramData\Anaconda3\lib\contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\tag.py", line 37, in tag_in_exception
raise type(ex)(msg)
LookupError: With tag (0010, 0010) got exception: unknown encoding: ISO_IR 149
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\tag.py", line 30, in tag_in_exception
yield
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\filewriter.py", line 521, in write_dataset
write_data_element(fp, dataset.get_item(tag), dataset_encoding)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\filewriter.py", line 464, in write_data_element
writer_function(buffer, data_element, encodings=encodings)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\filewriter.py", line 264, in write_PN
val = [elem.encode(encodings) for elem in val]
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\filewriter.py", line 264, in <listcomp>
val = [elem.encode(encodings) for elem in val]
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\valuerep.py", line 763, in encode
return _encode_personname(self.components, encodings)
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\valuerep.py", line 594, in _encode_personname
for group in comp.split('^')]
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\valuerep.py", line 594, in <listcomp>
for group in comp.split('^')]
File "C:\ProgramData\Anaconda3\lib\site-packages\pydicom\charset.py", line 274, in encode_string
encoded = value.encode(encoding)
LookupError: unknown encoding: ISO_IR 149
答案很简单,但可能令人不满意:DICOM 不直接支持 ISO_IR 149。它确实支持带有韩语代码扩展技术的字符集。 DICOM 中韩文字符的定义术语是:"ISO 2022 IR 149"。也许使用 UTF-8 (ISO_IR 192) 是您的另一种选择?