Skip to content

Create 3D surfaces using Mango

Lani Cupo edited this page Aug 4, 2023 · 11 revisions

Mango (http://ric.uthscsa.edu/mango/) is a useful tool for creating 3D surfaces from label files. This can be helpful in displaying the spatial organization of a label/region of interest, especially in comparison to a slice view. To do this, you will need to convert your label to a nifti file, create a separate file for each label value, then create a surface for each of these files using mango. Instructions and examples are below.

In the instructions below, left-hc.mnc is the original label file. It has 4 values (1, 2, 3, 4).

  1. Convert .mnc to .nii Fix the range of the .mnc file, this ensures label values don’t get distorted in the conversion. Without this, you could have label 1 end up with a value of 1.005 for example. The following mincreshape command does this:
module load minc-toolkit
mincreshape -normalize -unsigned -byte -image_range 0 255 -valid_range 0 255 left-hc.mnc left-hc_fix.mnc

Convert to .nii, zip the file

mnc2nii left-hc_fix.mnc left-hc_fix.nii
gzip left-hc_fix.nii
  1. Separate the file such that you have one file for each label value (4 total files in this example). You can use the fslmaths command to do this as follows:
module unload minc-toolkit
module load FSL
fslmaths left-hc_fix.nii.gz -thr 1 -uthr 1 left-hc_fix_1.nii.gz
fslmaths left-hc_fix.nii.gz -thr 2 -uthr 2 left-hc_fix_2.nii.gz
fslmaths left-hc_fix.nii.gz -thr 3 -uthr 3 left-hc_fix_3.nii.gz
fslmaths left-hc_fix.nii.gz -thr 4 -uthr 4 left-hc_fix_4.nii.gz

Use fsleyes to view each of the created files above to ensure they are as expected:

fsleyes left-hc_fix_1.nii.gz
  1. Use mango to create a surface for each of the separate label files. You can open mango from the command line by running the command mango
module load mango
mango

  1. Open the first of your label files using the Open tab:

  1. Under the Image tab, select build surface:

Click ok, and mango will build a surface. This may take up to a minute. After the surface is complete, a new window will pop up displaying the newly created surface.

  1. In the surface window, use the File tab to export the surface as a .vtk file:

  1. After exporting, close the image window. Then repeat steps 4-6 for each label value. After creating a surface for your final label, build the surface and export to a .vtk file. Instead of closing the surface and image windows, load in the other surfaces you created using the Shapes -> load from file tab:

You should then be able to view all of your newly created surfaces together.

  1. For visualization purposes, you can change the colour of each surface by using the 'Material' option:

These steps describe creating a visual 3D representation of your label files. Mango does appear to have many other powerful features, feel free to explore at http://ric.uthscsa.edu/mango/. Also, be sure to credit Mango in any publications by referencing the website.

Using the command line to create surfaces

(Mango v3.5 and above)

  1. Open Mango (step 3 - previous section)

  2. Go to options -> select install utilities.
    Click install. Once installed, click OK.

  3. Go to options -> script manager.

Screen Shot 2020-05-23 at 7 10 22 PM

  1. Include the following code.

    m_SurfMan_result = m_VolMan_manager.buildSurface( 50,True,True,False,True,2.0,3,1.0,1.0,1.0,True,0.2,44.0,1)

    m_VolMan_manager.surfaceManager.exportTo( m_VolMan_manager.makeFilename(".vtk"),"VTK",None, "Allow line breaks=false,Include normals=false")

    Note: the output file type in this case is .vtk. You may use other formats such as .surf.gii

  2. Name your script (e.g. make_surface) and click save.

Screen Shot 2020-05-23 at 6 44 17 PM

  1. In the command line, enter: mango-script "make_surface" input.nii This should give a .vtk file as the output.

    For example: mango-script "make_surface" HAD0064_labels.nii would give the output file HAD0064_labels.vtk

Creating 3D visualizations/movies of stats.

  1. Open mango

  2. Open > Open Image

  3. Select your population average produced by the DBM (e.g. template_sharpen_shapeupdate.nii.gz). Must be in nifti format. It will be opened in three 2-d views, like with Display: image

  4. At the top of the window with this image, go to Image > Build Surface. Defaults should be fine. A new window will open with a 3d rendering:

image

  1. Click on the original window (3 2-d views). Go to File > Add Overlay and select your stats file, saved in nifti format. They will display on the average:

image

  1. On the small window with the color bar slider, set the lower bound to the lower value you are interested in (from FDR), such as the value associated with 10% FDR. Set the upper to the highest value you are interested in (1% FDR, or max). If you want to show negative values, just add the negative sign.
  2. If you want to switch the color bar for negatives or choose another value, then, in the small window, select Options > Color Table Manager >(New Color Table) and your selection, such as "Blue Overlay" > Done

image

  1. Now, to display it on your 3d rendering, go to the Surface window (with the 3d image). Go to Shapes > Add Overlay, you should see the name of the file and the color bar in the pop up. Select "Add"
  2. You still won't be able to see the hot spot, because the surface is not transparent. You can make it transparent by going to Surface > Material and increasing the "Transparency":

image

  1. In my case, this isn't very good, however, because you cannot see any of the internal anatomy that will tell us where this hotspot is. Instead, I will remove the transparency (again with Surface > Material) and add a cutout. Go to Surface > All Cut Planes:

image

  1. Adjust the Cut planes to best visualize your hot spot. For example, I will go Surface > Sagittal Cut Plane > Right because I think it looks better. You can adjust the position of the cross-hair (cut-planes) by moving the cursor in the other window with the three 2-d views:

image

  1. If you want to create an image or movie of the rotating file, go to Surface >Create Snapshot or > Create Video
  2. If you want to add your positive values on the same image, you can repeat the steps from 5-8 with a different Color map and threshold.
Clone this wiki locally