示例#1
0
    def run(self,
            stack: ImageStack,
            in_place: bool = False,
            verbose=None,
            n_processes=None) -> ImageStack:
        """Perform filtering of an image stack

        Parameters
        ----------
        stack : ImageStack
            Stack to be filtered.
        in_place : bool
            if True, process ImageStack in-place, otherwise return a new stack
        verbose : None
            Not used. Elementwise multiply carries out a single vectorized multiplication that
            cannot provide a status bar. Included for consistency with Filter API.
        n_processes : None
            Not used. Elementwise multiplication scales slowly with additional processes due to the
            efficiency of vectorization on a single process. Included for consistency with Filter
            API. All computation happens on the main process.

        Returns
        -------
        ImageStack :
            If in-place is False, return the results of filter as a new stack.  Otherwise return the
            original stack.

        """

        # Align the axes of the multipliers with ImageStack
        mult_array_aligned: np.ndarray = self.mult_array.transpose(
            *stack.xarray.dims).values
        if not in_place:
            stack = deepcopy(stack)

        # stack._data contains the xarray
        stack._data *= mult_array_aligned
        if self.clip_method == Clip.CLIP:
            stack._data = preserve_float_range(stack._data, rescale=False)
        else:
            stack._data = preserve_float_range(stack._data, rescale=True)
        return stack
示例#2
0
    def run(
        self,
        stack: ImageStack,
        in_place: bool = False,
        verbose: bool = False,
        n_processes: Optional[int] = None,
        *args,
    ) -> ImageStack:
        """Perform filtering of an image stack

        Parameters
        ----------
        stack : ImageStack
            Stack to be filtered.
        in_place : bool
            if True, process ImageStack in-place, otherwise return a new stack
        verbose : bool
            if True, report on filtering progress (default = False)
        n_processes : Optional[int]
            Number of parallel processes to devote to calculating the filter

        Returns
        -------
        ImageStack :
            If in-place is False, return the results of filter as a new stack.  Otherwise return the
            original stack.

        """
        # Align the axes of the multipliers with ImageStack
        mult_array_aligned: np.ndarray = self.mult_array.transpose(
            *stack.xarray.dims).values
        if not in_place:
            stack = deepcopy(stack)

        # stack._data contains the xarray
        stack._data *= mult_array_aligned
        if self.clip_method == Clip.CLIP:
            stack._data = preserve_float_range(stack._data, rescale=False)
        else:
            stack._data = preserve_float_range(stack._data, rescale=True)
        return stack