How can I generate and save volume rendered images of brain arteries

how can I generate and save images that are in nii (nifti) format into volume rendered image using simpleITK

Hello @Aleena_Suhail,

Not clear what it is that you want to do. There is no ā€œvolume renderedā€ image in ITK or SimpleITK. You have an image file, in a variety of formats, and you have an image in memory.

I am guessing here that you want to read a nifti volume from file and display it using volume rendering. For that functionality, see itkwidgets.

If this is not what you want, please be more specific.

I wish to visualise and save 3D MRI image in 2D using volume rendering technique how can I do this using SimpleITK

Got it.

So itkwidgets should work for that. The view has a variety of parameters you will need to play with. This assumes you are working in a Jupyter notebook. If you are looking for a more turnkey and medically oriented visualization with good/standard preset rendering parameters Iā€™d recommend using Slicer (see documentation).

import SimpleITK as sitk
import itkwidgets

image = sitk.ReadImage('training_001_mr_T1.mha')
itkwidgets.view(image, cmap=itkwidgets.cm.gray)

Thank you
the following code runs but I cannot visualise or save the image can you please help me with how I can amend the code to visualise the image on Google Colab and save it

import itkwidgets

import SimpleITK as sitk

image = sitk.ReadImage(ā€™/content/drive/MyDrive/3D/10001/10001_TOF.nii.gzā€™)

itkwidgets.view(image, cmap=itkwidgets.cm.gray)

Hello @Aleena_Suhail,

What exactly is the problem?

If the code runs without errors, you should see something. It may not look correct due to the transfer function settings, but that just means you need to modify those to get a good visualization.

If this is not the case, then please be more specific about the problem. What error message are you getting, etc.

What she probably wants is something like:

view3d = itkwidgets.view(image, cmap=itkwidgets.cm.gray)
rendered3D = view3d.screenshot()
sitk.WriteImage(rendered3D, '/content/drive/MyDrive/3D/10001/10001_TOF.png')

And .screenshot() function probably does not exist.

1 Like

Yes, what can I use instead of screenshot the following code is giving me an error
image = sitk.ReadImage(ā€˜/content/drive/MyDrive/3D/10001/10001_TOF.nii.gzā€™)

view3d = itkwidgets.view(image, cmap=itkwidgets.cm.gray)

rendered3D = view3d.screenshot()

sitk.WriteImage(rendered3D, ā€˜/content/drive/MyDrive/3D/10001/10001_TOF.pngā€™)

image = sitk.ReadImage(ā€™/content/drive/MyDrive/3D/10001/10001_TOF.nii.gzā€™)

view3d = itkwidgets.view(image, cmap=itkwidgets.cm.gray)

rendered3D = view3d.screenshot()

sitk.WriteImage(rendered3D, '/content/drive/MyDrive/3D/10001/10001_TOF.pngā€™)

something like this what should I replace screenshot with because it is giving me an error

This might be a way, because itkwidgets use vtk.js for rendering.

I donā€™t know if this SO question is helpful.

@matt.mccormick might have a suggestion.

1 Like