Functionalities

Collection of operations aiming to help in displaying and analyzing results, e.g. to visualize images.

execute(anchor=None, kernel_source: str = '', kernel_name: str = '', global_size: tuple = (1, 1, 1), parameters: dict = {}, constants: dict = {}, device: pyclesperanto._pyclesperanto._Device = None)[source]

Execute a kernel from a file or a string

Call, build, and execute a kernel compatible with CLIj framework. The kernel can be called from a file or a string.

Parameters:
  • anchor (str, default = 'None') – Use __file__ when calling this method and the corresponding open.cl file lies in the same folder as the python file calling it. Ignored if kernel_source is a string.

  • kernel_source (str) – Filename of the open.cl file to be called, or string containing the open.cl source code

  • kernel_name (str) – Kernel method inside the open.cl file to be called most clij/clesperanto kernel functions have the same name as the file they are in

  • global_size (tuple (z,y,x), default = (1, 1, 1)) – Global_size according to OpenCL definition (usually shape of the destination image).

  • parameters (dict(str, [Array, float, int])) – Dictionary containing parameters. Take care: They must be of the right type and in the right order as specified in the open.cl file.

  • constants (dict(str, int), optional) – Dictionary with names/values which will be added to the define statements. They are necessary, e.g. to create arrays of a given maximum size in OpenCL as variable array lengths are not supported.

  • device (Device, default = None) – The device to execute the kernel on. If None, use the current device

imshow(image, title: str | None = None, labels: bool | None = False, min_display_intensity: float | None = None, max_display_intensity: float | None = None, color_map: str | None = None, plot=None, colorbar: bool | None = False, colormap: str | ListedColormap | None = None, alpha: float | None = None, continue_drawing: bool | None = False)[source]

Visualize an image, e.g. in Jupyter notebooks using matplotlib.

Parameters:
  • image (np.ndarray) – numpy or OpenCL-backed image to visualize

  • title (str, optional) – Obsolete (kept for ImageJ-compatibility)

  • labels (bool, optional) – True: integer labels will be visualized with colors False: Specified or default colormap will be used to display intensities.

  • min_display_intensity (float, optional) – lower limit for display range

  • max_display_intensity (float, optional) – upper limit for display range

  • color_map (str, optional) – deprecated, use colormap instead

  • plot (matplotlib axis, optional) – Plot object where the image should be shown. Useful for putting multiple images in subfigures.

  • colorbar (bool, optional) – True puts a colorbar next to the image. Will not work with label images and when visualizing multiple images (continue_drawing=True).

  • colormap (str or matplotlib colormap, optional)

  • alpha (float, optional) – alpha blending value

  • continue_drawing (float) – True: the next shown image can be visualized on top of the current one, e.g. with alpha = 0.5

native_execute(anchor=None, kernel_source: str = '', kernel_name: str = '', global_size: tuple = (1, 1, 1), local_size: tuple = (1, 1, 1), parameters: dict = {}, device: pyclesperanto._pyclesperanto._Device = None)[source]

Execute an OpenCL kernel from a file or a string

Call, build, and execute a kernel compatible with OpenCL language. The kernel can be called from a file or a string.

The parameters must still be passed as a dictionary with the correct types and order. Buffer parameters must be passed as Array objects. Scalars must be passed as Python native float or int.

Warning: Only 1D buffers are supported for now.

Parameters:
  • anchor (str, default = '__file__') – Enter __file__ when calling this method and the corresponding open.cl file lies in the same folder as the python file calling it. Ignored if kernel_source is a string.

  • kernel_source (str) – Filename of the open.cl file to be called or string containing the open.cl source code

  • kernel_name (str) – Kernel method inside the open.cl file to be called most clij/clesperanto kernel functions have the same name as the file they are in

  • global_size (tuple (z,y,x), default = (1, 1, 1)) – Global_size according to OpenCL definition (usually shape of the destination image).

  • local_size (tuple (z,y,x), default = (1, 1, 1)) – Local_size according to OpenCL definition (usually default is good).

  • parameters (dict(str, [Array, float, int])) – Dictionary containing parameters. Take care: They must be of the right type and in the right order as specified in the open.cl file.

  • device (Device, default = None) – The device to execute the kernel on. If None, use the current device

operation(name: str) Callable[source]

Returns a function from the pyclesperanto package

Parameters:

name (str) – name of the operation

Return type:

Callable function

operations(must_have_categories: list = None, must_not_have_categories: list = None) dict[source]

Retrieve a dictionary of operations, which can be filtered by annotated categories.

Parameters:
  • must_have_categories (list of str, optional) – if provided, the result will be filtered so that operations must contain all given categories.

  • must_not_have_categories (list of str, optional) – if provided, the result will be filtered so that operations must not contain all given categories.

Returns:

dict of str

Return type:

Callable function

search_operation_names(name: str) list[source]

Returns a list of operation names containing the given string

Parameters:

name (str) – string to search for in operation names

Returns:

list of operation names containing the given string

Return type:

list