How to use the napari.gui_qt 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 / examples / 5D_image.py View on Github external
"""
Display one 5-D image layer using the add_image API
"""

import numpy as np
from skimage import data
import napari


with napari.gui_qt():

    viewer = napari.view(np.random.random((4, 4, 1, 30, 40)))
github constantinpape / cluster_tools / publications / leveraging_domain_knowledge / 1_axon_dendrite_attribution / 4_view_results.py View on Github external
ds.n_threads = 4
        raw = ds[:]

        ds = f['probs/membranes']
        ds.n_threads = 4
        mem = ds[:]

        ds = f['volumes/segmentation/multicut']
        ds.n_threads = 4
        mc_seg = ds[:]

        ds = f['volumes/segmentation/lifted_multicut']
        ds.n_threads = 4
        lmc_seg = ds[:]

    with napari.gui_qt():
        viewer = napari.Viewer()
        viewer.add_image(raw, name='raw')
        viewer.add_image(mem, name='membranes')

        viewer.add_labels(mc_seg, name='mc-seg')
        viewer.add_labels(lmc_seg, name='lmc-seg')
github napari / napari / examples / set_colormaps.py View on Github external
Add named or unnamed vispy colormaps to existing layers.
"""

import numpy as np
import vispy.color
from skimage import data
import napari


histo = data.astronaut() / 255
rch, gch, bch = np.transpose(histo, (2, 0, 1))
red = vispy.color.Colormap([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]])
green = vispy.color.Colormap([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
blue = vispy.color.Colormap([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]])

with napari.gui_qt():
    v = napari.Viewer()

    rlayer = v.add_image(rch, name='red channel')
    rlayer.blending = 'additive'
    rlayer.colormap = 'red', red
    glayer = v.add_image(gch, name='green channel')
    glayer.blending = 'additive'
    glayer.colormap = green  # this will appear as [unnamed colormap]
    blayer = v.add_image(bch, name='blue channel')
    blayer.blending = 'additive'
    blayer.colormap = {'blue': blue}
github zeiss-microscopy / OAD / jupyter_notebooks / Read_CZI_and_OMETIFF_and_display_widgets_and_napari / modules / imgfileutils.py View on Github external
:type verbose: bool, optional
    :param use_pylibczi: specify if pylibczi was used to read the CZI file, defaults to True
    :type use_pylibczi: bool, optional
    """

    def calc_scaling(data, corr_min=1.0,
                     offset_min=0,
                     corr_max=0.85,
                     offset_max=0):

        # get min-max values for initial scaling
        minvalue = np.round((data.min() + offset_min) * corr_min)
        maxvalue = np.round((data.max() + offset_max) * corr_max)
        print('Scaling: ', minvalue, maxvalue)

    with napari.gui_qt():

        # create scalefcator with all ones
        scalefactors = [1.0] * len(array.shape)

        # initialize the napari viewer
        print('Initializing Napari Viewer ...')
        viewer = napari.Viewer()

        if metadata['ImageType'] == 'ometiff':

            # find position of dimensions
            posZ = metadata['DimOrder BF Array'].find('Z')
            posC = metadata['DimOrder BF Array'].find('C')
            posT = metadata['DimOrder BF Array'].find('T')

            # get the scalefactors from the metadata
github napari / napari / examples / add_pyramid.py View on Github external
from skimage import data
from skimage.util import img_as_ubyte
from skimage.color import rgb2gray
from skimage.transform import pyramid_gaussian
import napari
import numpy as np


# create pyramid from astronaut image
base = np.tile(data.astronaut(), (8, 8, 1))
pyramid = list(
    pyramid_gaussian(base, downscale=2, max_layer=4, multichannel=True)
)
print('pyramid level shapes: ', [p.shape[:2] for p in pyramid])

with napari.gui_qt():
    # add image pyramid
    napari.view_image(pyramid, is_pyramid=True)
github AllenCellModeling / aicsimageio / aicsimageio / aics_image.py View on Github external
if data.shape[c_axis] > 3:
                        visible = False
                    else:
                        visible = True
                else:
                    visible = True

                # Drop channel from dims string
                dims = (
                    dims.replace(Dimensions.Channel, "")
                    if Dimensions.Channel in dims
                    else dims
                )

                # Run napari
                with napari.gui_qt():
                    napari.view_image(
                        data,
                        is_pyramid=False,
                        ndisplay=3 if Dimensions.SpatialZ in dims else 2,
                        channel_axis=c_axis,
                        axis_labels=dims,
                        title=title,
                        visible=visible,
                        **kwargs,
                    )

        except ModuleNotFoundError:
            raise ModuleNotFoundError(
                "'napari' has not been installed. To use this function install napari "
                "with either: pip install napari' or "
github constantinpape / elf / example / embeddings / ovules.py View on Github external
def segment_from_embeddings():
    in_folder = '/home/pape/Work/data/data_science_bowl/dsb2018/test/images'
    input_images = os.listdir(in_folder)

    test_image = input_images[0]
    test_name = os.path.splitext(test_image)[0]
    im = np.asarray(imageio.imread(os.path.join(in_folder, test_image)))

    pred_file = './predictions.h5'
    with h5py.File(pred_file, 'r') as f:
        pred = f[test_name][:]

    pca = embed.embedding_pca(pred).transpose((1, 2, 0))
    seg = embed.embedding_slic(pred)

    with napari.gui_qt():
        viewer = napari.Viewer()
        viewer.add_image(im, name='image')
        viewer.add_image(pca, rgb=True, name='pca')
        viewer.add_labels(seg, name='segmentation')
github AllenCellModeling / aicsimageio / aicsimageio / aics_image.py View on Github external
# Create name for window
            if isinstance(self.reader, ArrayLikeReader):
                title = f"napari: {self.dask_data.shape}"
            else:
                title = f"napari: {self.reader._file.name}"

            # Handle RGB entirely differently
            if rgb:
                # Swap channel to last dimension
                new_dims = f"{dims.replace(Dimensions.Channel, '')}{Dimensions.Channel}"
                data = transforms.transpose_to_dims(
                    data=data, given_dims=dims, return_dims=new_dims
                )

                # Run napari
                with napari.gui_qt():
                    napari.view_image(
                        data,
                        is_pyramid=False,
                        ndisplay=3 if Dimensions.SpatialZ in dims else 2,
                        title=title,
                        axis_labels=dims.replace(Dimensions.Channel, ""),
                        rgb=rgb,
                        **kwargs,
                    )

            # Handle all other images besides RGB not requested
            else:
                # Channel axis
                c_axis = (
                    dims.index(Dimensions.Channel)
                    if Dimensions.Channel in dims
github napari / napari / examples / xarray_nD_image.py View on Github external
Displays an xarray
"""

try:
    import xarray as xr
except ImportError:
    raise ImportError("""This example uses a xarray but xarray is not
    installed. To install try 'pip install xarray'.""")

import numpy as np
import napari

data = np.random.random((20, 40, 50))
xdata = xr.DataArray(data, dims=['z', 'y', 'x'])

with napari.gui_qt():
    # create an empty viewer
    viewer = napari.Viewer()

    # add the xarray
    layer = viewer.add_image(xdata, name='xarray')
github constantinpape / elf / example / transformation / affine.py View on Github external
with h5py.File(path, 'r') as f:
        inp = f['raw'][:]

    bb = np.s_[0:5, 0:256, 0:256]
    matrix = compute_affine_matrix(scale=(2., 2., 2.), rotation=(25., 0., 0.))

    print("Transform elf ...")
    t1 = transform_subvolume_with_affine(inp, matrix, bb)
    print("Transform scipy ...")
    t2 = affine_transform(inp, matrix, order=0)[bb]

    not_close = ~np.isclose(t1, t2)
    print("Not close elements:", not_close.sum(), "/", t2.size)
    not_close = not_close.reshape(t2.shape)

    with napari.gui_qt():
        viewer = napari.Viewer()
        viewer.add_image(t1, name='transformed-elf')
        viewer.add_image(t2, name='transformed-scipy')
        viewer.add_labels(not_close, name='diff-pixel')