0

我不明白 sitk.ReadImage 是否可以读取图像列表?我没有找到一个示例来说明如何将图像列表输入到函数中。但在功能文档中它说:

ReadImage(**VectorString fileNames**, itk::simple::PixelIDValueEnum outputPixelType) -> Image
ReadImage(std::string const & filename, itk::simple::PixelIDValueEnum outputPixelType) -> Image



ReadImage is a procedural interface to the ImageSeriesReader class which is convenient for most image reading tasks.


Note that when reading a series of images that have meta-data
associated with them (e.g. a DICOM series) the resulting image will
have an empty meta-data dictionary. It is possible to programmatically
add a meta-data dictionary to the compounded image by reading in one
or more images from the series using the ImageFileReader class,
analyzing the meta-dictionary associated with each of those images and
creating one that is relevant for the compounded image.

因此,从文档看来,这是可能的。谁能给我一个简单的例子。

编辑:我尝试了以下方法:

sitk.ReadImage(['volume00001.mhd','volume00002.mhd'])

但这是我得到的错误:

RuntimeErrorTraceback (most recent call last)
<ipython-input-42-85abf82c3afa> in <module>()
      1 files = [f for f in os.listdir('.') if 'mhd' in f]
      2 print(sorted_files[1:25])
----> 3 sitk.ReadImage(['volume00001.mhd','volume00002.mhd'])

/gpfs/bbp.cscs.ch/home/amsalem/anaconda2/lib/python2.7/site-packages/SimpleITK/SimpleITK.pyc in ReadImage(*args)
   8330 
   8331     """
-> 8332     return _SimpleITK.ReadImage(*args)
   8333 class HashImageFilter(ProcessObject):
   8334     """

RuntimeError: Exception thrown in SimpleITK ReadImage: /tmp/SimpleITK/Code/IO/src/sitkImageSeriesReader.cxx:145:
sitk::ERROR: The file in the series have unsupported 3 dimensions.

谢谢。

4

1 回答 1

0

SimpleITK 使用 SWIG 将 C++ 接口包装到 Insight Segmentation and Registration Toolkit (ITK)。因此,内联 python 文档应补充 C++ Doxygen 文档。存在 C++ 类型到 Python 类型的映射,它们之间具有强大的隐式转换。您可以在此处找到 sitk::ReadImage 方法的文档: https ://itk.org/SimpleITKDoxygen/html/namespaceitk_1_1simple.html#ae3b678b5b043c5a8c93aa616d5ee574c

请注意,有 2 个 ReadImage 方法,您列出的 Python 文档字符串就是其中之一。

从 SimpleITK 示例这里是阅读 DICOM 系列的片段:

print( "Reading Dicom directory:", sys.argv[1] )
reader = sitk.ImageSeriesReader()

dicom_names = reader.GetGDCMSeriesFileNames( sys.argv[1] )
reader.SetFileNames(dicom_names)

image = reader.Execute()

这使用类接口而不是过程。这只是:

image = sitk.ReadImage(dicom_names)

或通常使用字符串文件名列表:

image = sitk.ReadImage(["image1.png", "image2.png"...])

许多常见的数组类型的字符串将被隐式转换为 SWIGVectorString类型。

于 2017-07-14T13:03:12.680 回答