Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleITK not working with any data type, be it 3D or 2D #592

Closed
StuckinPhD opened this issue Nov 13, 2018 · 5 comments
Closed

SimpleITK not working with any data type, be it 3D or 2D #592

StuckinPhD opened this issue Nov 13, 2018 · 5 comments
Labels

Comments

@StuckinPhD
Copy link

I'm using SimpleITK to load in a layered tiff image, its a volumetric image having 30 planes/slices.

After playing around a lot with skimage and imageio Ive found out that SimpleITK is the best way to handle volumetric images but the problem is that none of the functions seem to work for my image.

img = sitk.ReadImage(path)

After reading the image in, I can easily convert it to numpy and even display it using sitk.Show() so its loading up properly. but any function I use on it such as:

img_s = sitk.CurvatureFlow(img, 0.125, 5)
# or
sitk.IntensityWindowing(img)
# or
img_m = sitk.ConnectedThreshold(img, (257,419,7))

gives the warning:

sitk::ERROR: Pixel type: vector of 16-bit unsigned integer is not
supported in 3D byclass itk::simple::

I tried casting to to any other datatype as well but I keep getting errors again:

img2 = sitk.Cast(img, sitk.sitkFloat32)

sitk::ERROR: Filter does not support casting from casting vector of
16-bit unsigned integer to 32-bit float

I tried a 2D variation as well of the above:

img_m = sitk.ConnectedThreshold(img2[:,:,7], [(257,419)])

but this time I got the error:

sitk::ERROR: Pixel type: vector of 64-bit float is not supported in 2D
byclass itk::simple::ConnectedThresholdImageFilter

Any idea what may be causing this?

Thanks

@blowekamp
Copy link
Member

Your image is a multi-component vector image, it's pixel type is "vector of 16-bit unsigned integer". Perhaps the image is an RGB image? You can get the number of components with img.GetNumberOfComponentsPerPixel() or looking at the image's meta-data via "print(img)".

The first filters only support scalar images, and not vector images. You could select the first components with sitk.VectorIndexSelectionCast(img,0).

img2 = sitk.Cast(img, sitk.sitkFloat32)

You can not cast a vector image to s scalar, try casting to sitk.sitkVectorFloat32.

@StuckinPhD
Copy link
Author

Your image is a multi-component vector image, it's pixel type is "vector of 16-bit unsigned integer". Perhaps the image is an RGB image? You can get the number of components with img.GetNumberOfComponentsPerPixel() or looking at the image's meta-data via "print(img)".

The first filters only support scalar images, and not vector images. You could select the first components with sitk.VectorIndexSelectionCast(img,0).

img2 = sitk.Cast(img, sitk.sitkFloat32)

You can not cast a vector image to s scalar, try casting to sitk.sitkVectorFloat32.

Thank you for responding. Yes the image is a grayscale TIFF image. My original image is a "Leica Image Format, .lif" file. SimpleITK does not support that I believe so I used bio-formats in ImageJ to export it to a multi-layered TIFF file, and that is what I am using as input here. Is there a better way to handle this?

Below is the output of print(img)

VectorImage (0000020E9CC62E20)
  RTTI typeinfo:   class itk::VectorImage<unsigned short,3>
  Reference Count: 1
  Modified Time: 957
  Debug: Off
  Object Name: 
  Observers: 
    none
  Source: (none)
  Source output name: (none)
  Release Data: Off
  Data Released: False
  Global Release Data: Off
  PipelineMTime: 944
  UpdateMTime: 956
  RealTimeStamp: 0 seconds 
  LargestPossibleRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [1024, 512, 30]
  BufferedRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [1024, 512, 30]
  RequestedRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [1024, 512, 30]
  Spacing: [0.000568182, 0.000568182, 1]
  Origin: [0, 0, 0]
  Direction: 
1 0 0
0 1 0
0 0 1
  IndexToPointMatrix: 
0.000568182 0 0
0 0.000568182 0
0 0 1
  PointToIndexMatrix: 
1760 0 0
0 1760 0
0 0 1
  Inverse Direction: 
1 0 0
0 1 0
0 0 1
  VectorLength: 3
  PixelContainer: 
    ImportImageContainer (0000020E9C8AB710)
      RTTI typeinfo:   class itk::ImportImageContainer<unsigned __int64,unsigned short>
      Reference Count: 1
      Modified Time: 953
      Debug: Off
      Object Name: 
      Observers: 
        none
      Pointer: 0000020EA50C9040
      Container manages memory: true
      Size: 47185920
      Capacity: 47185920

sitk.VectorIndexSelectionCast(img,0) gave me an output having all zero's. No imformation was retained from the original image?

Thanks

@blowekamp
Copy link
Member

Yes, reading microscopy image formats can be tricky. We are actively working on getting SCIFIO (bio-formats) to work better with SimpleITK, and improve the ability to read microscopy file formats. Using SCIFIO, right now requires compelling SimpleITK's master branch with some custom configuration flags. Here is a recent discussion: https://discourse.itk.org/t/reading-images-via-scifio-handle-5-d-images/918/3

I am not sure you need to convert the file with ImageJ/FIJI. You image is still a multi-component image, which is the original source of the error message. It appears the you expect the image to just be grayscale but it's actually a multi-component image.

I'd recommend loading the original image, and running the StatisticsImageFilter on each of the components of the image.

I suspect that there was a conversion problem going form a 16-bit to 8-bit data. We need to know the range of values of the original input image.

@StuckinPhD
Copy link
Author

Thanks for the reply @blowekamp

I'd recommend loading the original image, and running the StatisticsImageFilter on each of the components of the image.

By original file, do you mean the original .lif file? I tried that and followed your method that you gave in your link above but got the following:

path2 = 'C:\\300117.lif'
reader = sitk.ImageFileReader()
reader.SetFileName(path2)
reader.ReadImageInformation()

RuntimeError: Exception thrown in SimpleITK ImageFileReader_ReadImageInformation: C:\d\VS14-Win64-pkg\SimpleITK\Code\IO\src\sitkImageReaderBase.cxx:97:
sitk::ERROR: Unable to determine ImageIO reader for "C:\300117.lif"

We need to know the range of values of the original input image.

Im happy to provide this, can you please let me know what you mean or how I can determine the range of values?

Thanks for your help

@blowekamp
Copy link
Member

Thank you for your questions. If your problem is not resolved you are welcome to reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants