예제 #1
0
 def externalUpdate(self, new_img):
     old_vox = self.image.vox_coords
     if len(new_img.shape) > 3:
         self.image = SlicerImage(new_img.subImage(0))
     else:
         self.image = SlicerImage(new_img)
     self.image.vox_coords = old_vox
     if iscomplex(self.image[:]):
         self.image.prefilter = abs_xform
     self.setNorm()
     self.setUpAxesSize()
     self.updateSlices(self.image.zyx_coords())
예제 #2
0
    def initoverlay(self, action):
        image_filter = gtk.FileFilter()
        image_filter.add_pattern("*.hdr")
        image_filter.add_pattern("*.nii")
        image_filter.set_name("Recon Images")
        fname = ask_fname(self,
                          "Choose file to overlay...",
                          action="open",
                          filter=image_filter)
        if not fname:
            return
        img = readImage(fname, vrange=(0, 0))
        self.overlay_img = SlicerImage(img)

        img_dims = N.take(
            N.array(self.image.shape) * self.image.dr, self.image.slicing())
        ovl_dims = N.take(
            N.array(self.overlay_img.shape) * self.overlay_img.dr,
            self.overlay_img.slicing())
        if not (img_dims == ovl_dims).all():
            print img_dims, ovl_dims
            print "Overlay failed because physical dimensions do not align..."
            print "base image dimensions (zyx): [%3.1f %3.1f %3.1f] (mm)" % tuple(
                img_dims)
            print "overlay image dimenensions (zyx: [%3.1f %3.1f %3.1f] (mm)" % tuple(
                ovl_dims)
            return
        self.setNorm()
        (ax, cor, sag) = self.overlay_img.slicing()
        self.ax_overlay = OverLay(self.ax_plot,
                                  ax,
                                  norm=self.overlay_norm,
                                  interpolation=self.ax_plot.interpolation)
        self.cor_overlay = OverLay(self.cor_plot,
                                   cor,
                                   norm=self.overlay_norm,
                                   interpolation=self.cor_plot.interpolation)
        self.sag_overlay = OverLay(self.sag_plot,
                                   sag,
                                   norm=self.overlay_norm,
                                   interpolation=self.sag_plot.interpolation)
        self.overlays = [self.ax_overlay, self.cor_overlay, self.sag_overlay]
        self.updateSlices(self.image.zyx_coords(),
                          sliceplots=self.overlays,
                          image=self.overlay_img,
                          norm=self.overlay_norm)
예제 #3
0
    def __init__(self, image, title="spmclone", parent=None):
        gtk.Window.__init__(self)
        children = self.get_children()
        if children:
            self.remove(children[0])
            self.hide_all()
        table = gtk.Table(4, 2)

        # super dumb way of storing the image object with its original
        # class identification
        self.img_obj = image
        self.image = len(image.shape) > 3 \
                     and SlicerImage(image.subImage(0)) \
                     or SlicerImage(image)
        if iscomplex(self.image[:]):
            self.image.prefilter = abs_xform

        self.overlay_img = None
        self.zoom = 0
        self.slice_patches = None
        self.setNorm()
        self.dimlengths = self.image.dr * N.array(self.image.shape)
        zyx_lim = self.image.extents()
        # I'm using [ax,cor,sag] such that this list informs each
        # sliceplot what dimension it slices in the image array
        # (eg for coronal data, the coronal plot slices the 0th dim)
        ax, cor, sag = self.image.slicing()
        origin = [0, 0, 0]
        # Make the ortho plots ---
        self.ax_plot = SlicePlot(self.image.data_xform(ax, origin),
                                 0,
                                 0,
                                 ax,
                                 norm=self.norm,
                                 extent=(zyx_lim[2] + zyx_lim[1]))

        self.cor_plot = SlicePlot(self.image.data_xform(cor, origin),
                                  0,
                                  0,
                                  cor,
                                  norm=self.norm,
                                  extent=(zyx_lim[2] + zyx_lim[0]))

        self.sag_plot = SlicePlot(self.image.data_xform(sag, origin),
                                  0,
                                  0,
                                  sag,
                                  norm=self.norm,
                                  extent=(zyx_lim[1] + zyx_lim[0]))

        # Although it doesn't matter 99% of the time, this list is
        # expected to be ordered this way
        self.sliceplots = [self.ax_plot, self.cor_plot, self.sag_plot]

        # menu bar
        merge = gtk.UIManager()
        merge.insert_action_group(self._create_action_group(), 0)
        mergeid = merge.add_ui_from_string(ui_info)
        self.menubar = merge.get_widget("/MenuBar")

        table.attach(self.menubar, 0, 2, 0, 1)
        self.menubar.set_size_request(600, 30)
        table.attach(self.cor_plot, 0, 1, 1, 2)
        self.cor_plot.set_size_request(250, 250)
        table.attach(self.sag_plot, 1, 2, 1, 2)
        self.sag_plot.set_size_request(250, 250)
        table.attach(self.ax_plot, 0, 1, 2, 3)
        self.ax_plot.set_size_request(250, 250)

        self.displaybox = DisplayInfo(self.image)
        self.displaybox.attach_toggle(self.crosshair_hider)
        self.displaybox.attach_imginterp(self.interp_handler)
        self.displaybox.attach_imgframe(self.zoom_handler)
        self.displaybox.attach_imgspace(self.rediculous_handler)
        table.attach(self.displaybox, 1, 2, 3, 4)
        self.displaybox.set_size_request(300, 300)
        self.statusbox = DisplayStatus(
            tuple(self.image.vox_coords.tolist()),
            tuple(self.image.zyx_coords().tolist()),
            self.image[tuple(self.image.vox_coords)])
        table.attach(self.statusbox, 0, 1, 3, 4)
        self.statusbox.set_size_request(300, 300)
        self.connect("configure_event", self.resize_handler)
        #table.set_row_spacing(1,25)
        # heights = 800
        # 250 plot 1
        # 250 plot 2
        # 370 info stuff
        # 30 menubar
        self.connect_crosshair_id = []
        self.connectCrosshairEvents()

        self.set_data("ui-manager", merge)
        self.add_accel_group(merge.get_accel_group())
        self.set_default_size(600, 730)
        self.set_border_width(3)
        self.set_title(title)
        self.add(table)
        self.show_all()
        #self.setUpAxesSize()
        #P.show()
        if parent:
            self.set_screen(parent.get_screen())
            self.destroy_handle = self.connect(
                'destroy', lambda x: parent._plotter_died())
        else:
            self.connect("destroy", lambda x: gtk.main_quit())
            gtk.main()