Last active
August 31, 2021 18:51
-
-
Save psobolewskiPhD/2890e50504224533c46ee1d1d482ea81 to your computer and use it in GitHub Desktop.
Widget to browse LIF scenes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#%% | |
from aicsimageio import AICSImage | |
import napari | |
import dask.array as da | |
import numpy as np | |
from vispy.color import Colormap | |
import os | |
from qtpy.QtWidgets import QListWidget | |
from qtpy.QtCore import Qt | |
#%% | |
# Load data from LIF into a dask stack | |
img = AICSImage( | |
os.path.expanduser("~/Documents/Leica DMi8/20210428/20210428_24w_L929_Ho_B2C3.lif"), | |
reconstruct_mosaic=False, | |
) | |
#%% | |
# get pixel sizes (this is px/micron) | |
# 1/img.physical_pixel_sizes.X was needed before AICSI 4.10 now it's fixed! | |
microns_per_pixel = [img.physical_pixel_sizes.X, img.physical_pixel_sizes.Y] | |
# User Napari to view the stack of ROIs | |
I_Blueish = Colormap([[1, 1, 1], [0, 0.4, 1], [0, 0, 0]]) | |
#%% | |
def open_scene(item): | |
scene = item.text() | |
img.set_scene(scene) | |
viewer.add_image( | |
img.get_image_dask_data("CZYX"), | |
name=scene, | |
colormap=("I Blueish", I_Blueish), | |
scale=microns_per_pixel, | |
) | |
#%% | |
# Cache dask stuff, based on @TalleyJLambert in napari zulip | |
from napari.utils import resize_dask_cache | |
cache = resize_dask_cache() | |
# Widget based on @sofroniewn https://github.com/sofroniewn/image-demos/blob/b39128d708cbb88902bd91ac383da3772c51eb64/examples/rxrx19_browser.py | |
viewer = napari.Viewer() | |
list_widget = QListWidget() | |
for scene in img.scenes: | |
list_widget.addItem(scene) | |
list_widget.currentItemChanged.connect(open_scene) | |
viewer.window.add_dock_widget([list_widget], area="right") | |
# %% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment