[ITK] Can python sitk.ReadImage read a list of images?
Lowekamp, Bradley (NIH/NLM/LHC) [C]
blowekamp at mail.nih.gov
Fri Jul 14 09:06:44 EDT 2017
Please avoid cross posting questions.
I’ll repost my answer here for completeness though:
SimpleITK uses SWIG to wrap a C++ interface to Insight Segmentation and Registration Toolkit (ITK). As such the inline python documentation should be supplemented with the C++ Doxygen documentation. There is a mapping of C++ types to Python types with robust implicit conversion between them. You can find the documentation for the sitk::ReadImage methods here:
https://itk.org/SimpleITKDoxygen/html/namespaceitk_1_1simple.html#ae3b678b5b043c5a8c93aa616d5ee574c
Notice there are 2 ReadImage methods, and the Python docstring you listed appears is one of them.
From the SimpleITK examples here is a snippet to read a DICOM series:
print( "Reading Dicom directory:", sys.argv[1] )
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames( sys.argv[1] )
reader.SetFileNames(dicom_names)
image = reader.Execute()
This uses the class interface as opposed to the procedural. Which would simply be:
image = sitk.ReadImage(dicom_names)
or generically with a list of string filenames:
image = sitk.ReadImage(["image1.png", "image2.png"...])
Many common array like type of strings will be implicitly converted to the SWIG VectorStringtype.
From: Oren <oren.a4 at gmail.com>
Date: Friday, July 14, 2017 at 3:12 AM
To: "community at itk.org" <community at itk.org>
Subject: [ITK] Can python sitk.ReadImage read a list of images?
Hello,
I do not understand if sitk.ReadImage can read a list of images or not? I did not manage to find an example showing how to list of images should be imputed to the function.
But in the function documentations it say:
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.
So it seems from the documentations that it is possible. Can someone show me a simple example.
I also posted the question in stackoverflow in case anyone else will ask it in the future:
https://stackoverflow.com/questions/45096861/can-python-sitk-readimage-read-a-list-series-of-images
Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20170714/7a432c81/attachment-0001.html>
More information about the Community
mailing list