[Nipy-devel] sliceplot.py

Thorsten Kranz thorstenkranz@googlemail....
Mon Apr 7 07:25:16 CDT 2008


I was playing around with the examples, and I tried the
viewer/mni_anat.py example, which uses sliceplot.py. It worked rather
bad bad and showed zillions of errors of this kind:

Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py",
line 193, in button_press_event
    FigureCanvasBase.button_press_event(self, x, y, event.button)
  File "/usr/lib/python2.5/site-packages/matplotlib/backend_bases.py",
line 915, in button_press_event
    self.callbacks.process(s, mouseevent)
  File "/usr/lib/python2.5/site-packages/matplotlib/cbook.py", line
157, in process
    func(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/neuroimaging/ui/sliceplot.py",
line 165, in _on_pick
    self.parent._on_pick(self, x, y)
  File "/usr/lib/python2.5/site-packages/neuroimaging/ui/sliceplot.py",
line 524, in _on_pick
    self._set_axial_data()
  File "/usr/lib/python2.5/site-packages/neuroimaging/ui/sliceplot.py",
line 615, in _set_axial_data
    data = _axial_slice(self.img, self._z)
  File "/usr/lib/python2.5/site-packages/neuroimaging/ui/sliceplot.py",
line 700, in _axial_slice
    img_slice = img[zindex, ylim[0]:ylim[1], xlim[0]:xlim[1]]
  File "/usr/lib/python2.5/site-packages/neuroimaging/core/image/image.py",
line 130, in __getitem__
    raise ValueError, 'when slicing images, index must be a list of
integers or slices'
ValueError: when slicing images, index must be a list of integers or slices

I adressed the problem by checking the types passed to the function
__getitem__, and noticed that a float was given instead of an int and
therefore the ValueError is raised. One could fix this by adding a
cast to sliceplot.py for coronal, axial and sagittal slices, e.g.

#################################################
def _axial_slice(img, zindex, xlim=None, ylim=None, t=0):
    """Return axial slice of the image."""

    if img.ndim is 4:
        img = img[t, :, :, :]
    zdim, ydim, xdim = img.shape
    if not xlim:
        xlim = [0, xdim]
    if not ylim:
        ylim = [0, ydim]
    zindex=int(zindex) # add this
    img_slice = img[zindex, ylim[0]:ylim[1], xlim[0]:xlim[1]]
    return asarray(img_slice)
#################################################

Maybe I missed something and the error is somewhere else, but it fixed
the problem for me.

Nevertheless, it still didn't really work. For my own images it made
strange plots, like it was messing up something. When I changed to
giving an array to sliceplot.py (by using pynifti), it worked, but now
it somehow clipped the image. I'd like to attach some pictures to show
the problems, is it possible and is there interest for it?

For importing the array, I had to do another fix, as the line 760 in
sliceplot.py

img = image.fromarray(data)

doesn't fit the definition of fromarray in image.py:

def fromarray(data, names, grid=None):

as here two arguments are required.

Greetings,
Thorsten






Greetings,

Thorsten


More information about the Nipy-devel mailing list