.nii to .vtk AND keeping the voxel values

372 views
Skip to first unread message

Shahin Safazadeh

unread,
May 5, 2021, 4:16:05 AM5/5/21
to itksnap-users
Hi everyone,

I am having a probelm converting a fMRI .nii file to .vtk, using ITK-SNAP.

First, I open an anatomical image. After that, I open the functional MRI image using the "segmention" section. Then, I export the data as "surface mesh" (.vtk format). 
The voxels in the fMRI image have values between 0 and 1. Here is the issue. ITK-SNAP rounds down the voxel values below 1 to 0, and below 2 to 1. So, I lose the voxel values in the .vtk image.

Is it possible to convert the .nii image to .vtk AND keeping the voxel values? Is there any kind of threshold setting in ITK-SNAP for this purpose?

Thank you in advance.

Jilei Hao

unread,
May 5, 2021, 9:24:49 PM5/5/21
to itksna...@googlegroups.com
Hi Shahin,

Voxel values in segmentation images in ITK-SNAP can only be represented by integers (unsigned short). So mesh export cannot export decimal values to .vtk image.

Thanks,
Jilei

--
You received this message because you are subscribed to the Google Groups "itksnap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to itksnap-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/itksnap-users/d9a12fca-bb29-4661-a2f9-c24ececca877n%40googlegroups.com.

Shahin Safazadeh

unread,
May 6, 2021, 3:00:59 AM5/6/21
to itksnap-users
Hi Jilei,

Thanks for your answer.

In a modification, I expanded the range of voxel values to [1:100], all integers. Now, I do not most of the voxels in the segmented image. Do know what could be the reasons? Is it because too many small isosurfaces cannot be made in a file?

Thanks.

Markus Heller

unread,
May 6, 2021, 4:20:26 AM5/6/21
to itksnap-users
Dear Shahin,

at least to me it is a bit unclear what exactly your starting point is and where you actually want to go.

Part of the confusion may stem from the fact that .vtk can either be indicative of a format to store 3D image data, much like .nii.gz or .mhd or similar formats but on the other hand you can represent geometry (surfaces, points, etc.) also in that format.

If you want to create a surface representation of a segmentation in ITK-SNAP, you need your image data together with the segmentation.
As explained before, segmentations are represented by unsigned shorts, where each interger/label represents a different material.
Given that eah interger represents a different object I don't quite get what you tried to achieve by changing the range of your segmentation lables?
If your initial segmentation was more like a probability map (0 - no chance a voxel represents the object of interest; 1 the voxel defeinitively represents the desired object] you could simply threshold that data to get a binary representation of background and forground (objetc of interest) using the c3d command line tool (https://sourceforge.net/p/c3d/git/ci/master/tree/doc/c3d.md).

From your description I'm not sure whether the data you seem to try to convert is an actual segmentation with such kind of lables though or is indeed just another image? For the latter case a first step would indeed be to segment the structures of interest first and assign the relevant labels.

To generate a surface from a segmentation, typically a marching cubes algorith is used and often there is also some some smoothing/further processing involved. In ITK-SNAP there are a few settings which influence that processing here - you can find these under "Tools", "Preferences", "3D Rendering" menu (settings for smoothing and decimation) -- they will influence the resulting surface. If you have rather small features/objects, these may be "removed" during "too intense" smoothing.

Hope that helps,
 Markus

Shahin Safazadeh

unread,
May 6, 2021, 5:09:46 AM5/6/21
to itksna...@googlegroups.com

Dear Markus,

Thanks very much for your reply.

The goal is to illustrate a section of the brain (3D) in the ParaView software. For that, the image has to be in .vtk format in order to depict the 3D surface of the brain. (Please see the first attached screenshot.)

The voxel values in the brain nifti image are the result of Principal Component Analysis (PCA). However, I normalized them to be fitted in the range [0:1]. This range can be modified as long as the relative ratio between the voxel values is saved.

As you can see in the attached image, there are 10 different values  (shown in 10 different colors) representative of the voxel values. This is when I modified the range to [1:10] integers. However, this reduces the detail in the image since the relative ratio between the voxel values is not saved. To address that, I thought I can expand the range (e.g. [1:100]) to keep more details. Although, when I increase the range (integer, too),  the polygons in the 3D image get less dense! You can see the 2nd attached image.
This is what I could not understand!

Do you know why this happens? And how to fix it?

Thanks very much.

Bests,
Shahin


You received this message because you are subscribed to a topic in the Google Groups "itksnap-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/itksnap-users/Aki-pjKiIZg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to itksnap-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/itksnap-users/cc47fb64-184b-431a-8791-60d4e800e241n%40googlegroups.com.


--
Screen Shot 2021-05-06 at 10.56.26.png
Screen Shot 2021-05-06 at 11.05.25.png

Markus Heller

unread,
May 7, 2021, 2:40:56 AM5/7/21
to itksnap-users

The effect you describe is to be expected - such behaviour is comparable e.g. to a situation where you determine a hstogram and compare conditions for a smaller vs. a larger number of bins. The more bins you define, the smaller the number of voxels in a certain category will be. For you case that means that there will be less voxels assoiated to the ID and thus volume/area per interger will be smaller. The idea of the segmentation is that each label (integer ID) represents a different structcure/object - and as mentioned before I'm not sure whether that is really what you want/need.

I'm not a domain expert here so you might really have to check with colleagues from your area to understand in how far the approach is best suited to achieve your desired goal.

I do have a feeling though that thresholding your [0...1] data set might be closer to what what you really want - indeed looking at a histogram of the data might help to decide where the threshold should be defined. In principle such thresholding is really easy with the c3d command line tool that is part of the ITK-SNAP installation.If you try something along the lines of:
c3d fmri.img -threshold 0 0.7 1 0 -type uchar -o data_thresholded_at_0.7.nii.gz
and then load the result as segmentation in ITK-SNAP and finally generate a surface from that you might(!!)  be closer to where you want to be. Results will of course depend on the choice of the threshold value and 0.7 is just a random choice here.

Otherwise you can of course also use ParaView to generate isosorfaces from the fmri data directly - there are quite a few ways to do that e.g. for just looking at the data:
Doing so might give you some good insight into the fmri data in the first place and may help to decide on a threshold to generate suitable isosurfaces for further processing/analysis if you so desire.

Best wishes,
 Markus
Reply all
Reply to author
Forward
0 new messages