ZEISS Knowledge Base
Help
ZEISS Knowledge Base

Scripting and interaction with other programs

Segmenting objects into equal parts in arivis Pro

This guides goal is to guide the scientists in the workflow for segmenting objects into smaller equal parts and create 3D bounding-box objects surrounding them. The application note includes the steps to import the data and object to be segmented.

 

Download the Anaconda package

  1. Open the Anaconda web pages using the following link: https:/anaconda.org
  2. Select the Download Anaconda item
  3. Click on Download

    Note: The Individual Edition is Open source and freely distributable.
  4. Click on 64-bit Graphical Installer

    Note: The Individual Edition is Open source and freely distributable
  1. The download task starts.

Install the Anaconda package

  1. Open the Download folder and locate the Anaconda3 setup file.
  2. Run it and press the Next button on the setup dialog.

    Note: The Python release must be at least 3.8.
  3. Click on the I Agree button to accept the License Agreement terms.
  4. Select the Just Me option.
  5. Press the Next button to complete the installation.

Image Registration for Multiplexing Experiments in arivis Pro

How to: Align multiple 3D images based on the nuclei staining

This guides goal is to guide the user in the correct installation of the Anaconda3 Python package and the image registration workflow. This script will read multiple .czi image files (or SIS imagesets) in a given folder in a tile-wise manner and create the SIS files for each of the original files. During the registration process, the new SIS file will be created with each tile as a new imageset. The first cycle image will be copied from the original file and the image stacks from the following cycles will be registered to the first cycle image based on the indicated channel, typically, nuclei staining. In the last step, the Tile Sorter tool needs to be run to assemble the registered mosaic stack together. The resulting image can be used for the following image analysis.

Introduction

Image registration is the process of transforming different sets of data to overlay images from different experiments, taken at different times, positions or angles, or with different imaging modalities. The algorithm attempts to discover the matching areas and align them together. Image registration methods can be divided into two large groups: rigid and non-rigid transformations. For the multiplexing experiments, we will use the nuclei staining in each of the experiment cycles to register the subsequent experiments to the first image. This method is applicable both to 2D and 3D images.

The application workflow starts from importing the original image files (for example, CZI) in arivis Pro and registering the subsequent experimental cycles to the first one based on the indicated nuclei staining channel (i.e. DAPI or Hoechst). The images will be imported as a stack of individual tiles with all the channels from all the experiment cycles, each registered to the nuclei staining in the first experiment cycle. After the registration, the mosaic image should be stitched using the Tile Sorter tool.

The images used in this application note were published in https://www.sciencedirect.com/science/article/pii/S0165027022001807

Image registration in a nutshell

Image registration is the process of transforming different sets of data to overlay images from different experiments, taken at different times, positions or angles, or with different imaging modalities. The algorithm attempts to discover the matching areas and align them together. Image registration methods can be divided into two large groups: rigid and non-rigid transformations. For the multiplexing experiments, we will use the nuclei staining in each of the experiment cycles to register the subsequent experiments to the first image. This method is applicable both to 2D and 3D images.

The application workflow starts from importing the original image files (for example, CZI) in arivis Pro and registering the subsequent experimental cycles to the first one based on the indicated nuclei staining channel (i.e. DAPI or Hoechst). The images will be imported as a stack of individual tiles with all the channels from all the experiment cycles, each registered to the nuclei staining in the first experiment cycle.  After the registration, the mosaic image should be stitched using the Tile Sorter tool.

Preliminary Remarks

arivis Pro runs multiple applications (image registration) using external and independent Python libraries and tools produced by third parties. These tools must be installed by the user under its responsibility, strictly following the instruction on this document. arivis has tested the setup protocol on several computers, however, due to the different and not predictable hardware and software configuration of each computer, the results can be different case by case. Therefore, arivis declines any responsibility concerning the correct tools installation and setup on the user computer. arivis cannot be blamed about any malfunctioning or failure of the deep learning environment setup. arivis will not give technical support on the setup task. Both activities are totally on the user charge. arivis also declines any responsibility about the scientific results gathered from this application.

Installing the prerequisites

To use the registration script for multiplexed data in arivis Pro, we need 3 configuration steps:

  1. Install Anaconda Python.
  2. Import the registration environment.
  3. Configure the arivis Pro Scripting preferences to use the environment.

Setting up the image registration environment

Converting Cellpose models for use in arivis

How to use the Cellpose to ONNX script

First, download the script file here: Cellpose_to_onnx.py

Copy and paste the py file in the main folder of your cellpose python solution.

The script requires that the ONNX python libraries are installed. If these libraries are not yet installed, or you just want to make sure you have the latest:

  1. Open a cmd in the same folder as python.exe which your environment uses as its interpreter (this ensures that you are installing ONNX module for the correct env)
  2. Run pip install onnx to install ONNX module from official python packages

The script has two options:

  • Convert all models: look for built-in and custom models where Cellpose saves them. Any custom change in Cellpose behaviour (where the models are saved, for example) is not guaranteed to work with this option.
  • Convert individual model: convert single model at the time, the user must provide the model full path and a mean_diameter

Convert a single model

Command line: python cellpose_to_onnx.py --model_path [FULL_PATH_TO_THE_MODEL] --mean_diamter [30. or 17.]

  • The model could be anywhere
  • Use this if you are not using cellpose folder structure

Change the output location

The script automatically outputs the converted model to the same folder as the input. To change the output folder, where the ONNX models are saved we need to ad --output to the command line.

Command line: python cellpose_to_onnx.py --output_directory [DIRECTOY_TO_SAVE_ONNX_FILES]

Install Anaconda Python for Vision4D

This article provides instructions for installing and configuring Anaconda Python for Vision4D.

Introduction

Anaconda is a Python distribution that aims to simplify package management and deployment. Used in conjunction with the scripting module in arivis Vision4D it allows users to implement advanced image processing that may not be possible out of the box for Vision4D. Anaconda is necessary for a variety of scripts provided by arivis, including our StarDist and CellPose integrations, but is not normally needed except for advanced imaging workflows that use those libraries.

Users of Vision4D 3.3 or earlier should use the Anaconda 2 installation. Installation files for this can be found in the Anaconda archive. These configurations are no longer officially supported.

For all other users, the latest Anaconda release is recommended and can be found here.

Performing contrast limited adaptive histogram equalization (CLAHE)»

This guide explains how to apply the contrast limited adaptive histogram equalization (CLAHE) algorithm. The CLAHE algorithm partitions the images into contextual regions and applies the histogram equalization to each one. This evens out the distribution of used grey values and thus makes hidden features of the image more visible. The full grey spectrum is used to express the image. CLAHE is an improved version of AHE, or Adaptive Histogram Equalization. Both overcome the limitations of standard histogram equalization.

Loading the Python script

  1. Open Python Script Editor. From the Extra menu, select Script Editor.
  2. Load the Clahe_Rev5 (3_4).py Python Script.
  3. Browse the folder on which the file has been saved.

Python script code usage rights:The user has the permission to use, modify and distribute this code, as long as this copyright notice remains part of the code itself: Copyright(c) 2021 arivis AG, Germany. All Rights Reserved.

Setting the script features

Some Clahe algorithm options can be set to optimize the results:

  • INPUT_CHANNEL : Set the source channel to be equalized. NOTE: Only one channel can be processed.
  • OUTPUT_CH_CHANNEL : Set the output channel name.

The size used to compute the Clahe can be freely set.

  • CLAHE_CV2 = True : Set the OpenCV2 algorithm – False the Skimage one.
  • HISTO_STRETCH : With the CLAHE_CV2 = False sets the result stretching.
  • BLOCK_NUMBER_X : Sets the number of horizontal patches (tiles) used to compute the local equlization.
  • BLOCK_NUMBER_Y : Sets the number of vertical patches (tiles) used to compute the local equalization.
  • CLIP_LIMIT_CV2 : Sets the clipping limit, normalized between 0 and 100 (higher values give more contrast). It is applied to the OpenCv2 algorithm.
  • CLIP_LIMIT_SKIMAGE : Sets the clipping limit, normalized between 0 and 1 (higher values give more contrast). It is applied to the Skimage algorithm.
  • ACTIVE_FRAME : If True, the Clahe is applied only to the active time point.
  • ACTIVE_PLANE : If True, the Clahe is applied only to the active Z plane.

Installing the Anaconda3 package and the OpenCV module

The Anaconda3 Package and the OpenCV module are required to run the script. Please refer to the Application Note #20 for more details.

  1. Once the Anaconda3 package has been correctly installed, the OpenCV module can be installed too.
  1. From the Window menu, select the Anaconda Prompt.

  2. Type pip install opencv-python and press return.
  3. A message confirms the correct OpenCv installation.

Objects contacts analysis

This article describes how to perform the objects contacts analysis in arivis Vision4D.

Introduction

Identifying the contacts between adjacent objects belonging to the same TAG, is a complex task that requires to detect the space on which two objects edges are touching or overlapping each other. Objects can be in contact either sharing a single voxel rather than more volume.

The python script is available as stand alone code as well as operator.

Please Contact the arivis application support to know how to get either the stand alone script or the operator script.

The process to achive the contacts analysis is executed  as two separate processes:

  • Identifying the overlapping object bounding boxes
  • Verifying if the objects withing the touching bounding boxes are really in contact or overlapped.

Set and run the Script operator

Open the analysis panel (Pipeline workspace) using the "flask" icon on the main, top icon bar.

Add the Python Segment Modifier operator to the active pipeline. Chose it from the Add Operation list.

Select the ContactBetweenObjects_RevC(4_0)_OP.py python operator file from the folder on which it is stored. Click on the "3 dots" button to browser in your hard disk  and select the file.

Digit the objects TAG. The TAG must collect the objects to be analyzed.

NOTE: the TAG name is case sensitive.

Sets the «Refine_Contact» option ON

NOTE: A segmentation operator must come first the Python Segment Modifier one.

It creates the objects to be analyzing by contacts. If the script operator have to be executed on objects already segmented in a separated pipeline, it is necessary to import them in the active pipeline using the “Import Document Objects” operator.

Color Deconvolution

This article describes how to implement color deconvolution and un-mixing method for RGB images in arivis Vision4D.

Introduction

Color or RGB images are common in histopathology where bright-field images capture white light from which the diagnostic dyes absorb a certain portion of the spectrum. These images can be segmented in a range of ways, but a better separation of the signal components from the red, green, and blue channels can significantly improve segmentation results. This script is an implementation in Vision4D of the method developed by Ruifrok, A.C. & Johnston, D.A. as described here

This method has been developed specifically for the unmixing of diaminobenzidine, hematoxylin and eosin dies.

The output of the script is the creation of three additional channels to the current image set containing the unmixed signal.

This script relies on the NumPy libraries that are installed automatically with version 3.4 or above of arivis Vision4D. Earlier versions may require additional components.

Importing and editing the script

The script can be downloaded here. Once the ZIP file is decompressed the PY file can be loaded into the script editor.

Once opened the script will probably require some modifications for each specific usage.

Dye Selection

The script has been preconfigured for specific dye combinations. For the un-mixing to work, the correct combination must be selected. Immediately below the Input Channel settings, you'll find the STAINING settings.

# -------------------------------------------------------------------------

# 0 == HEMA_DAB

# 1 == HEMA_EOSIN

# 2 == HEMA_EOSIN2

# 3 == FEULGEN_LGRENN

# 4 == HEMA_EOSIN_DAB

# 5 == GIEMSA

# 6 == Fast Red, Fast Blue and DAB

# 7 == Methyl green and DAB

# 8 == Haematoxylin, Eosin and DAB (H&E DAB)

# 9 == Haematoxylin and AEC (H AEC)

# 10 == Azan-Mallory

# 11 == Alcian blue & Haematoxylin

# 12 == MASSON THRICROME

# 13 == Haematoxylin and Periodic Acid of Schiff (PAS)

# -------------------------------------------------------------------------

STAINING = 0

Simply replace the number after the "STAINING = " to match your image. For example, if using Hematoxylin and Eosin (H&E), the line should then read:

STAINING = 1

Interpreting the results

The output of the script is three additional channels in the source image sets. These channels are named for the dye signal that has been extracted and can be used in any pipeline as any regular image channel for segmentation etc. In cases of dual staining (e.g. H&E), the third channel essentially contains only the signal that could not be reliably attached to either of the other two. this means that this third channel can essentially be used as some form of quality control for the output since in a perfect deconvolution this third channel would ideally be empty. If there is still a strong signal in the third channel this usually indicates that the deconvolution parameters do not perfectly match  the staining in the image. This could be caused by white balancing issues or extreme staining (either too weak or too strong). 

For more information on the process of the deconvolution, please refer to the published literature on which this is based, linked above.

Conclusions

Once the script has been run, pipelines can be created as per usual that can use the newly created channel for segmentation or any additional modification, just like any other image channel. 

Support for this script can be obtained by logging a support ticket using the link at the top of this page.

A more detailed description of the script functionality and editing can be found here.

 

Download the script

Download the script for arivis Vision4D 3.3/3.4 here (may work with earlier versions but has been tested in 3.3 and 3.4).

Download the script for version 3.5 and above here.

Creating XYZ matrix of sub-volumes

This guide explains how to create a sampling volume (ROI) as a XYZ matrix of boxes. The application uses a Python script to create single or contiguous sub-regions that can be used as ROI for further analysis. The unique limit is related to the sampling volume shape. Only regular 3D boxes are available.

Opening the working dataset

  1. Select Open... from the file menu.
  2. Select the dataset from the file browser.
    The dataset is a multi dimensional, discrete, representation of your real sample volume. It can be structured as a Z series of planes (Optical sectioning) of multiple channels (dyes) in a temporal sequence of time points (located in several spatial positions).​
    Usually, the dataset shows a single experimental situation (a complete experiment can be composed by several datasets). The datasets are available as graphic files saved in plenty of file formats (standard formats as well as proprietary formats)​.
    Note: The dataset is visualized according to the current rendering setting parameters. Refer to the arivis Pro Help for more details.

Loading the Python script

  1. Open Python Script Editor. From the Extra menu, select Script Editor.
  2. Load the Divide_Scope Python Script.
    Note: The script name can change according to the new version released. The latest script is: DivideScope RevE (3_4).py.
  3. Browse the folder on which the file has been saved.

Python script code usage rights:The user has the permission to use, modify and distribute this code, as long as this copyright notice remains part of the code itself: Copyright(c) 2021 arivis AG, Germany. All Rights Reserved.

Setting the script features

In order to define the contiguous sub-regions (sampling volume) features, few parameters of the script should be adjusted to match your analysis needs. These parameters are located in the code area labeled as USER SETTING.

Only the parameters located in the USER SETTING area can be modified. Don’t change any other number, definition or text in the code outside this dedicated area.

  • SIZE_BOX_X = the X axis size of each box . The value is expressed in µm.
  • SIZE_BOX_Y = the Y axis size of each box . The value is expressed in µm.
  • SIZE_BOX_Z = the Z axis size of each box . The value is expressed in µm.

  • PRESERVE_EDGES = This option sets the boxes touching / non touching feature. If TRUE, the boxes edges are not contiguous to each other (2 pixels space in between).
    Note: The volume sizes (XYZ) are divided by the single box XYZ size. The integer number of boxes fitting in the volume is computed. It may happen that the boxes don't cover the whole sample volume.

  • TAG_SEGMENTS = defines the segments TAG to be used to compute the boxes. It is used as alternative of the standard method (whole volume). If empty, the default method (whole volume) is used.
  • TAG_BOXES = defines the TAG assigned to the created boxes.
  • TAG_SEGMENTS = “”
  • TAG_SEGMENTS = “Manual”

    Note: If the TAG_SEGMENTS is set to an existing TAG, all the objects belonging to it are used to create the boxes matrix. Specifically, the bounding box volume of each object is taken as the reference volume that is divided into boxes.

Creating Heat-Map – density distribution

This guide explains how to create a density distribution map, also called ”Heat-Map”. The script generates contiguous boxes in X,Y and Z directions that can be used as ROIs for further analysis (Compartmentalization, gradient distribution, etc.)

Opening the working dataset

  1. Select Open... from the file menu.
  2. Select the dataset from the file browser.
    The dataset is a multi dimensional, discrete, representation of your real sample volume. It can be structured as a Z series of planes (Optical sectioning) of multiple channels (dyes) in a temporal sequence of time points (located in several spatial positions).​
    Usually, the dataset shows a single experimental situation (a complete experiment can be composed by several datasets). The datasets are available as graphic files saved in plenty of file formats (standard formats as well as proprietary formats)​.
    Note: The dataset is visualized according to the current rendering setting parameters. Refer to the arivis Pro Help for more details.

Loading the Python script

  1. Open Python Script Editor. From the Extra menu, select Script Editor.
  2. Load the Divide_Scope Python Script.
    Note: The script name can change according to the new version released. The latest script is: DivideScope RevE (3_4).py.
  3. Browse the folder on which the file has been saved.

Python script code usage rights:The user has the permission to use, modify and distribute this code, as long as this copyright notice remains part of the code itself: Copyright(c) 2021 arivis AG, Germany. All Rights Reserved.

Set the Script features

In order to define the contigues sub-regions (sampling volume) features, some parameters of the script should be adjusted to match your analysis needs. These parameters are located in the code area labeled as USER SETTING.

SIZE_BOX_X : Set the X sub-volume size.

SIZE_BOX_Y : Set the Y sub-volume size.

SIZE_BOX_Z : Set the Z sub-volume size.

All the values are expressed in metric units (µm).

If one of the box dimensions is bigger than the correspondent volume size, the script will not be executed and an error message is issued.

Only the parameters located in the USER SETTING area can be modified. Don’t change any other number, definition or text in the code outside this dedicated area.

Running the Python script

Run the DivideScope RevE (3_4) Python Script by pressing the Run Script button or pressing the F5 key.

Note: Activate the Output Panel, if not already displayed. The status of the script execution (errors including) will be visualized here.

This is the script result, a 3D matrix of sub-volumes:

The sub-volumes segments are shown in the objects table using the TAG Script.

Viewing the results

Results (segments and measurements) will be stored in the dataset only if the Store Objects operator has been correctly set. Tick appropriately the option as shown below before complete the pipeline execution.

  1. Open the data table if not already visible.
  2. Measurements are now visible in the data table​.

    Note: The spots count in the single sub-region is shown in the data table.​ The empty sub-regions are not listed.​ To get the total spots count the group statistic feature must be used.

Features can be added or removed from the data table using the Feature Column command.

Creating freely XY oriented sub volumes

This guide explains how to create a sampling volume (ROI) freely oriented along X and Y axis.

The application uses a Python script to create single or contiguous sub-regions that can be used as ROI for further analysis. 

Running the Python script

Run the Free-Oriented Sub-volume Python Script by pressing the Run Script button or pressing the F5 key.

Note: Activate the Output Panel, if not already displayed. The status of the script execution (errors including) will be visualized here.

Creating concentric sub volume - matryoshka dolls

This guide explains how to create concentric objects based on the source segments shape, from the outside to the inside. The concentric shapes can be used as ROIs for further analysis (Compartmentalization, gradient distribution, heat map, etc.).

Loading the Python script

  1. Open Python Script Editor. From the Extra menu, select Script Editor.
  2. Load the Matryoshka_doll_revxx Python Script.
  3. Browse the folder on which the file has been saved.

Python script code usage rights:The user has the permission to use, modify and distribute this code, as long as this copyright notice remains part of the code itself: Copyright(c) 2021 arivis AG, Germany. All Rights Reserved.

Running the Python script

Run the Matryoshka_doll_revxx Python Script by pressing the Run Script button or by pressing the F5 key.

Activate the Output Panel, if not already displayed. The status of the script execution (errors including) will be visualized here.

Creating spiral oriented sub volume»

This guide explains how to create spiral based boxes.

The boxes can be used as ROIs for further analysis (Compartmentalization, gradient distribution, heat map, etcetera)

Opening the working dataset

  1. Select Open... from the file menu.
  2. Select the dataset from the file browser.
    The dataset is a multi dimensional, discrete, representation of your real sample volume. It can be structured as a Z series of planes (Optical sectioning) of multiple channels (dyes) in a temporal sequence of time points (located in several spatial positions).​
    Usually, the dataset shows a single experimental situation (a complete experiment can be composed by several datasets). The datasets are available as graphic files saved in plenty of file formats (standard formats as well as proprietary formats)​.
    Note: The dataset is visualized according to the current rendering setting parameters. Refer to the arivis Pro Help for more details.

Loading the Python script

  1. Open Python Script Editor. From the Extra menu, select Script Editor.
  2. Load the Free-Oriented Sub-volume Python Script.
  3. Browse the folder on which the file has been saved.
Python script code overview
Python script code overview

Only the parameters located in the USER SETTING area can be modified. Don’t change any other number, definition or text in the code outside this dedicated area.

Setting the script features

  1. In order to define the spiral distributed sub-regions (sampling volume) features, some parameters of the script should be adjusted to match your analysis needs. These parameters are located in the code area labeled as USER SETTING.
  1. Set the Z planes range.
    FIRST_PLANE defines the lower Z plane of the sub-regions ROI.
    LAST_PLANE defines the higher Z plane of the sub-regions ROI.
    The values of -1 set the Z planes range equal to the whole volume depth (total number of Z Planes available).
  2. STEP_ANGLE defines the step size in degrees. The boxes will be positioned on the spiral curve every STEP_ANGLE.
  3. SPIRAL_LOOP defines the number of loops (concentric spirals). Any single loop is a complete 360° spiral. Values less than 1.0 draw a partial spiral.

  4. COEFFICENT_B is the coefficient used to define the distance between the loops of the concentric spiral.

  5. BOX_HEIGHT sets the height of the boxes (Y).
    BOX_WIDTH sets the width of the boxes (X).
    Both are expressed in pixels.

Set the distance of the loops and their numbers according to the size of the boxes. Wrong parameters setting can make the boxes overlap, especially inside the inner part of the spiral.

Running the Python script

Run the Spiral Oriented Sub Volume Python Script by pressing the Run Script button or pressing the F5 key.

Note: Activate the Output Panel, if not already displayed. The status of the script execution (errors including) will be visualized here.

Running the analysis Pipeline

The pipeline can be executed step by step (back and forth). This method allows to run and undo a single Operation. Either the arrow buttons or the Operation list can be used to go through the operators list.

  1. Run the single operator.
  2. Optional: Undo the single operator.

    Note: Undo the last operator executed if you need to change the operator settings.
  3. Run the whole pipeline with no pauses.
  4. Optional: Stop the pipeline execution.

This icon, located on the right side of the operator title bar, shows the operator status.

Task running:

Task completed:

Viewing the results

  1. Results (segments and measurements) will be stored in the dataset only if the Store Objects operator has been correctly set. Tick appropriately the option as shown below before complete the pipeline execution.
  1. Open the data table if not already visible.
  2. Measurements are now visible in the data table​.

    Note: The spots count in the single sub-region is shown in the data table.​ The empty sub-regions are not listed.​ To get the total spots count the group statistic feature must be used. ​

Features can be added or removed from the data table using the Feature Column command.

Impressum
Carl-Zeiss-Strasse 22
73447 Oberkochen
Germany
Legal