def test_vectorData_datatype1():
    """
    test data of coord-like shape
    :return:
    """
    with app_context():
        # create the viewer and window
        viewer = ViewerApp()

        N = 10
        pos = np.zeros(shape=(N, 4), dtype=np.float32)
        try:
            viewer.add_vectors(pos)
        except Exception as ex:
            print("exception thrown when creating coord-like vector layer: "+str(ex))
def test_vectorData_image_assignment(self):
    """
    test replacing vector data after layer construction
    :return:
    """
    with app_context():
        # create the viewer and window
        viewer = ViewerApp()

        N = 10
        pos = np.zeros(shape=(N, 4), dtype=np.float32)
        pos2 = np.zeros(shape=(N, N, 2), dtype=np.float32)
        try:
            layer = viewer.add_vectors(pos)
            layer.vectors = pos2
        except Exception as ex:
            print("exception thrown when : "+str(ex))
def test_vectorData_datatype_notimpl2(self):
    """
    test data of vispy-coordinate shape (not allowed)
    :return:
    """
    with app_context():
        # create the viewer and window
        viewer = ViewerApp()

        N = 10
        pos = np.zeros(shape=(N, 2), dtype=np.float32)
        try:
            viewer.add_vectors(pos)
        except InvalidDataFormatError:
            print('invalid data format')
        except Exception as ex:
            print("exception thrown when creating not implemented vector layer: "+str(ex))
def test_vectorData_datatype_notimpl():
    """
    test data of improper shape
    :return:
    """
    with app_context():
        # create the viewer and window
        viewer = ViewerApp()

        N = 10
        M = 5
        pos = np.zeros(shape=(N, M, 4), dtype=np.float32)
        try:
            viewer.add_vectors(pos)
        except InvalidDataFormatError:
            print('invalid data format')
        except Exception as ex:
            print("exception thrown when creating not implemented vector layer: "+str(ex))
Esempio n. 5
0
"""
Display one shapes layer ontop of one image layer using the add_shapes and
add_image APIs. When the window is closed it will print the coordinates of
your shapes.
"""

import numpy as np
from skimage import data
from skimage.color import rgb2gray
from napari import ViewerApp
from napari.util import app_context

with app_context():
    # create the viewer and window
    viewer = ViewerApp()

    # add the image
    layer = viewer.add_image(data.camera(), name='photographer')
    layer.colormap = 'gray'

    # create a list of polygons
    polygons = [
        np.array([[11, 13], [111, 113], [22, 246]]),
        np.array([[505, 60], [402, 71], [383, 42], [251, 95], [212, 59],
                  [131, 137], [126, 187], [191, 204], [171, 248], [211, 260],
                  [273, 243], [264, 225], [430, 173], [512, 160]]),
        np.array([[310, 382], [229, 381], [209, 401], [221, 411], [258, 411],
                  [300, 412], [306, 435], [268, 434], [265, 454], [298, 461],
                  [307, 461], [307, 507], [349, 510], [352, 369], [330, 366],
                  [330, 366]])
    ]
Esempio n. 6
0
"""
Displays one image using the add_image API and then adjust some of its
properties
"""

from skimage import data
from skimage.color import rgb2gray
from napari import ViewerApp
from napari.util import app_context


with app_context():
    # create the viewer with an image
    viewer = ViewerApp(astronaut=rgb2gray(data.astronaut()))

    # adjust some of the layer properties
    layer = viewer.layers[0]

    # change the layer name
    layer.name = 'astronaut'

    # change the layer visibility
    layer.visible = False
    layer.visible = True

    # change the layer selection
    layer.selected = False
    layer.selected = True

    # set the layer property widget to be expanded
    layer._qt_properties.setExpanded(True)
Esempio n. 7
0
"""
Display one markers layer ontop of one 4-D image layer using the
add_markers and add_image APIs, where the markes are visible as nD objects
accross the dimensions, specified by their size
"""

import numpy as np
from skimage import data
from napari import ViewerApp
from napari.util import app_context

with app_context():
    # TODO: change axis back to 0 once dims displayed in sane order
    blobs = np.stack([
        data.binary_blobs(
            length=128, blob_size_fraction=0.05, n_dim=3, volume_fraction=f)
        for f in np.linspace(0.05, 0.5, 10)
    ],
                     axis=-1)
    viewer = ViewerApp(blobs.astype(float))
    # add the markers
    markers = np.array([[100, 100, 0, 0], [50, 120, 0, 0], [100, 40, 1, 0],
                        [110, 20, 100, 2], [400, 100, 10, 8]])
    viewer.add_markers(markers,
                       size=[10, 10, 6, 0],
                       face_color='blue',
                       n_dimensional=True)
Esempio n. 8
0
"""
Displays an image and sets the theme to 'light'.
"""

from skimage import data
from napari import ViewerApp
from napari.util import app_context

with app_context():
    # create the viewer with an image
    viewer = ViewerApp(astronaut=data.astronaut(), title='napari light theme')

    # set the theme to 'light'
    viewer.theme = 'light'
Esempio n. 9
0
Vector data is an array of shape (N, 4)
Each vector position is defined by an (x, y, x-proj, y-proj) element
    where x and y are the center points
    where x-proj and y-proj are the vector projections at each center

"""

from napari import ViewerApp
from napari.util import app_context
from skimage import data

import numpy as np

with app_context():
    # create the viewer and window
    viewer = ViewerApp()

    layer = viewer.add_image(data.camera(), name='photographer')
    layer.colormap = 'gray'

    # sample vector coord-like data
    n = 1000
    pos = np.zeros((n, 4), dtype=np.float32)
    phi_space = np.linspace(0, 4 * np.pi, n)
    radius_space = np.linspace(0, 100, n)

    # assign x-y position
    pos[:, 0] = radius_space * np.cos(phi_space) + 350
    pos[:, 1] = radius_space * np.sin(phi_space) + 256

    # assign x-y projection
Esempio n. 10
0
"""
This example generates an image of vectors
Vector data is an array of shape (N, M, 2)
Each vector position is defined by an (x-proj, y-proj) element
    where x-proj and y-proj are the vector projections at each center
    where each vector is centered on a pixel of the NxM grid
"""

from napari import ViewerApp
from napari.util import app_context

import numpy as np

with app_context():
    # create the viewer and window
    viewer = ViewerApp()

    n = 100
    m = 200

    image = 0.2*np.random.random((n, m)) + 0.5
    layer = viewer.add_image(image, clim_range=[0, 1], name='background')
    layer.colormap = 'gray'

    # sample vector image-like data
    # n x m grid of slanted lines
    # random data on the open interval (-1, 1)
    pos = np.zeros(shape=(n, m, 2), dtype=np.float32)
    rand1 = 2*(np.random.random_sample(n * m)-0.5)
    rand2 = 2*(np.random.random_sample(n * m)-0.5)
Esempio n. 11
0
"""
Display one markers layer ontop of one image layer using the add_markers and
add_image APIs
"""

import numpy as np
from skimage import data
from skimage.color import rgb2gray
from napari import ViewerApp
from napari.util import app_context

print("click to add markers; close the window when finished.")

with app_context():
    viewer = ViewerApp(rgb2gray(data.astronaut()))
    markers = viewer.add_markers(np.zeros((0, 2)))
    markers.mode = 'add'

print("you clicked on:")
print(markers.coords)
Esempio n. 12
0
"""
Display multiple image layers using the add_image API and then reorder them
using the layers swap method and remove one
"""

from skimage import data
from skimage.color import rgb2gray
from napari import ViewerApp
from napari.util import app_context


with app_context():
    # create the viewer with several image layers
    viewer = ViewerApp(astronaut=rgb2gray(data.astronaut()),
                       photographer=data.camera(),
                       coins=data.coins(),
                       moon=data.moon())

    # remove the coins layer
    viewer.layers.remove('coins')

    # swap the order of astronaut and moon
    viewer.layers['astronaut', 'moon'] = viewer.layers['moon', 'astronaut']
Esempio n. 13
0
add_image APIs
"""

from skimage import data
from skimage.filters import threshold_otsu
from skimage.segmentation import clear_border
from skimage.measure import label
from skimage.morphology import closing, square, remove_small_objects
from napari import ViewerApp
from napari.util import app_context

with app_context():
    image = data.coins()[50:-50, 50:-50]

    # apply threshold
    thresh = threshold_otsu(image)
    bw = closing(image > thresh, square(4))

    # remove artifacts connected to image border
    cleared = remove_small_objects(clear_border(bw), 20)

    # label image regions
    label_image = label(cleared)

    # initialise viewer with astro image
    viewer = ViewerApp(coins=image, multichannel=False)
    viewer.layers[0].colormap = 'gray'

    # add the labels
    label_layer = viewer.add_labels(label_image, name='segmentation')
Esempio n. 14
0
"""
Display a labels layer above of an image layer using the add_labels and
add_image APIs
"""

from skimage import data
from scipy import ndimage as ndi
from napari import ViewerApp
from napari.util import app_context

with app_context():
    blobs = data.binary_blobs(length=128, volume_fraction=0.1, n_dim=3)
    v = ViewerApp(blobs=blobs)
    v.layers[0].colormap = 'gray'
    labeled = ndi.label(blobs)[0]
    label_layer = v.add_labels(labeled, name='blob ID')
Esempio n. 15
0

def set_index(index):
    global curr_index

    if index < 0:
        index = 0
    if index >= get_max_index():
        index = get_max_index() - 1

    curr_index = index


with app_context():
    # create an empty viewer
    viewer = ViewerApp()

    def save(viewer, layer_name="annotations"):
        """Save the current annotations
        """
        labels = viewer.layers[layer_name].image.astype(np.uint16)

        if (not save_if_empty) and np.all(labels == 0):
            msg = "{} layer is empty. save_if_empty set to False.".format(
                viewer.layers[layer_name].name)
            print(msg)
            viewer.status = msg
            return

        save_path = annotation_paths[curr_index]
        imsave(save_path, labels, plugin="tifffile", photometric="minisblack")
Esempio n. 16
0
"""
Display one 4-D image layer using the add_image API
"""

import numpy as np
from skimage import data
from napari import ViewerApp
from napari.util import app_context


with app_context():
    viewer = ViewerApp()
    blobs = data.binary_blobs(length=128, blob_size_fraction=0.05,
                              n_dim=2, volume_fraction=.25).astype(float)

    viewer.add_image(blobs, name='blobs')

    def accept_image(viewer):
        msg = 'this is a good image'
        viewer.status = msg
        print(msg)
        next(viewer)

    def reject_image(viewer):
        msg = 'this is a bad image'
        viewer.status = msg
        print(msg)
        next(viewer)

    def next(viewer):
        blobs = data.binary_blobs(length=128, blob_size_fraction=0.05,
Esempio n. 17
0
"""
Display one shapes layer ontop of one image layer using the add_shapes and
add_image APIs. When the window is closed it will print the coordinates of
your shapes.
"""

import numpy as np
from skimage import data
from skimage.color import rgb2gray
from napari import ViewerApp
from napari.util import app_context
from vispy.color import Colormap

with app_context():
    # create the viewer and window
    viewer = ViewerApp()

    # add the image
    layer = viewer.add_image(data.camera(), name='photographer')
    layer.colormap = 'gray'

    # create a list of polygons
    polygons = [
        np.array([[11, 13], [111, 113], [22, 246]]),
        np.array([[505, 60], [402, 71], [383, 42], [251, 95], [212, 59],
                  [131, 137], [126, 187], [191, 204], [171, 248], [211, 260],
                  [273, 243], [264, 225], [430, 173], [512, 160]]),
        np.array([[310, 382], [229, 381], [209, 401], [221, 411], [258, 411],
                  [300, 412], [306, 435], [268, 434], [265, 454], [298, 461],
                  [307, 461], [307, 507], [349, 510], [352, 369], [330, 366],
                  [330, 366]])
Esempio n. 18
0
"""
Displays one image using the add_image API and then adjust some of its
properties
"""

from skimage import data
from skimage.color import rgb2gray
from napari import ViewerApp
from napari.util import app_context

with app_context():
    # create the viewer with an image
    viewer = ViewerApp(astronaut=rgb2gray(data.astronaut()),
                       title='napari example')

    # adjust some of the layer properties
    layer = viewer.layers[0]

    # change the layer name
    layer.name = 'astronaut'

    # change the layer visibility
    layer.visible = False
    layer.visible = True

    # change the layer selection
    layer.selected = False
    layer.selected = True

    # set the layer property widget to be expanded
    layer._qt_properties.setExpanded(True)
from recOrder.visualization.GUI.RecorderWindowControl import RecorderWindowControl
from recOrder.program.SignalController.SignalController import SignalController
from recOrder.analysis.Processing.ReconOrder import ReconOrder
from py4j.java_gateway import JavaGateway
from recOrder.MicroscopeController.mm2python_controller import py4j_monitor_LC

from napari import ViewerApp
from napari.util import app_context

if __name__ == '__main__':
    with app_context():

        gateway = JavaGateway()

        #create Viewer, Windows
        viewer = ViewerApp()
        viewer_window = NapariWindow(viewer)

        recorder_window = QtWidgets.QDialog()
        recorder = RecorderWindowControl(recorder_window, gateway=gateway)
        recorder_window.show()

        #initialize file loaders
        loader = PipeFromFiles(type="Test", sample_type="Sample1")
        loader_bg = PipeFromFiles(type="Test", sample_type='BG')

        #initialize processors
        processor = ReconOrder()

        #initialize SignalController
        signals = SignalController()
Esempio n. 20
0
"""
Display one 4-D image layer using the add_image API
"""

import numpy as np
from skimage import data
from napari import ViewerApp
from napari.util import app_context

with app_context():
    blobs = np.stack([
        data.binary_blobs(
            length=128, blob_size_fraction=0.05, n_dim=3, volume_fraction=f)
        for f in np.linspace(0.05, 0.5, 10)
    ],
                     axis=0)
    viewer = ViewerApp(blobs.astype(float))
Esempio n. 21
0
"""
Display one markers layer ontop of one image layer using the add_markers and
add_image APIs
"""

import numpy as np
from skimage import data
from skimage.color import rgb2gray
from napari import ViewerApp
from napari.util import app_context

with app_context():
    # create the viewer and window
    viewer = ViewerApp()

    # add the image
    viewer.add_image(rgb2gray(data.astronaut()))
    # add the markers
    markers = np.array([[100, 100], [200, 200], [333, 111]])
    size = np.array([10, 20, 20])
    viewer.add_markers(markers, size=size)

    # unselect the image layer
    viewer.layers[0].selected = False

    # adjust some of the marker layer properties
    layer = viewer.layers[1]

    # change the layer name
    layer.name = 'spots'
Esempio n. 22
0
"""
Display one 4-D image layer using the add_image API
"""

import dask.array as da
import zarr
import numpy as np
from skimage import data
from napari import ViewerApp
from napari.util import app_context

with app_context():
    data = zarr.zeros((102_000, 200, 210), chunks=(100, 200, 210))
    data[53_000:53_100, 100:110, 110:120] = 1

    array = da.from_zarr(data)
    print(array.shape)
    viewer = ViewerApp(array, clim_range=[0, 1], multichannel=False)
Esempio n. 23
0
"""
Display a labels layer above of an image layer using the add_labels and
add_image APIs
"""

from skimage import data
from skimage.color import rgb2gray
from skimage.segmentation import slic
from napari import ViewerApp
from napari.util import app_context


with app_context():
    astro = data.astronaut()

    # initialise viewer with astro image
    viewer = ViewerApp(astronaut=rgb2gray(astro), multichannel=False)
    viewer.layers[0].colormap = 'gray'

    # add the labels
    # we add 1 because SLIC returns labels from 0, which we consider background
    labels = slic(astro, multichannel=True, compactness=20) + 1
    label_layer = viewer.add_labels(labels, name='segmentation')
    print(f'The color of label 5 is {label_layer.label_color(5)}')