How to use the napari.layers.Image function in napari

To help you get started, we’ve selected a few napari examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github napari / napari / napari / _qt / qt_about_keybindings.py View on Github external
self.layout = QVBoxLayout()

        self.setWindowTitle('Keybindings')
        self.setWindowModality(Qt.NonModal)
        self.setLayout(self.layout)

        # stacked keybindings widgets
        self.textEditBox = QTextEdit()
        self.textEditBox.setTextInteractionFlags(Qt.TextSelectableByMouse)
        self.textEditBox.setMinimumWidth(360)
        # Can switch to a normal dict when our minimum Python is 3.7
        self.keybindings_strs = OrderedDict()
        self.keybindings_strs[self.ALL_ACTIVE_KEYBINDINGS] = ''
        col = self.viewer.palette['secondary']
        layers = [
            napari.layers.Image,
            napari.layers.Labels,
            napari.layers.Points,
            napari.layers.Shapes,
            napari.layers.Surface,
            napari.layers.Vectors,
        ]
        for layer in layers:
            if len(layer.class_keymap) == 0:
                text = 'No keybindings'
            else:
                text = get_keybindings_summary(layer.class_keymap, col=col)
            self.keybindings_strs[f"{layer.__name__} layer"] = text

        # layer type selection
        self.layerTypeComboBox = QComboBox()
        for name in self.keybindings_strs:
github napari / napari / napari / _vispy / utils.py View on Github external
from ..layers import Image, Labels, Points, Shapes, Surface, Vectors
from .vispy_image_layer import VispyImageLayer
from .vispy_points_layer import VispyPointsLayer
from .vispy_shapes_layer import VispyShapesLayer
from .vispy_vectors_layer import VispyVectorsLayer
from .vispy_surface_layer import VispySurfaceLayer


layer_to_visual = {
    Image: VispyImageLayer,
    Labels: VispyImageLayer,
    Points: VispyPointsLayer,
    Shapes: VispyShapesLayer,
    Surface: VispySurfaceLayer,
    Vectors: VispyVectorsLayer,
}


def create_vispy_visual(layer):
    """Create vispy visual for a layer based on its layer type.

    Parameters
    ----------
    layer : napari.layers._base_layer.Layer
        Layer that needs its propetry widget created.
github napari / napari / napari / components / viewer_model.py View on Github external
gamma = ensure_iterable(gamma)

            layer_list = []
            zipped_args = zip(
                range(n_channels), colormap, contrast_limits, gamma, name
            )
            for i, cmap, clims, _gamma, name in zipped_args:
                if is_pyramid:
                    image = [
                        np.take(data[j], i, axis=channel_axis)
                        for j in range(len(data))
                    ]
                else:
                    image = np.take(data, i, axis=channel_axis)
                layer = layers.Image(
                    image,
                    rgb=rgb,
                    colormap=cmap,
                    contrast_limits=clims,
                    gamma=_gamma,
                    interpolation=interpolation,
                    rendering=rendering,
                    name=name,
                    metadata=metadata,
                    scale=scale,
                    translate=translate,
                    opacity=opacity,
                    blending=blending,
                    visible=visible,
                )
                self.add_layer(layer)
github napari / napari / benchmarks / benchmark_image_layer.py View on Github external
def setup(self, n):
        np.random.seed(0)
        self.data = np.random.random((n, n, n))
        self.new_data = np.random.random((n, n, n))
        self.layer = Image(self.data)
github napari / napari / napari / components / viewer_model.py View on Github external
layer : :class:`napari.layers.Image` or list
            The newly-created image layer or list of image layers.
        """
        if data is None and path is None:
            raise ValueError("One of either data or path must be provided")
        elif data is not None and path is not None:
            raise ValueError("Only one of data or path can be provided")
        elif data is None:
            data = io.magic_imread(path)

        if channel_axis is None:
            if colormap is None:
                colormap = 'gray'
            if blending is None:
                blending = 'translucent'
            layer = layers.Image(
                data,
                rgb=rgb,
                is_pyramid=is_pyramid,
                colormap=colormap,
                contrast_limits=contrast_limits,
                gamma=gamma,
                interpolation=interpolation,
                rendering=rendering,
                name=name,
                metadata=metadata,
                scale=scale,
                translate=translate,
                opacity=opacity,
                blending=blending,
                visible=visible,
            )
github napari / napari / napari / components / viewer_model.py View on Github external
layer : :class:`napari.layers.Image` or list
            The newly-created image layer or list of image layers.
        """
        if data is None and path is None:
            raise ValueError("One of either data or path must be provided")
        elif data is not None and path is not None:
            raise ValueError("Only one of data or path can be provided")
        elif data is None:
            data = io.magic_imread(path)

        if channel_axis is None:
            if colormap is None:
                colormap = 'gray'
            if blending is None:
                blending = 'translucent'
            layer = layers.Image(
                data,
                rgb=rgb,
                is_pyramid=is_pyramid,
                colormap=colormap,
                contrast_limits=contrast_limits,
                gamma=gamma,
                interpolation=interpolation,
                rendering=rendering,
                iso_threshold=iso_threshold,
                name=name,
                metadata=metadata,
                scale=scale,
                translate=translate,
                opacity=opacity,
                blending=blending,
                visible=visible,
github napari / napari / benchmarks / benchmark_image_layer.py View on Github external
def mem_layer(self, n):
        """Memory used by layer."""
        return Image(self.data)
github napari / napari / napari / components / viewer_model.py View on Github external
gamma = ensure_iterable(gamma)

            layer_list = []
            zipped_args = zip(
                range(n_channels), colormap, contrast_limits, gamma, name
            )
            for i, cmap, clims, _gamma, name in zipped_args:
                if is_pyramid:
                    image = [
                        data[j].take(i, axis=channel_axis)
                        for j in range(len(data))
                    ]
                else:
                    image = data.take(i, axis=channel_axis)
                layer = layers.Image(
                    image,
                    rgb=rgb,
                    colormap=cmap,
                    contrast_limits=clims,
                    gamma=_gamma,
                    interpolation=interpolation,
                    rendering=rendering,
                    name=name,
                    metadata=metadata,
                    scale=scale,
                    translate=translate,
                    opacity=opacity,
                    blending=blending,
                    visible=visible,
                )
                self.add_layer(layer)
github napari / napari / napari / _qt / layers / util.py View on Github external
from ...layers import Image, Labels, Points, Shapes, Surface, Vectors
from .qt_image_layer import QtImageControls
from .qt_points_layer import QtPointsControls
from .qt_shapes_layer import QtShapesControls
from .qt_labels_layer import QtLabelsControls
from .qt_surface_layer import QtSurfaceControls
from .qt_vectors_layer import QtVectorsControls


layer_to_controls = {
    Image: QtImageControls,
    Labels: QtLabelsControls,
    Points: QtPointsControls,
    Shapes: QtShapesControls,
    Surface: QtSurfaceControls,
    Vectors: QtVectorsControls,
}


def create_qt_controls(layer):
    """
    Create a qt controls widget for a layer based on its layer type.

    Parameters
    ----------
        layer : napari.layers._base_layer.Layer
            Layer that needs its controls widget created.