Skip to content

Commit 3f4215c

Browse files
authored
Tolerate missing ReferencedInstanceSequence (#380)
* Allow missing ReferencedInstanceSequence * Add test
1 parent fba1556 commit 3f4215c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/highdicom/image.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3980,10 +3980,14 @@ def _include_sequence(seq):
39803980
instance_sequence = (
39813981
ref_series.ReferencedSOPSequence
39823982
)
3983-
else:
3983+
elif 'ReferencedInstanceSequence' in ref_series:
39843984
instance_sequence = (
39853985
ref_series.ReferencedInstanceSequence
39863986
)
3987+
else:
3988+
# This is invalid according to the standard, but
3989+
# has been observed in some data
3990+
instance_sequence = []
39873991

39883992
for ref_ins in instance_sequence:
39893993
instance_data.append(

tests/test_image.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,3 +1439,17 @@ def test_imread_from_dicom_bytes_io_lazy():
14391439
# Two reads to ensure opening/closing is handled
14401440
im.get_frame(1)
14411441
im.get_frame(2)
1442+
1443+
1444+
def test_imread_missing_referenced_instances():
1445+
# Test for the case where a ReferencedSeriesSequence is present but does
1446+
# not list instances. This is not valid by the standard but is observed and
1447+
# we should be tolerant to it
1448+
dcm = get_testdata_file('eCT_Supplemental.dcm', read=True)
1449+
1450+
# Add ReferencedSeriesSequence without any referenced instances
1451+
ref_series = pydicom.Dataset()
1452+
ref_series.SeriesInstanceUID = UID()
1453+
dcm.ReferencedSeriesSequence = [ref_series]
1454+
1455+
Image.from_dataset(dcm, copy=False)

0 commit comments

Comments
 (0)