Ejemplo n.º 1
0
def test_exclude_labels_on_edges_blobs():
    import pyclesperanto_prototype as cle

    from skimage.io import imread, imsave

    # initialize GPU
    cle.select_device("GTX")
    print("Used GPU: " + cle.get_device().name)

    # load data
    root = Path(cle.__file__).parent
    filename = str(root / '..' / 'data' / 'blobs.tif')
    image = imread(filename)
    print("Loaded image size: " + str(image.shape))

    # push image to GPU memory
    input = cle.push(image)
    print("Image size in GPU: " + str(input.shape))

    # process the image
    blurred = cle.gaussian_blur(image, sigma_x=1, sigma_y=1)
    binary = cle.threshold_otsu(blurred)
    labeled = cle.connected_components_labeling_box(binary)

    wo_edges = cle.exclude_labels_on_edges(labeled)

    # The maxmium intensity in a label image corresponds to the number of objects
    num_labels = cle.maximum_of_all_pixels(wo_edges)

    # print out result
    print("Num objects in the image: " + str(num_labels))

    assert num_labels == 45
Ejemplo n.º 2
0
def test_connected_components_labeling_box_blobs():
    import pyclesperanto_prototype as cle

    from skimage.io import imread, imsave

    # initialize GPU
    cle.select_device("GTX")
    print("Used GPU: " + cle.get_device().name)

    # load data
    image = imread('https://imagej.nih.gov/ij/images/blobs.gif')
    print("Loaded image size: " + str(image.shape))

    # push image to GPU memory
    input = cle.push(image)
    print("Image size in GPU: " + str(input.shape))

    # process the image
    inverted = cle.subtract_image_from_scalar(image, scalar=255)
    blurred = cle.gaussian_blur(inverted, sigma_x=1, sigma_y=1)
    binary = cle.threshold_otsu(blurred)
    labeled = cle.connected_components_labeling_box(binary)

    # The maxmium intensity in a label image corresponds to the number of objects
    num_labels = cle.maximum_of_all_pixels(labeled)

    # print out result
    print("Num objects in the image: " + str(num_labels))

    assert num_labels == 63
Ejemplo n.º 3
0
def test_average_distance_of_n_nearest_other_labels_map():
    cle.select_device("gfx")

    labels = cle.push(
        np.asarray([[1, 0, 0, 0, 0, 3], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0,
                                                             2]]))

    other_labels = cle.push(
        np.asarray([[0, 2, 0, 0, 0, 3], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 4], [0, 0, 0, 0, 5,
                                                             0]]))

    reference = cle.push(
        np.asarray([[1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0,
                                                             1]]))

    average_distance_to_n_nearest_other_labels_map = cle.average_distance_to_n_nearest_other_labels_map(
        labels, other_labels, n=1)

    a = cle.pull(average_distance_to_n_nearest_other_labels_map)
    b = cle.pull(reference)

    print(a)
    print(b)

    assert (np.allclose(a, b, 0.01))
def test_gpu_switch():
    image = np.random.random((100, 100))

    # select NVidia
    print(cle.select_device("RTX"))
    cle.gaussian_blur(image, sigma_x=1, sigma_y=1)

    # select AMD
    print(cle.select_device("gfx"))
    cle.gaussian_blur(image, sigma_x=1, sigma_y=1)

    # select Intel
    print(cle.select_device("Intel"))
    cle.gaussian_blur(image, sigma_x=1, sigma_y=1)
Ejemplo n.º 5
0
def main():
    import napari
    from skimage.io import imread
    import pyclesperanto_prototype as cle
    from napari_pyclesperanto_assistant._gui._Assistant import Assistant

    import sys

    if len(sys.argv) > 1:
        filename = str(sys.argv[1])
        image = imread(filename)
    else:
        # make some artificial cell image
        filename = "undefined.tif"
        labels = cle.artificial_tissue_2d(width=512,
                                          height=512,
                                          delta_x=48,
                                          delta_y=32,
                                          random_sigma_x=6,
                                          random_sigma_y=6)
        membranes = cle.detect_label_edges(labels)
        eroded = cle.maximum_sphere(membranes, radius_x=3, radius_y=3)
        blurred = cle.gaussian_blur(eroded, sigma_x=3, sigma_y=3)
        image = cle.pull_zyx(blurred)

    #image = imread('https://samples.fiji.sc/blobs.png')
    #image = imread('C:/structure/data/lund_000500_resampled.tif')
    #filename = 'data/Lund_000500_resampled-cropped.tif'
    #filename = str(Path(__file__).parent) + '/data/CalibZAPWfixed_000154_max-16.tif'

    print("Available GPUs: " + str(cle.available_device_names()))
    cle.select_device("rtx")
    print("Used GPU: " + str(cle.get_device()))

    with napari.gui_qt():
        # create a viewer and add some image
        viewer = napari.Viewer()
        layer = viewer.add_image(image, metadata={'filename': filename})

        from napari_pyclesperanto_assistant import napari_plugin
        napari_plugin(viewer)
Ejemplo n.º 6
0
    dock_widget = table_to_widget(table)
    viewer.window.add_dock_widget(dock_widget, area='right')


def table_to_widget(table: dict) -> QTableWidget:
    view = QTableWidget(len(next(iter(table.values()))), len(table))
    for i, column in enumerate(table.keys()):
        view.setItem(0, i, QTableWidgetItem(column))
        for j, value in enumerate(table.get(column)):
            view.setItem(j + 1, i, QTableWidgetItem(str(value)))
    return view


# -----------------------------------------------------------------------------
from skimage.io import imread

image = imread('https://samples.fiji.sc/blobs.png')

#image = imread('C:/structure/data/lund_000500_resampled.tif')

cle.select_device("RTX")
print(cle.get_device())

with napari.gui_qt():
    # create a viewer and add some image
    viewer = napari.Viewer()
    viewer.add_image(image)

    # add the gui to the viewer as a dock widget
    dock_widget = viewer.window.add_dock_widget(Gui(viewer), area='right')
Ejemplo n.º 7
0
import pyclesperanto_prototype as cle

# list names of all available OpenCL-devices
print("Available OpenCL devices:" + str(cle.available_device_names()))

# list CPUs and GPUs separately
gpu_devices = cle.available_device_names(dev_type="gpu")
print("Available GPU OpenCL devices:" + str(gpu_devices))

cpu_devices = cle.available_device_names(dev_type="cpu")
print("Available CPU OpenCL devices:" + str(cpu_devices))

# selecting an Nvidia RTX
cle.select_device("RTX")
print("Using OpenCL device " + cle.get_device().name)

# selecting an Nvidia GTX
cle.select_device("GTX")
print("Using OpenCL device " + cle.get_device().name)

# selecting an Intel UHD GPU
cle.select_device("Intel")
print("Using OpenCL device " + cle.get_device().name)

# selecting an AMD Vega GPU
cle.select_device("904")
print("Using OpenCL device " + cle.get_device().name)

# selecting an AMD Vega GPU
cle.select_device("902")
print("Using OpenCL device " + cle.get_device().name)
Ejemplo n.º 8
0
import pyclesperanto_prototype as cle
import numpy as np
import time

cle.select_device('RTX')
cle.set_wait_for_kernel_finish(True)

# config
num_iterations = 10
num_tests = 10

# initialize GPU
print("Used GPU: " + cle.get_device().name)

# generate data; 50 MB
image = np.random.random([50, 1024, 1024])
print("Image size: " + str(image.shape))

# push image to GPU memory
flip = cle.push_zyx(image)
flop = cle.create_like(flip)

for j in range(0, num_tests):
    start = time.time()

    for i in range(0, num_iterations):
        cle.maximum_sphere(flip, flop, 3, 3, 0)
        cle.minimum_sphere(flop, flip, 3, 3, 0)

    end = time.time()
Ejemplo n.º 9
0
import pyclesperanto_prototype as cle

from skimage.io import imread, imsave

# initialize GPU
cle.select_device("GTX")
print("Used GPU: " + cle.get_device().name)

# load data
image = imread('https://imagej.nih.gov/ij/images/blobs.gif')
print("Loaded image size: " + str(image.shape))

# push image to GPU memory
input = cle.push(image)
print("Image size in GPU: " + str(input.shape))

# process the image
inverted = cle.subtract_image_from_scalar(image, scalar=255)
blurred = cle.gaussian_blur(inverted, sigma_x=1, sigma_y=1)
binary = cle.threshold_otsu(blurred)
labeled = cle.connected_components_labeling_box(binary)

# The maxmium intensity in a label image corresponds to the number of objects
num_labels = cle.maximum_of_all_pixels(labeled)

# print out result
print("Num objects in the image: " + str(num_labels))

# for debugging: print out image
print(labeled)
# Tribolium castaneum morphometry workflow
# See also: https://clij.github.io/clij2-docs/md/tribolium_morphometry/
# Thanks to Pradeep Rajasekhar (Monash University) and Daniela Vorkel (MPI CBG Dresden)
# for code snippets and data :-)

import pyclesperanto_prototype as cle

# we need to select a powerful GPU for this
cle.select_device()

# check which GPU we use
print(cle.get_device().name)

# load data
from skimage.io import imread
image = imread('/home2/kdean/Desktop/lund1051_resampled.tif')
# The dataset is available online:
# https://git.mpi-cbg.de/rhaase/clij2_example_data/blob/master/lund1051_resampled.tif

print(image.shape)

# The dataset shows a Tribolium castaneum embryo, imaged by a custom light sheet microscope,
# at a wavelength of 488nm (Imaging credits: Daniela Vorkel, Myers lab, MPI CBG).
# The data set has be resample to a voxel size of
voxel_size = [1, 1, 1]  # microns
# The embryo expresses nuclei-GFP. We will use the dataset to detect nuclei and to generate
# an estimated cell-segmentation.

# Define an interactive user interface using magicgui
from magicgui import magicgui
from napari.layers import Image, Labels