def __createTransposedView(self): """Create the new view on the stack depending on the perspective (set orthogonal axis browsed on the viewer as first dimension) """ assert self._stack is not None assert 0 <= self._perspective < 3 # ensure we have the stack encapsulated in an array-like object # having a transpose() method if isinstance(self._stack, numpy.ndarray): self.__transposed_view = self._stack elif is_dataset(self._stack) or isinstance(self._stack, DatasetView): self.__transposed_view = DatasetView(self._stack) elif isinstance(self._stack, ListOfImages): self.__transposed_view = ListOfImages(self._stack) # transpose the array-like object if necessary if self._perspective == 1: self.__transposed_view = self.__transposed_view.transpose((1, 0, 2)) elif self._perspective == 2: self.__transposed_view = self.__transposed_view.transpose((2, 0, 1)) self._browser.setRange(0, self.__transposed_view.shape[0] - 1) self._browser.setValue(0)
def setStack(self, stack, perspective=None, reset=True, calibrations=None): """Set the 3D stack. The perspective parameter is used to define which dimension of the 3D array is to be used as frame index. The lowest remaining dimension number is the row index of the displayed image (Y axis), and the highest remaining dimension is the column index (X axis). :param stack: 3D stack, or `None` to clear plot. :type stack: 3D numpy.ndarray, or 3D h5py.Dataset, or list/tuple of 2D numpy arrays, or None. :param int perspective: Dimension for the frame index: 0, 1 or 2. Use ``None`` to keep the current perspective (default). :param bool reset: Whether to reset zoom or not. :param calibrations: Sequence of 3 calibration objects for each axis. These objects can be a subclass of :class:`AbstractCalibration`, or 2-tuples *(a, b)* where *a* is the y-intercept and *b* is the slope of a linear calibration (:math:`x \mapsto a + b x`) """ if stack is None: self.clear() self.sigStackChanged.emit(0) return self._set3DScaleAndOrigin(calibrations) # stack as list of 2D arrays: must be converted into an array_like if not isinstance(stack, numpy.ndarray): if not is_dataset(stack): try: assert hasattr(stack, "__len__") for img in stack: assert hasattr(img, "shape") assert len(img.shape) == 2 except AssertionError: raise ValueError( "Stack must be a 3D array/dataset or a list of " + "2D arrays.") stack = ListOfImages(stack) assert len(stack.shape) == 3, "data must be 3D" self._stack = stack self.__createTransposedView() perspective_changed = False if perspective not in [None, self._perspective]: perspective_changed = True self.setPerspective(perspective) # This call to setColormap redefines the meaning of autoscale # for 3D volume: take global min/max rather than frame min/max if self.__autoscaleCmap: self.setColormap(autoscale=True) # init plot self._plot.addImage(self.__transposed_view[0, :, :], legend=self.__imageLegend, colormap=self.getColormap(), origin=self._getImageOrigin(), scale=self._getImageScale(), replace=True, resetzoom=False) self._plot.setActiveImage(self.__imageLegend) self.__updatePlotLabels() self._updateTitle() if reset: self._plot.resetZoom() # enable and init browser self._browser.setEnabled(True) if not perspective_changed: # avoid double signal (see self.setPerspective) self.sigStackChanged.emit(stack.size)
def setStack(self, stack, perspective=0, reset=True): """Set the 3D stack. The perspective parameter is used to define which dimension of the 3D array is to be used as frame index. The lowest remaining dimension number is the row index of the displayed image (Y axis), and the highest remaining dimension is the column index (X axis). :param stack: 3D stack, or `None` to clear plot. :type stack: 3D numpy.ndarray, or 3D h5py.Dataset, or list/tuple of 2D numpy arrays, or None. :param int perspective: Dimension for the frame index: 0, 1 or 2. By default, the dimension for the image index is the first dimension of the 3D stack (``perspective=0``). :param bool reset: Whether to reset zoom or not. """ if stack is None: self.clear() self.sigStackChanged.emit(0) return # stack as list of 2D arrays: must be converted into an array_like if not isinstance(stack, numpy.ndarray): if h5py is None or not isinstance(stack, h5py.Dataset): try: assert hasattr(stack, "__len__") for img in stack: assert hasattr(img, "shape") assert len(img.shape) == 2 except AssertionError: raise ValueError( "Stack must be a 3D array/dataset or a list of " + "2D arrays.") stack = ListOfImages(stack) assert len(stack.shape) == 3, "data must be 3D" self._stack = stack self.__createTransposedView() # This call to setColormap redefines the meaning of autoscale # for 3D volume: take global min/max rather than frame min/max if self.__autoscaleCmap: self.setColormap(autoscale=True) # init plot self._plot.addImage(self.__transposed_view[0, :, :], legend=self.__imageLegend, colormap=self.getColormap(), resetzoom=False) self._plot.setActiveImage(self.__imageLegend) self.__updatePlotLabels() if reset: self._plot.resetZoom() # enable and init browser self._browser.setEnabled(True) if perspective != self._perspective: self.__setPerspective(perspective) self.sigStackChanged.emit(stack.size)