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: