AIMS / Anatomist volume manipulationΒΆ

Loading, handling and viewing a Volume with aims and anatomist

../_images/sphx_glr_aimsvolumetest_001.png
from __future__ import absolute_import
import anatomist.direct.api as anatomist
from soma import aims
from soma.qt_gui.qt_backend import Qt
import sys

# load any volume as a aims.Volume_* object
vol = aims.read('irm.ima')

runloop = False
if Qt.QApplication.instance() is None:
    runloop = True

# initialize Anatomist
a = anatomist.Anatomist()

# convert the AimsData volume to Anatomist API
avol = a.toAObject(vol)
avol.releaseAppRef()

win = a.createWindow('Axial')

# put volume in window
win.addObjects(avol)

# volume change and update test

# using Numeric API
arr = vol.arraydata()
# we're just printing a white square in the middle of the volume
arr[0, 50:70, 100:130, 100:130] = 255

# update Anatomist object and its views
avol.setChanged()
avol.notifyObservers()


# fusion test

# have a second volume. We could have loaded another one
# (and it would have been nicer on screen). This example also
# shows the ability to share the volume data with multiple anatomist/aims
# objects
avol2 = a.toAObject(vol)
avol2.releaseAppRef()

# set a different palette on the second object so we can see something
a.setObjectPalette(avol2, 'Blue-Red-fusion')

# another view
win2 = a.createWindow('Axial')

a.addObjects(avol2, win2)

# create the fusion object
fus = a.fusionObjects([avol, avol2], 'Fusion2DMethod')

# show it
win3 = a.createWindow('Sagittal')

a.addObjects(fus, win3)


# display in matplotlib for sphinx_gallery
win3.sphinx_gallery_snapshot()
if runloop and 'sphinx_gallery' not in sys.modules:
    Qt.QApplication.instance().exec_()
if runloop or 'sphinx_gallery' in sys.modules:
    del win, win2, win3, fus, avol, arr, avol2

Total running time of the script: ( 0 minutes 1.548 seconds)

Gallery generated by Sphinx-Gallery