11
11
import traceback
12
12
from collections import OrderedDict
13
13
from enum import Enum
14
- from multiprocessing .pool import ThreadPool
15
14
from pathlib import Path
16
15
from typing import (
17
16
Any ,
@@ -294,13 +293,7 @@ def __init__(self, fp: Union[str, Path, DicomFileLike]):
294
293
'the path to a DICOM file stored on disk.'
295
294
)
296
295
297
- # We use threads to read multiple frames in parallel. Since the
298
- # operation is I/O rather CPU limited, we don't need to worry about
299
- # the Global Interpreter Lock (GIL) and use lighweight threads
300
- # instead of separate processes. However, that won't be as useful for
301
- # decoding, since that operation is CPU limited.
302
- self ._pool : Union [ThreadPool , None ] = None
303
-
296
+ # Those attributes will be set by the "open()"
304
297
self ._metadata : Dataset = Dataset ()
305
298
self ._is_open = False
306
299
self ._as_float = False
@@ -510,7 +503,6 @@ def open(self) -> None:
510
503
'Number of Frames.'
511
504
)
512
505
513
- self ._pool = ThreadPool ()
514
506
self ._is_open = True
515
507
516
508
def _assert_is_open (self ) -> None :
@@ -531,46 +523,10 @@ def metadata(self) -> Dataset:
531
523
532
524
def close (self ) -> None :
533
525
"""Close file."""
534
- if self ._pool is not None :
535
- self ._pool .close ()
536
- self ._pool .terminate ()
537
526
if self ._fp is not None :
538
527
self ._fp .close ()
539
528
self ._is_open = False
540
529
541
- def read_frames (
542
- self ,
543
- indices : Iterable [int ],
544
- parallel : bool = False
545
- ) -> List [bytes ]:
546
- """Read the pixel data of one or more frame items.
547
-
548
- Parameters
549
- ----------
550
- indices: Iterable[int]
551
- Zero-based frame indices
552
- parallel: bool, optional
553
- Whether frame items should be read in parallel using multiple
554
- threads
555
-
556
- Returns
557
- -------
558
- List[bytes]
559
- Pixel data of frame items encoded in the transfer syntax.
560
-
561
- Raises
562
- ------
563
- IOError
564
- When frames could not be read
565
-
566
- """
567
- self ._assert_is_open ()
568
- if parallel :
569
- func = self .read_frame
570
- return self ._pool .map (func , indices ) # type: ignore
571
- else :
572
- return [self .read_frame (i ) for i in indices ]
573
-
574
530
def read_frame (self , index : int ) -> bytes :
575
531
"""Read the pixel data of an individual frame item.
576
532
@@ -679,39 +635,6 @@ def decode_frame(self, index: int, value: bytes):
679
635
ds .PixelData = value
680
636
return ds .pixel_array
681
637
682
- def read_and_decode_frames (
683
- self ,
684
- indices : Iterable [int ],
685
- parallel : bool = False
686
- ) -> List [np .ndarray ]:
687
- """Read and decode the pixel data of one or more frame items.
688
-
689
- Parameters
690
- ----------
691
- indices: Iterable[int]
692
- Zero-based frame indices
693
- parallel: bool, optional
694
- Whether frame items should be read in parallel using multiple
695
- threads
696
-
697
- Returns
698
- -------
699
- List[numpy.ndarray]
700
- Pixel arrays of frame items
701
-
702
- Raises
703
- ------
704
- IOError
705
- When frames could not be read
706
-
707
- """
708
- self ._assert_is_open ()
709
- if parallel :
710
- func = self .read_and_decode_frame
711
- return self ._pool .map (func , indices ) # type: ignore
712
- else :
713
- return [self .read_and_decode_frame (i ) for i in indices ]
714
-
715
638
def read_and_decode_frame (self , index : int ):
716
639
"""Read and decode the pixel data of an individual frame item.
717
640
@@ -2927,10 +2850,9 @@ def retrieve_instance_frames(
2927
2850
frame_index = frame_number - 1
2928
2851
frame_indices .append (frame_index )
2929
2852
2930
- frames = image_file_reader .read_frames (frame_indices , parallel = True )
2931
-
2932
2853
reencoded_frames = []
2933
- for frame in frames :
2854
+ for frame_index in frame_indices :
2855
+ frame = image_file_reader .read_frame (frame_index )
2934
2856
if not transfer_syntax_uid .is_encapsulated :
2935
2857
reencoded_frame = frame
2936
2858
else :
0 commit comments