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
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
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)
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')
# 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("RTX") # check which GPU we use print(cle.get_device().name) # load data from skimage.io import imread image = imread('C:\structure\data\Lund_18.0_22.0_Hours.tif') # The dataset is available online: # https://zenodo.org/record/4276076#.X8QJWc1KguV print(image.shape) # extract a time point image = image[12] # 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 a voxel size of voxel_size = [0.6934000, 0.6934000, 2.5] # microns # The embryo expresses nuclei-GFP. We will use the dataset to detect nuclei and to generate # an estimated cell-segmentation.
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)
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()