Segmentation and modeling of MRI image

Hi,

I want to implement the segmentation of bladder from pelvic floor MRI images and then implement 3D reconstruction of the organ in a python scripted module.
I currently created a model which can predict by each pixel of the MRI image. The model returns a (227,227,30) matrix of value 0 and 1. (the MRI image has 30 images with 227*227 pixels). In the matrix, 1 indicates this pixel is a part of bladder and 0 is not. This model tells the position of the segmented organ in the image.
For the 3D Modeling part, I think the Show 3D and Fill between slices of the Segment Editor module will do it. But how can I segment the organ by the matrix predicted by my model? Does anyone have any idea how to implement this?

Thanks for your time!
Andrea

The data you call model we call binary labelmap. Please load is to Slicer as a labelmap (choose labelmap in the options of the load window, or convert it to labelmap after loading in the Volumes module), then import it as a segmentation (right-click labelmap in Data module and choose import labelmap to segmentation).

Hi, thanks so much for your help.
Your idea seems practical but I’m sorry I didn’t completely understand. I load MRI images in the format .gz to Slicer, and the model is a .h5 file which is made of a convolutional neural network. My model can predict the MRI images to a (227,227,30) matrix. What should I load to Slicer? I’m new to Slicer so sorry for lack of knowledge.

Save the “model” (we call it labelmap volume) as a .nrrd or .mha file and you will be able to load it as segmentation or labelmap volume.

Hi, thanks for answering.
I’m a little confused. The “model” is a deep convolutional neural network, how can I load it as volume?

@ZiyunLiang, what you call the “matrix” (output of your neural network “model”) is what we call a labelmap, so if you load that into Slicer, you can make it into a what Slicer calls a “model” which is a triangulated surface. :grinning:

1 Like

That’s right. matrix = labelmap, not model as I said.

You cannot import your model to Slicer, but if it’s python or C++ or Matlab, then you can integrate it within a new module.

1 Like

Hi, really appreciate your help and explanation, I have figured out a way to implement this now. However, I still got a problem when I’m trying to write it in my scripted python module.
When I’m trying to convert my volume to labelmap by using Volumes module, Volume information section, and Convert to label map
I used the code

volumeNode=slicer.util.getNode(‘vtkMRMLScalarVolumeNode1’)
labelmap=slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLabelMapVolumeNode’)
slicer.modules.Volumes.logic().CreateLabelVolumeFromVolume(vtkMRMLScene,label map,volumeNode)

But there is something wrong.

AttributeError: ‘module’ object has no attribute ‘Volumes’

I don’t have much experience in writing python code in 3d Slicer so please help me out. What is the correct way of realizing this?

Thanks for your time!

You have the case wrong which is causing the attribute error.

slicer.modules.Volumes.logic().CreateLabelVolumeFromVolume(vtkMRMLScene,label map,volumeNode)

should be

slicer.modules.volumes.logic().CreateLabelVolumeFromVolume(vtkMRMLScene,label map,volumeNode)

A tip is also to press {TAB} after any period to see the available options in an auto-complete type of way.

Hi, thanks for the quick response and the tip, I’ll keep that in mind. I tried this but I think I’m still implementing this function wrong. What should the vtkMRMLScene be?

NameError: name ‘vtkMRMLScene’ is not defined

Yes any variable needs to be defined as well. In this case, vtkMRMLScene wasn’t defined. We can instead use “slicer.mrmlScene” which is defined.

slicer.modules.volumes.logic().CreateLabelVolumeFromVolume(slicer.mrmlScene, labelmap, volumeNode)

Hi James,
Thanks so much for your help. It’s working now.:grinning:

1 Like

Instead of this approach, I’d load the volume as labelmap to begin with:

slicer.util.loadLabelVolume('d:/path/to/Voulme.nrrd',{})

This is indeed an easier way to do this. Thanks:smiley: