Beispiel #1
0
    def update_image(self, image, mode='world'):
        if type(image) != ni_api.Image:
            try:
                image = load_spatial_image(image)
            except RuntimeError:
                self.image = None
                self._image_loaded = False
                raise
        self.blender.main = image
        # this reference may no longer be necessary
        self.image = self.blender.main
        self._image_loaded = True
        # need to update:
        # slider ranges
        # plugin params
        limits = self.blender.bbox
        print 'new limits:', limits
        self.update_ranges(limits)
        self._update_plugin_params()
        planes = self.blender.cut_image((0,0,0))

        self.ortho_figs_widget.initialize_plots(planes, (0,0,0), limits)

        if hasattr(self, 'mayavi_widget') and self.mayavi_widget is not None:
            self.mayavi_widget.mr_vis.blender = self.blender
Beispiel #2
0
 def update_image(self, image, mode='world'):
     if type(image) != ni_api.Image:
         try:
             image = load_spatial_image(image)
         except RuntimeError:
             self.image = None
             self._image_loaded = False
             raise
     self._image_loaded = True
     self.viewer.blender.main = image
     self.image = self.viewer.blender.main
     self._update_plugin_args()
Beispiel #3
0
def load_resampled_slicer(image, bbox=None, fliplr=False, mask=False):
    from xipy.slicing.image_slicers import ResampledVolumeSlicer
    from xipy.io import load_spatial_image
    if type(image) in (str, unicode):
        return ResampledVolumeSlicer(load_spatial_image(image),
                                     bbox=bbox,
                                     mask=mask,
                                     fliplr=fliplr)
    elif type(image) is ni_api.Image:
        return ResampledVolumeSlicer(image,
                                     bbox=bbox,
                                     mask=mask,
                                     fliplr=fliplr)
    elif type(image) is ResampledVolumeSlicer:
        return image
    else:
        raise ValueError('unknown type for image argument '+str(type(image)))
Beispiel #4
0
def plot_tfbeam(beam, stats=None, with3d=False):
    from xipy.vis.ortho_viewer import ortho_viewer
    struct = load_spatial_image(beam.coreg.mrpath)
    sman = TimeFreqSnPMaps(stats_results=stats)
    bbox = vu.world_limits(struct)
    bman = TFBeamManager(bbox, bstats_manager=sman)
    bman.update_beam(beam)


    win = ortho_viewer(image=struct, mayavi_viewer=with3d)
    win.make_tool_from_functional_manager(NmTimeFreqWindow, bman)
    win.show()
##     app.exec_()
##     # XYZ: this is truly ugly
    bman.signal_image_props()
    bman.signal_new_image()
    return win
Beispiel #5
0
def load_sampled_slicer(overlay, bbox=None, grid_spacing=None,
                        mask=False, fliplr=False):
    from xipy.slicing.image_slicers import SampledVolumeSlicer
    from xipy.io import load_spatial_image
    if type(overlay) in (str, unicode):
        return SampledVolumeSlicer(load_spatial_image(overlay), bbox=bbox,
                                   mask=mask,
                                   grid_spacing=grid_spacing,
                                   fliplr=fliplr)
    elif type(overlay) is ni_api.Image:
        return SampledVolumeSlicer(overlay, bbox=bbox,
                                   mask=mask,
                                   grid_spacing=grid_spacing,
                                   fliplr=fliplr)
    elif type(overlay) is SampledVolumeSlicer:
        return overlay
    else:
        raise ValueError('unknown type for image argument '+str(type(overlay)))
Beispiel #6
0
from xipy import TEMPLATE_MRI_PATH
from xipy.vis.three_dee_viewer import MayaviViewer
from xipy.overlay.image_overlay import ImageOverlayManager, ImageOverlayWindow
import xipy.io as xio

from PyQt4 import QtCore, QtGui
import sys, os
if QtGui.QApplication.startingUp():
    app = QtGui.QApplication(sys.argv)
else:
    app = QtGui.QApplication.instance() 

anat = xio.load_spatial_image(TEMPLATE_MRI_PATH)
func = xio.load_image(os.path.join(os.path.dirname(__file__),
                                  '../data/dtk_dti_out/dti_fa.nii'))
func_man = ImageOverlayManager(None, overlay=func)
#                              ^^^^ API will change soon 
        
win = MayaviViewer(image=anat)
win.make_tool_from_functional_manager(ImageOverlayWindow, func_man)

win.show()
app.exec_()
Beispiel #7
0
    op = optparse.OptionParser(usage=usage)
    op.add_option('-m', '--main-spline-order', dest='main_spline_order',
                  type='int', default=0)
    op.add_option('-o', '--over-spline-order', dest='over_spline_order',
                  type='int', default=0)
    return op

if __name__=='__main__':
    import sys
    import xipy.volume_utils as vu
    import xipy.io as xio
    op = make_option_parser()
    op.add_option('-i', '--index-slicer', dest='use_index_slicer',
                  action='store_true', default=False)
    (opts, args) = op.parse_args()

    files = args

    cls = ResampledIndexVolumeSlicer if opts.use_index_slicer \
          else ResampledVolumeSlicer
    orders = (opts.main_spline_order, opts.over_spline_order)
    images = [cls(xio.load_spatial_image(i), order=o)
              for i, o in zip(files, orders)]
    if QtGui.QApplication.startingUp():
        app = QtGui.QApplication(sys.argv)
    else:
        app = QtGui.QApplication.instance()
    win = SimpleOrtho(*images)
    win.show()
    sys.exit(app.exec_())
Beispiel #8
0
        planes = self.image.cut_image(xyz_loc, axes=axes)
        self.ortho_figs_widget.update_plot_data(
            planes, fig_labels=axes
            )

if __name__=='__main__':
    import sys
    import xipy.io as xio
    from test_two_images import make_option_parser
    op = make_option_parser()
    op.add_option('-t', '--vtk-order', dest='vtk_order',
                  action='store_true', default=False)

    (opts, args) = op.parse_args()
    
    images = []
    for arg in args:
        images.append(xio.load_spatial_image(arg))
    images = images + [None] * (2-len(images))
    
    if QtGui.QApplication.startingUp():
        app = QtGui.QApplication(sys.argv)
    else:
        app = QtGui.QApplication.instance()
    kws = dict(vtk_order=opts.vtk_order,
               main_spline_order=opts.main_spline_order,
               over_spline_order=opts.over_spline_order)
    win = BlendedOrtho(*images, **kws)
    win.show()
    sys.exit(app.exec_())
Beispiel #9
0
import numpy as np
import xipy.colors.rgba_blending as rb
import xipy
import xipy.io as xio
import xipy.colors.mayavi_tools as mt

from enthought.mayavi import mlab
from enthought.tvtk.api import tvtk

over_img = xio.load_spatial_image('tfbeam_img.nii')
over_img._data = np.ma.masked_where(over_img._data > 1e10, over_img._data)

main_img = xio.load_spatial_image(xipy.TEMPLATE_MRI_PATH)

bi = rb.BlendedImages(vtk_order = True)
m_src = mt.MasterSource(blender=bi)
bi.main = main_img
bi.over = over_img

m_src = mlab.pipeline.add_dataset(m_src)

aa1 = mlab.pipeline.set_active_attribute(
    m_src, point_scalars=m_src.main_channel
    )

ipw1 = mt.image_plane_widget_rgba(aa1)
ipw1.ipw.plane_orientation = 'x_axes'

aa2 = mlab.pipeline.set_active_attribute(
    m_src, point_scalars=m_src.main_channel
    )