Overview
Forum
Mango
iMango
Papaya
Multi-image Analysis GUI
Download
User Guide
Developer Guide
Troubleshooting
Acknowledgements

Mango Script Examples

Add 1 to every voxel

m_Vol_baseVol = m_VolMan_manager.baseVolume
xDim = m_Vol_baseVol.XDim
yDim = m_Vol_baseVol.YDim
zDim = m_Vol_baseVol.ZDim
for z in range(zDim):
    for y in range(yDim):
         for x in range(xDim):
             val = m_Vol_baseVol.getVoxelValueAtIndex(x, y, z)
             m_Vol_baseVol.putVoxelValueAtIndex(x, y, z, val + 1)

Print out coordinate and value of every voxel in all selected ROIs

import sys

m_Vol_baseVol = m_VolMan_manager.baseVolume
m_ROIData_roi = m_VolMan_manager.roiData
selectedMask = m_ROIData_roi.selectedMask

if (selectedMask == 0):
    print "No ROI selected"
    sys.exit(1)

xDim = m_Vol_baseVol.XDim
yDim = m_Vol_baseVol.YDim
zDim = m_Vol_baseVol.ZDim

for z in range(zDim):
    for y in range(yDim):
         for x in range(xDim):
             if (m_ROIData_roi.getMaskValue(x, y, z) & selectedMask != 0):
                 val = m_Vol_baseVol.getVoxelValueAtIndex(x, y, z)
                 print `x` + '\t' + `y` + '\t' + `z` + '\t' + `val`

Create a snapshot of the top 10 overlay cluster maxima

Assumptions: There is at least one overlay loaded and it operates on the currently selected overlay

j_List_result = m_VolMan_manager.runClusterAnalysis(
    m_VolMan_manager.overlays[-1],4.0)

for i in range(0, min(10, j_List_result.size())):
    m_VolMan_manager.setCurrentPosition(
        j_List_result[i].analysis.maxCoordinate)
    m_VolMan_manager.captureSnapshot(
        m_VolMan_manager.makeFilename("_cluster" + `(i + 1)` + ".png"))

Generate ROIs of specified coordinates

size = 5
sameColor = False
worldCoordinates = False

coordinates = [
    [0, 0, 0],
    [20, 20, 20],
    # etc...
]

while (not sameColor and 
    (m_VolMan_manager.roiData.maximumColors < len(coordinates)) and
    (m_VolMan_manager.roiData.maximumColors < 64)):
    m_VolMan_manager.addMoreROIColors()

colorIndex = m_VolMan_manager.roiColor

for c in coordinates:
    if (not sameColor):
        m_VolMan_manager.roiColor = colorIndex
        colorIndex = (colorIndex + 1) % m_VolMan_manager.roiData.maximumColors

    coord = m_Coord(c[0],c[1],c[2])

    if (worldCoordinates):
        m_VolMan_manager.convertWorldToIndexCoordinate(coord)

    m_VolMan_manager.runAddROI(coord,size,True)

Create orthogonal slice view snapshots of the top 3 overlay cluster maxima

Assumptions: There is at least one overlay loaded and it operates on the currently selected overlay

j_List_result = m_VolMan_manager.runClusterAnalysis(
    m_VolMan_manager.overlays[-1],4.0)

for i in range(0, min(3, j_List_result.size())):
    m_VolMan_manager.setCurrentPosition(
        j_List_result[i].analysis.maxCoordinate)

    m_VolMan_manager.setSliceDirection(m_VolMan_manager.SLICE_DIRECTION_AXIAL)
    m_VolMan_manager.captureSnapshot(
        m_VolMan_manager.makeFilename("_cluster" + `(i + 1)` + "_axial.png"))

    m_VolMan_manager.setSliceDirection(m_VolMan_manager.SLICE_DIRECTION_CORONAL)
    m_VolMan_manager.captureSnapshot(
        m_VolMan_manager.makeFilename("_cluster" + `(i + 1)` + "_coronal.png"))

    m_VolMan_manager.setSliceDirection(m_VolMan_manager.SLICE_DIRECTION_SAGITTAL)
    m_VolMan_manager.captureSnapshot(
        m_VolMan_manager.makeFilename("_cluster" + `(i + 1)` + "_sagittal.png"))

Output atlas labels for the max coordinate of all currently listed statistics

Assumptions: World mode, atlas currently selected, one or more statistics operations have been run

atlas = m_Mango_mango.currentAtlas
analyses = m_Mango_mango.allAnalyses
for stat in analyses:
    maxCoord = stat.maxCoordinate.clone()
    m_VolMan_manager.convertIndexToWorldCoordinate(maxCoord)
    labels = atlas.getLabel(maxCoord.xDbl, maxCoord.yDbl, maxCoord.zDbl)
    coordStr = `maxCoord.xDbl` + "\t" + `maxCoord.yDbl` + "\t" + `maxCoord.zDbl`
    print coordStr + "\t" + '\t'.join(labels[i] for i in range(0,atlas.maxReturnedLabels))

Loop through series and position cursor at maximum value in each volume

import time
seriesLength = m_VolMan_manager.baseVolume.seriesLength
for t in range(seriesLength):
    m_VolMan_manager.setCurrentSeriesPoint(t)
    m_Stat_result = m_VolMan_manager.runVolumeStats()
    m_VolMan_manager.setCurrentPosition(m_Stat_result.getMaxCoordinate())
    time.sleep(2)

Loop over all ROI points and position cursor at each

import time
m_ROIData_roi = m_VolMan_manager.roiData
j_List_result = m_ROIData_roi.getUsedPoints()
for m_ROIPoint_point in j_List_result:
    m_Coord_point = m_Coord(m_ROIPoint_point.x, m_ROIPoint_point.y, m_ROIPoint_point.z)
    m_VolMan_manager.setCurrentPosition(m_Coord_point)
    time.sleep(2)

Create an animated video showing overlay clusters on a rendered semi-transparent surface

Assumptions: There is at least one overlay loaded and it operates on the currently selected overlay

import time

m_ImageVol_base = m_VolMan_manager.baseVolume
vox = m_ImageVol_base.voxelDimensions

m_SurfMan_result = m_VolMan_manager.buildSurface(
    m_ImageVol_base.imageRange.imageMax * .5,False,True,False,True,2.0,3,
    vox.XSize,vox.YSize,vox.ZSize,False,0.2,44.0,0)

time.sleep(1)  # give OpenGL time to render base surface

m_ImageVol_ovly = m_VolMan_manager.overlays[-1]
vox = m_ImageVol_ovly.voxelDimensions
m_Surf_result = m_VolMan_manager.surfaceManager.addShapeFromOverlay(
    m_ImageVol_ovly,"Overlay",-4259840,m_ImageVol_ovly.imageRange.imageMax * .5,
    True,False,False,2.0,3,vox.XSize,vox.YSize,vox.ZSize,False,0.2,44.0,0)

m_VolMan_manager.surfaceManager.setMaterial(
    m_VolMan_manager.surfaceManager.baseSurface,-1,True,False,False,0,0.51,0.0,
    64.0,3.0)

# make the video have smaller dimensions
m_VolMan_manager.surfaceManager.selectMenuOption("Zoom Out")
m_VolMan_manager.surfaceManager.selectMenuOption("Zoom Out")

m_VolMan_manager.surfaceManager.captureVideoStart(
    m_VolMan_manager.makeFilename(".avi"),0,0,30,True)

Create ROI spheres of constant size at overlay maxima

Assumptions: There is at least one overlay loaded and it operates on the currently selected overlay

m_VolMan_manager.setRoiColor(0)
boolean_result = m_VolMan_manager.runThresholdToROI(75.0,True,False,False,False)
j_List_result = m_VolMan_manager.runComponentAnalysisROI(0)
m_VolMan_manager.runComponentSplitROI(0,2)
usedROIs = m_VolMan_manager.roiData.getUsedMasks()
for roi in usedROIs:
    m_Stat_result = m_VolMan_manager.runStat(roi)
    m_VolMan_manager.setRoiColor(roi.color)
    m_VolMan_manager.deleteROI(roi)
    m_VolMan_manager.runAddROI(m_Stat_result.maxCoordinate,12.0,True)