def get_slice(self, plane='sagittal', index=None, seg=None):
        copy_rpi = Image(self)
        copy_rpi.change_orientation('RPI')
        if seg is not None:
            seg.change_orientation('RPI')
        nx, ny, nz, nt, px, py, pz, pt = self.dim
        slice = None
        slice_seg = None
        if plane == 'sagittal':
            if index is None:
                slice = copy_rpi.data[int(round(nx/2)), :, :]
                if seg is not None:
                    slice_seg = seg.data[int(round(nx/2)), :, :]
            else:
                assert index < nx, 'Index larger than image dimension.'
                slice = copy_rpi.data[index, :, :]
                if seg is not None:
                    slice_seg = seg.data[index, :, :]

        elif plane == 'coronal':
            if index is None:
                slice = copy_rpi.data[:, int(round(ny/2)), :]
                if seg is not None:
                    slice_seg = seg.data[:, int(round(ny/2)), :]
            else:
                assert index < ny, 'Index larger than image dimension.'
                slice = copy_rpi.data[:, index, :]
                if seg is not None:
                    slice_seg = seg.data[:, index, :]

        elif plane == 'axial' or plane == 'transverse':
            if index is None:
                slice = copy_rpi.data[:, :, int(round(nz/2))]
                if seg is not None:
                    slice_seg = seg.data[:, :, int(round(nz/2))]
            else:
                assert index < nz, 'Index larger than image dimension.'
                slice = copy_rpi.data[:, :, index]
                if seg is not None:
                    slice_seg = seg.data[:, :, index]
        else:
            from sct_utils import printv
            printv('ERROR: wrong plan input to save slice. Please choose "sagittal", "coronal" or "axial"', self.verbose, type='error')

        return (slice, slice_seg)

    #
Handle event from a device.
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/scripts/msct_image.py/Image.get_slice--crossover with--dataset/ETHPy150Open tomwilkie/awesomation/src/pi/control.py/Control._device_event_callback