I have been dabbling with SimpleITK in python for a while now, and just now I ran in to an issue I cannot find the answer to. From the documentation it is possible to create images with complex type (sitkComplexFloat32, sitkComplexFloat64) (https://simpleitk.readthedocs.io/en/master/Documentation/docs/source/fundamentalConcepts.html)
SimpleITK images are either 2D, 3D, or 4D and can have an arbitrary number of channels with a scalar or complex value in each channel.
However, I can’t go much further than to create an empty complex image. If I try to export that image as a numpy array I get the error message
RuntimeError: Images of Complex Pixel types currently are not supported.
I get similar error if I try to create a image from a complex numpy array, or if I try the slicing operators on my complex image.
Will this support be added? Otherwise I think it is a bit misleading to state that SimpleITK support complex values, when all you can do is create an empty complex image.
Thank you in advance!
You are quite right that the
complex support for the
GetImageFromArray methods are missing! Can you please create an issue in SimpleITK on Github?
The support for complex images in SimpleITK has focused of course on the
Image class, FFTs, image math, image grid operations and of course IO.
Here is quick grok at a list of filters which support complex pixel types in SimpleITK:
I did notice that the
ResampleImageFilter is not on that list. As I recall not all ITK interpolators worked with complex pixels so it would not be an easy task to add resample support.
Are there filters you tried to use with complex images?
Thanks for the quick reply! I will create an issue on GitHub. Wow, there are quite a few filters that support complex images, I’m pleasantly surprised I tried the MedianImageFilter, and that did not work (maybe not surprisingly, I don’t know how that would work). I also tried the WriteImage filter, and it produced an mhd file pixel type MET_FLOAT with two channels, so I assume that’s in order.
Would it be possible to add the interpolators that do work for complex images, in order to get
ResampleImageFilter to work? I think that would be a useful function, even though it would be limited.
Resample operations would be separable, meaning that you could do the operation twice on the imaginary then the real component of the complex number.
The usage of complex number images have typical been limited to operations related to FFT operations and basic math. I am curious if you have a driving problem, or if you are simply curious of what can be done with complex numbers in SimpleITK?
I’m mostly curious of how SimpleITK handles complex numbers. I work with MRI images, which are complex at their core, so I’m currently exploring what support the SimpleITK image class has for these types of applications.
I recall asking about
ResampleImageFilter in ITK itself and complex numbers some time ago and receiving a similar answer about the interpolators (something to do with complex numbers not having a natural ordering). If any support for resampling complex-images could be added to ITK I would be very, very grateful. I regularly have to resample complex-valued images and having to split them into real and imaginary components, resample, and then recombine is highly annoying.
Does this recent commit help? Also, vector resample is now deprecated, and this example shows how to use it. Does this not work for
complex pixel type?
Here is a pull request which adds complex pixel type support to the