napari.layers.Image#

class napari.layers.Image(data, *, affine=None, attenuation=0.05, blending='translucent', cache=True, colormap='gray', contrast_limits=None, custom_interpolation_kernel_2d=None, depiction='volume', experimental_clipping_planes=None, gamma=1.0, interpolation2d='nearest', interpolation3d='linear', iso_threshold=None, metadata=None, multiscale=None, name=None, opacity=1.0, plane=None, projection_mode='none', rendering='mip', rgb=None, rotate=None, scale=None, shear=None, translate=None, visible=True)[source]#

Bases: IntensityVisualizationMixin, ScalarFieldBase

Image layer.

Parameters:
  • data (array or list of array) – Image data. Can be N >= 2 dimensional. If the last dimension has length 3 or 4 can be interpreted as RGB or RGBA if rgb is True. If a list and arrays are decreasing in shape then the data is treated as a multiscale image. Please note multiscale rendering is only supported in 2D. In 3D, only the lowest resolution scale is displayed.

  • affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a length N translation vector and a 1 or a napari Affine transform object. Applied as an extra transform on top of the provided scale, rotate, and shear values.

  • attenuation (float) – Attenuation rate for attenuated maximum intensity projection.

  • blending (str) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘translucent’, ‘translucent_no_depth’, ‘additive’, ‘minimum’, ‘opaque’}.

  • cache (bool) – Whether slices of out-of-core datasets should be cached upon retrieval. Currently, this only applies to dask arrays.

  • colormap (str, napari.utils.Colormap, tuple, dict) – Colormaps to use for luminance images. If a string, it can be the name of a supported colormap from vispy or matplotlib or the name of a vispy color or a hexadecimal RGB color representation. If a tuple, the first value must be a string to assign as a name to a colormap and the second item must be a Colormap. If a dict, the key must be a string to assign as a name to a colormap and the value must be a Colormap.

  • contrast_limits (list (2,)) – Intensity value limits to be used for determining the minimum and maximum colormap bounds for luminance images. If not passed, they will be calculated as the min and max intensity value of the image.

  • custom_interpolation_kernel_2d (np.ndarray) – Convolution kernel used with the ‘custom’ interpolation mode in 2D rendering.

  • depiction (str) – 3D Depiction mode. Must be one of {‘volume’, ‘plane’}. The default value is ‘volume’.

  • experimental_clipping_planes (list of dicts, list of ClippingPlane, or ClippingPlaneList) – Each dict defines a clipping plane in 3D in data coordinates. Valid dictionary keys are {‘position’, ‘normal’, and ‘enabled’}. Values on the negative side of the normal are discarded if the plane is enabled.

  • gamma (float) – Gamma correction for determining colormap linearity; defaults to 1.

  • interpolation2d (str) – Interpolation mode used by vispy for rendering 2d data. Must be one of our supported modes. (for list of supported modes see Interpolation enum) ‘custom’ is a special mode for 2D interpolation in which a regular grid of samples is taken from the texture around a position using ‘linear’ interpolation before being multiplied with a custom interpolation kernel (provided with ‘custom_interpolation_kernel_2d’).

  • interpolation3d (str) – Same as ‘interpolation2d’ but for 3D rendering.

  • iso_threshold (float) – Threshold for isosurface.

  • metadata (dict) – Layer metadata.

  • multiscale (bool) – Whether the data is a multiscale image or not. Multiscale data is represented by a list of array-like image data. If not specified by the user and if the data is a list of arrays that decrease in shape, then it will be taken to be multiscale. The first image in the list should be the largest. Please note multiscale rendering is only supported in 2D. In 3D, only the lowest resolution scale is displayed.

  • name (str) – Name of the layer.

  • opacity (float) – Opacity of the layer visual, between 0.0 and 1.0.

  • plane (dict or SlicingPlane) – Properties defining plane rendering in 3D. Properties are defined in data coordinates. Valid dictionary keys are {‘position’, ‘normal’, ‘thickness’, and ‘enabled’}.

  • projection_mode (str) – How data outside the viewed dimensions, but inside the thick Dims slice will be projected onto the viewed dimensions. Must fit to ImageProjectionMode

  • rendering (str) – Rendering mode used by vispy. Must be one of our supported modes.

  • rgb (bool, optional) – Whether the image is RGB or RGBA if rgb. If not specified by user, but the last dimension of the data has length 3 or 4, it will be set as True. If False, the image is interpreted as a luminance image.

  • rotate (float, 3-tuple of float, or n-D array.) – If a float, convert into a 2D rotation matrix using that value as an angle. If 3-tuple, convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise, assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with ‘np.degrees’ if needed.

  • scale (tuple of float) – Scale factors for the layer.

  • shear (1-D array or n-D array) – Either a vector of upper triangular values, or an nD shear matrix with ones along the main diagonal.

  • translate (tuple of float) – Translation values for the layer.

  • visible (bool) – Whether the layer visual is currently being displayed.

data#

Image data. Can be N dimensional. If the last dimension has length 3 or 4 can be interpreted as RGB or RGBA if rgb is True. If a list and arrays are decreasing in shape then the data is treated as a multiscale image. Please note multiscale rendering is only supported in 2D. In 3D, only the lowest resolution scale is displayed.

Type:

array or list of array

metadata#

Image metadata.

Type:

dict

rgb#

Whether the image is rgb RGB or RGBA if rgb. If not specified by user and the last dimension of the data has length 3 or 4 it will be set as True. If False the image is interpreted as a luminance image.

Type:

bool

multiscale#

Whether the data is a multiscale image or not. Multiscale data is represented by a list of array like image data. The first image in the list should be the largest. Please note multiscale rendering is only supported in 2D. In 3D, only the lowest resolution scale is displayed.

Type:

bool

mode#

Interactive mode. The normal, default mode is PAN_ZOOM, which allows for normal interactivity with the canvas.

In TRANSFORM mode the image can be transformed interactively.

Type:

str

colormap#

The first is the name of the current colormap, and the second value is the colormap. Colormaps are used for luminance images, if the image is rgb the colormap is ignored.

Type:

2-tuple of str, napari.utils.Colormap

colormaps#

Names of the available colormaps.

Type:

tuple of str

contrast_limits#

Color limits to be used for determining the colormap bounds for luminance images. If the image is rgb the contrast_limits is ignored.

Type:

list (2,) of float

contrast_limits_range#

Range for the color limits for luminance images. If the image is rgb the contrast_limits_range is ignored.

Type:

list (2,) of float

gamma#

Gamma correction for determining colormap linearity.

Type:

float

interpolation2d#

Interpolation mode used by vispy. Must be one of our supported modes. ‘custom’ is a special mode for 2D interpolation in which a regular grid of samples are taken from the texture around a position using ‘linear’ interpolation before being multiplied with a custom interpolation kernel (provided with ‘custom_interpolation_kernel_2d’).

Type:

str

interpolation3d#

Same as ‘interpolation2d’ but for 3D rendering.

Type:

str

rendering#

Rendering mode used by vispy. Must be one of our supported modes.

Type:

str

depiction#

3D Depiction mode used by vispy. Must be one of our supported modes.

Type:

str

iso_threshold#

Threshold for isosurface.

Type:

float

attenuation#

Attenuation rate for attenuated maximum intensity projection.

Type:

float

plane#

Properties defining plane rendering in 3D. Valid dictionary keys are {‘position’, ‘normal’, ‘thickness’}.

Type:

SlicingPlane or dict

experimental_clipping_planes#

Clipping planes defined in data coordinates, used to clip the volume.

Type:

ClippingPlaneList

custom_interpolation_kernel_2d#

Convolution kernel used with the ‘custom’ interpolation mode in 2D rendering.

Type:

np.ndarray

Notes

_data_viewarray (N, M), (N, M, 3), or (N, M, 4)

Image data for the currently viewed slice. Must be 2D image data, but can be multidimensional for RGB or RGBA images if multidimensional is True.

inherited-members:

Methods

as_layer_data_tuple()

bind_key(key_bind[, func, overwrite])

Bind a key combination to a keymap.

block_update_properties()

click_plane_from_click_data(click_position, ...)

Calculate a (point, normal) plane parallel to the canvas in data coordinates, centered on the centre of rotation of the camera.

create(data[, meta, layer_type])

Create layer from data of type layer_type.

data_to_world(position)

Convert from data coordinates to world coordinates.

get_ray_intersections(position, ...[, world])

Get the start and end point for the ray extending from a point through the data bounding box.

get_source_str()

get_status([position, view_direction, ...])

Status message information of the data at a coordinate position.

get_value(position, *[, view_direction, ...])

Value of the data at a position.

projected_distance_from_mouse_drag(...)

Calculate the length of the projection of a line between two mouse clicks onto a vector (or array of vectors) in data coordinates.

refresh([event])

Refresh all layer data based on current view slice.

reset_contrast_limits([mode])

Scale contrast limits to data range

reset_contrast_limits_range([mode])

Scale contrast limits range to data type if dtype is an integer, or use the current maximum data range otherwise.

save(path[, plugin])

Save this layer to path with default (or specified) plugin.

set_view_slice()

world_to_data(position)

Convert from world coordinates to data coordinates.

Attributes

ModeCallable

alias of Callable[[Layer, Event], Union[None, Generator[None, None, None]]]

affine

Extra affine transform to go from physical to world coordinates.

attenuation

attenuation rate for attenuated_mip rendering.

blending

Determines how RGB and alpha values get mixed.

bounding_box

class_keymap

colormap

colormap for luminance images.

colormaps

names of available colormaps.

contrast_limits

Limits to use for the colormap.

contrast_limits_range

The current valid range of the contrast limits.

cursor

String identifying cursor displayed over canvas.

cursor_size

Size of cursor if custom.

custom_interpolation_kernel_2d

data

Data, possibly in multiscale wrapper.

data_level

Current level of multiscale, or 0 if image.

data_raw

Data, exactly as provided by the user.

depiction

The current 3D depiction mode.

downsample_factors

Downsample factors for each level of the multiscale.

dtype

editable

Whether the current layer data is editable from the viewer.

experimental_clipping_planes

extent

Extent of layer in data and world coordinates.

gamma

help

displayed in status bar bottom right.

interactive

interpolation

Return current interpolation mode.

interpolation2d

interpolation3d

iso_threshold

threshold for isosurface.

keymap

level_shapes

Shapes of each level of the multiscale or just of image.

loaded

True if this layer is fully loaded in memory, False otherwise.

metadata

Key/value map for user-stored data.

mode

Interactive mode

mouse_pan

Determine if canvas interactive panning is enabled with the mouse.

mouse_zoom

Determine if canvas interactive zooming is enabled with the mouse.

name

Unique name of the layer.

ndim

Number of dimensions in the data.

opacity

Opacity value between 0.0 and 1.0.

plane

projection_mode

Mode of projection of the thick slice onto the viewed dimensions.

rendering

Return current rendering mode.

rotate

Rotation matrix in world coordinates.

scale

Anisotropy factors to scale data into world coordinates.

shear

Shear matrix in world coordinates.

source

thumbnail

Integer array of thumbnail for the layer

translate

Factors to shift the layer by in units of world coordinates.

visible

Whether the visual is currently being displayed.

Details

property attenuation: float#

attenuation rate for attenuated_mip rendering.

Type:

float

property contrast_limits#

Limits to use for the colormap.

Type:

list of float

property data: LayerDataProtocol | MultiScaleData#

Data, possibly in multiscale wrapper. Obeys LayerDataProtocol.

property interpolation#

Return current interpolation mode.

Selects a preset interpolation mode in vispy that determines how volume is displayed. Makes use of the two Texture2D interpolation methods and the available interpolation methods defined in vispy/gloo/glsl/misc/spatial_filters.frag

Options include: ‘bessel’, ‘cubic’, ‘linear’, ‘blackman’, ‘catrom’, ‘gaussian’, ‘hamming’, ‘hanning’, ‘hermite’, ‘kaiser’, ‘lanczos’, ‘mitchell’, ‘nearest’, ‘spline16’, ‘spline36’

Returns:

The current interpolation mode

Return type:

str

property iso_threshold: float#

threshold for isosurface.

Type:

float

property rendering#

Return current rendering mode.

Selects a preset rendering mode in vispy that determines how volume is displayed. Options include:

  • translucent: voxel colors are blended along the view ray until

    the result is opaque.

  • mip: maximum intensity projection. Cast a ray and display the

    maximum value that was encountered.

  • minip: minimum intensity projection. Cast a ray and display the

    minimum value that was encountered.

  • attenuated_mip: attenuated maximum intensity projection. Cast a

    ray and attenuate values based on integral of encountered values, display the maximum value that was encountered after attenuation. This will make nearer objects appear more prominent.

  • additive: voxel colors are added along the view ray until

    the result is saturated.

  • iso: isosurface. Cast a ray until a certain threshold is

    encountered. At that location, lighning calculations are performed to give the visual appearance of a surface.

  • average: average intensity projection. Cast a ray and display the

    average of values that were encountered.

Returns:

The current rendering mode

Return type:

str