T2 Map Multi-volume related questions

Operating system: Ubuntu 16
Slicer version: 4.8
Expected behavior: Display volume information and an image
Actual behavior: Slicer displays a white image and crash when opening the “Volume” Module

Dear all,
I have a CD contains a DICOM of MRI T2 Map Volume. I converted the contents to nrrd to do some experience. This produces 9 volumes: imgT2MAP_0 to imgT2MAP_7 (8 separate files nrrd files) and one nrrd file imgT2MAP of type vtkMRMLMultiVolumeNode.

When I open the last file in Slicer it display an image but it does not show voxel values in the Data Probe. Instead it displays “8 components”. My question is how this image is represented with these 8 values? what are the gray values in the shown image?

I tried to do some computation e.g. generate the first image imgT2MAP_0 from imgT2MAP by taking only the first value from the vector. The code runs but I got a white image, when I open the resulted volume in “Volume” Slicer crashes. Here is the code (forgive my dirty coding as I wrote in a hurry):

    v = self.inputSelector.currentNode()
    # get image properties 
    vd=v.GetImageData()
    sz=vd.GetDimensions()
    sp= v.GetSpacing()
    og= v.GetOrigin()
    dm = vtk.vtkMatrix4x4()
    v.GetIJKToRASDirectionMatrix(dm)
    va = slicer.util.array(v.GetID())    
    tp =  vd.GetScalarType()

    img=vtk.vtkImageData()
    img.SetDimensions(sz)
    img.AllocateScalars(tp, 1)
    thresholder=vtk.vtkImageThreshold()
    thresholder.SetInputData(img)
    thresholder.SetInValue(0)
    thresholder.SetOutValue(0)        
    vn=slicer.vtkMRMLScalarVolumeNode()
    vn.SetSpacing(sp)
    vn.SetOrigin(og) 
    vn.SetIJKToRASDirectionMatrix(dm)     
    vn.SetImageDataConnection(thresholder.GetOutputPort())
    vn.SetName("imgT2MapOutput")      
    
    # Add volume to scene
    slicer.mrmlScene.AddNode(vn)
    displayNode=slicer.vtkMRMLScalarVolumeDisplayNode()
    slicer.mrmlScene.AddNode(displayNode)
    colorNode = slicer.util.getNode('Grey')
    displayNode.SetAndObserveColorNodeID(colorNode.GetID())
    vn.SetAndObserveDisplayNodeID(displayNode.GetID())
    vn.CreateDefaultStorageNode()
     
     
    vm = slicer.util.getNode("imgT2MapOutPut")
    vmd=vm.GetImageData()
    vma = slicer.util.array(vm.GetID())    
   
    for k in xrange(0, sz[0]):  
        for j in xrange(0,sz[1]):
            for i in xrange(0, sz[2]):
                vc= va[i,j,k]
                vma [i,j,k] =  vc[0] 
     
    vm.Modified()  

Please help me to find out what makes this strange output and slicer crash in the previous code. Also, I would like to know if there is a better way to do the same thing e.g. using iterators instead of loops.
Thanks!

You can load 4D nrrd files if Sequences module is installed. In Add data dialog, choose Volume sequence for the data set. If you use .seq.nrrd extension instead of just .nrrd then Volume sequence will be selected by default.

1 Like

Hi Andras and thanks for your reply,

  • I installed the sequence extension.
  • I changed the file by adding .seq and load the volume as you described.
  • In Volume Module. The volume type is changed.

This is helpful for viewing but I still can not do computations e.g. generate different nodes from the sequence or compute T2 mapping. Could you please check the code I wrote and help with mentioned issues.

Best!
Ibraheem

See SequenceRegistration extension for an example for how to access, create, and modify volume sequences.

Do you plan to improve T2 mapping extension?

Thanks for the reply and the info.
I didn’t know that there is already such an extension, why it does not appear in Slicer’s extension manager?

I was planning to use Scipy to do the fitting so at the end I have only one file python code to make a simple portable Slicer plugin.
I will check the links today.

Still (for the sake of knowledge), I don’t know what cause the issues in the code above. If I change this line:

vma [i,j,k] =  vc[0]  

To be something like

vma [i,j,k] =  0 

or

vma [i,j,k] =  4000

In both situations, Slicer does not crash when I load the resulted volume in “Volume” module. It crashes only when I try to assign voxel value from the multi volume. I printed the value of vc[0] and it looks like a single scalar value (not a vector).

When you copy between numpy arrays, numpy tries to do shallow copies. During shallow copying, numpy reallocates memory and shares it between arrays, which is a prohibited operation on the VTK-managed array that slicer.util.array returns. See more information here.

1 Like

Now it works, thanks for your continuous support.
:slight_smile:

1 Like

T2Mapping extension was only added to the latest master version of Slicer, which currently in a transitioning phase and so not all extensions are available.

I’ve now added T2mapping to the latest stable (4.8.1) extension index, so the T2mapping extension should show up tomorrow in stable version’s extension manager.

Thanks for your concern. The extension is useful. but there is only one issue that the result is not shown after computation, something like this should be added to the end of the python file (in my case, I am interested in the Spine sagittal view):

yellow_logic = slicer.app.layoutManager().sliceWidget("Yellow").sliceLogic()
yellow_cn = yellow_logic.GetSliceCompositeNode()
yellow_cn.SetBackgroundVolumeID(T2outputVolume.GetID())
lm = slicer.app.layoutManager()
lm.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutOneUpYellowSliceView)

# Fit slice to window
sliceNodes = slicer.util.getNodes('vtkMRMLSliceNode*')
layoutManager = slicer.app.layoutManager()
for sliceNode in sliceNodes.values():
    sliceWidget = layoutManager.sliceWidget(sliceNode.GetLayoutName())
    if sliceWidget:
        sliceWidget.sliceLogic().FitSliceToAll()    
logging.info('Processing completed')

return True

Hi Andras:

I do not see T2mapping extension in extension manager. Please, let me know how to find and load it.

thanks

Nirotu

It will appear in the extension manager of Slicer-4.8.1 version tomorrow. For nightly builds (4.9.x) it should show up in a couple of days.

If you have any suggestion to improve the extension, please submit a pull request with your proposed changes.

Note that to show an image in slice viewers, you can use slicer.util.setSliceViewerLayers command.

Thank you, Andras.

A
Nirotu