|
32 | 32 | from pydicom.datadict import dictionary_VR, keyword_for_tag, tag_for_keyword |
33 | 33 | from pydicom.dataelem import DataElement |
34 | 34 | from pydicom.dataset import Dataset, FileMetaDataset |
35 | | -from pydicom.encaps import encapsulate, get_frame_offsets |
| 35 | +from pydicom.encaps import encapsulate |
| 36 | +try: |
| 37 | + # pydicom >= 3.0 - parse_basic_offsets replaces get_frame_offsets |
| 38 | + from pydicom.encaps import parse_basic_offsets |
| 39 | + _use_parse_basic_offsets = True |
| 40 | +except ImportError: |
| 41 | + # pydicom < 3.0 - use deprecated get_frame_offsets |
| 42 | + from pydicom.encaps import get_frame_offsets |
| 43 | + _use_parse_basic_offsets = False |
36 | 44 | from pydicom.errors import InvalidDicomError |
37 | 45 | from pydicom.filebase import DicomFileLike |
38 | 46 | from pydicom.filereader import data_element_offset_to_value, dcmread |
@@ -350,7 +358,13 @@ def _read_bot(fp: DicomFileLike) -> np.ndarray: |
350 | 358 | fp.is_implicit_VR, 'OB' |
351 | 359 | ) |
352 | 360 | fp.seek(pixel_data_element_value_offset - 4, 1) |
353 | | - is_empty, offsets = get_frame_offsets(fp) |
| 361 | + |
| 362 | + # Use parse_basic_offsets for pydicom >= 3.0, get_frame_offsets for < 3.0 |
| 363 | + if _use_parse_basic_offsets: |
| 364 | + offsets = parse_basic_offsets(fp) |
| 365 | + else: |
| 366 | + is_empty, offsets = get_frame_offsets(fp) |
| 367 | + |
354 | 368 | return np.array(offsets, dtype=np.uint32) |
355 | 369 |
|
356 | 370 |
|
|
0 commit comments