Skip to content

Instantly share code, notes, and snippets.

@tlancon
Last active June 8, 2021 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlancon/504f4a666ef49611e14597cbfad83307 to your computer and use it in GitHub Desktop.
Save tlancon/504f4a666ef49611e14597cbfad83307 to your computer and use it in GitHub Desktop.
Copies the main visualization properties from one layer to another in napari.
def copy_lut(from_layer, to_layer, opacity=False):
"""
Copies the visualization properties from one layer to another in napari.
Only the colormap, contrast limits, and gamma values are included by default.
The opacity can be optionally copied as well.
Blending and interpolation are ignored.
Params
------
from_layer : napari Image Layer
Image layer with the visualization parameters you'd like to copy from.
to_layer : napari Image Layer
Image layer that you'd like to copy the visualization parameters to.
opacity : Bool
If True, copy the opacity value from from_layer to to_layer.
Defaults to False.
"""
to_layer.colormap = from_layer.colormap
to_layer.contrast_limits = from_layer.contrast_limits
to_layer.gamma = from_layer.gamma
if opacity is True:
to_layer.opacity = from_layer.opacity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment