Skip to content

Instantly share code, notes, and snippets.

@ximeg
Created June 11, 2022 22:32
Show Gist options
  • Save ximeg/aae4455928c47322f182c187c6f922be to your computer and use it in GitHub Desktop.
Save ximeg/aae4455928c47322f182c187c6f922be to your computer and use it in GitHub Desktop.
Save napari layer as displayed at full resolution
LAYER = 'Cy3'
OUT = 'my_exported_image_' + LAYER
from matplotlib import pyplot as plt
import numpy as np
layer = viewer.layers[LAYER]
img = layer.data
dpi = 300
w, h = np.array(img.shape) / dpi
fig = plt.figure(frameon=False)
fig.set_size_inches(w, h)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
vmin, vmax = layer.contrast_limits
ax.imshow(img, aspect='auto', cmap=layer.colormap.name, vmin=vmin, vmax=vmax)
fig.savefig('my_awesome_image.png', dpi=dpi)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment