@@ -642,14 +642,21 @@ def imread(filename, pixel_type=None, fallback_only=False):
642
642
643
643
The reader is instantiated with the image type of the image file if
644
644
`pixel_type` is not provided (default). The dimension of the image is
645
- automatically found. If the given filename is a list or a tuple, the
646
- reader will use an itk.ImageSeriesReader object to read the files.
645
+ automatically found
646
+
647
+ If the filename provided is a directory then the directory is assumed to
648
+ be for a DICOM series volume. If there is exactly one DICOM series
649
+ volume in that directory, the reader will use an itk.ImageSeriesReader
650
+ object to read the the DICOM filenames within that directory.
651
+
652
+ If the given filename is a list or a tuple of file names, the reader
653
+ will use an itk.ImageSeriesReader object to read the files.
647
654
648
655
If `fallback_only` is set to `True`, `imread()` will first try to
649
656
automatically deduce the image pixel_type, and only use the given
650
- `pixel_type` if automatic deduction fails. Failures typically
651
- happen if the pixel type is not supported (e.g. it is not currently
652
- wrapped).
657
+ `pixel_type` if automatic deduction fails. Failures typically happen if
658
+ the pixel type is not supported (e.g. it is not currently wrapped).
659
+
653
660
"""
654
661
import itk
655
662
import itkTemplate
@@ -663,6 +670,21 @@ def imread(filename, pixel_type=None, fallback_only=False):
663
670
return imread (filename )
664
671
except (KeyError , itkTemplate .TemplateTypeError ):
665
672
pass
673
+ if type (filename ) not in [list , tuple ]:
674
+ import os
675
+ if os .path .isdir (filename ):
676
+ # read DICOM series of 1 image in a folder, refer to: https://github.com/RSIP-Vision/medio
677
+ names_generator = itk .GDCMSeriesFileNames .New ()
678
+ names_generator .SetUseSeriesDetails (True )
679
+ names_generator .AddSeriesRestriction ("0008|0021" ) # Series Date
680
+ names_generator .SetDirectory (filename )
681
+ series_uid = names_generator .GetSeriesUIDs ()
682
+ if len (series_uid ) == 0 :
683
+ raise FileNotFoundError (f"no DICOMs in: { name } ." )
684
+ if len (series_uid ) > 1 :
685
+ raise OSError (f"the directory: { name } contains more than one DICOM series." )
686
+ series_identifier = series_uid [0 ]
687
+ filename = names_generator .GetFileNames (series_identifier )
666
688
if type (filename ) in [list , tuple ]:
667
689
template_reader_type = itk .ImageSeriesReader
668
690
io_filename = filename [0 ]
0 commit comments