Missing methods

Hello,

I am trying to use sitk with Unity (C#). I have added the native and managed dll to my project.
I tried to follow the fundamental concepts here https://simpleitk.readthedocs.io/en/master/fundamentalConcepts.html
However, I can’t seem to use some methods while others work with no issue. For instance I wasn’t able to use image.GetPixel(), method isn’t defined; no problem with image.GetDimension() for exemple.

I am probably missing something simple but I’m pretty new to this.

Also, I think the dll is intended for .NET 3.5 while Unity allows only 2.0 or 4.0. How can I resolve this issue ? I read that I can build the files against .NET 3.5 but i’m unsure how to.

Thanks a lot !

The GetPixel example in the documentation uses some extra Python interface icing that is not in other languages. C# and other languages more closely follow the C++ Image interface. More specifically, C# is a strongly typed language and a single GetPixel method can not easily return different pixel types. So the Image class has a set of GetPixel methods for the specific types. For example if the image is of sitk.sitkUInt8 pixel type then the GetPixelAsUInt8 method needs to be use to get a pixel’s value.

The .NET environment should be backwardly compatible, so the SimpleITK 3.5 .NET binary should be able to be run with a 4.0 application.

Please look at the general build instructions for how to get started building SimpleITK if required.

2 Likes

Thanks to @zivy for updating the “GetPixel” section of the concepts page to clarify how it differs for different language.s

Hey
Thanks a lot for your answer ! It makes much more sense now. I was then able to successfully implement some nifti handler and viewer with unity.

Thanks again !

2 Likes

Hey,
Actually I have another short question: I realised my nifti files are of very different pixel types. Is there any simple way to extract their values or do I have to redefine my method for every single type possible and then check the image at first ?
Thanks in advance

Hello @Brumeux,

As far as I know, this is a characteristic of C#, you can’t have a function return different types. The closest to a function returning different types is to use a template function ( T GetPixel<T>(image, index){}), but that defeats your purpose as you have to specify T, just like you need to select the appropriate function in the SimpleITK code.

Bottom line, you’ll need to check for pixel type, GetPixelID, and call the appropriate function GetPixelAsUInt8, GetPixelAsFloat

If you have enough memory and are more interested in generic code, then you could up-convert all images to the highest common denominator during reading. For instance if they are uint8, uint16, uint32 you can read all of them as uint32 (see ImageFileReader's SetOutputPixelType). In the extreme you can read everything as double which covers pretty much any input (excluding multi-channel images and complex pixel type).

2 Likes

Exactly what I was looking for. Didn’t know I could use higher values to handle other types. Thanks a lot !