Skip to content

Latest commit

History

1,676 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Nyxus

Documentation StatusPyPIPyPI DownloadsCondaConda Downloads

Scalable Python library for calculating engineered geometric features from segmented and whole-slide images and volumes

Overview

Nyxus is a feature-rich, optimized, Python/C++ application capable of analyzing images of arbitrary size and assembling complex regions of interest (ROIs) split across multiple image tiles and files. This accomplished through multi-threaded tile prefetching and a three phase analysis pipeline shown below.

Nyxus can be used via Python or command line and is available in containerized form for reproducible execution. Nyxus computes over 450 combined intensity, texture, and morphological features at the ROI or whole image level with more in development. Key features that make Nyxus unique among other image feature extraction applications is its ability to operate at any scale, its highly validated algorithms, and its modular nature that makes the addition of new features straightforward.

Currently, Nyxus can read 2D image data from OME-TIFF, OME-Zarr, and DICOM 2D Grayscale images. Nyxus also reads compressed and uncompressed NIFTI 3D files. Nyxus Python API supports featurizing in-memory 2D image data represented by NumPy arrays.

The docs can be found at Read the Docs.

Getting started

For use in python, the latest version of Nyxus can be installed via the Pip package manager or Conda package manager:

pip install nyxus

or

conda install nyxus -c conda-forge

Usage

The library provides class Nyxus for 2-dimensional TIFF, OME.TIFF, OME.ZARR, and DICOM slides and intensity-mask slide pairs, and class Nyxus3D for NIFTI volumes and intensity-volume volume pairs. Additionally to a single-file representation, a volume can be represented by its z-slices residing in separate 2-dimensional TIFF or ONE.TIFF slides (so called "layout A"). Slides and volumes can be featurized as all the files in a directory filtered with a file pattern passed specified. Alternatively, explicit file name pairs and pair lists can be featurized. Alternatively, 2D and 3D NumPy arrays can be featurized.

2D usage

Given intensities and labels folders, Nyxus pairs up intensity-segmentation mask images and extracts features from all of them. A summary of the available feature are listed below.

featurizing data in file system directories

fromnyxusimportNyxusnyx=Nyxus (["*ALL*"])
intensityDir="/path/to/images/intensities/"maskDir="/path/to/images/labels/"features=nyx.featurize_directory (intensityDir, maskDir) # selecting all the .ome.tif slides (default)

featurizing explicitly defined lists of files

Alternatively, Nyxus can process explicitly defined pairs of intensity-mask images thus specifying custom 1:N and M:N mapping between segmentation mask and intensity image files. The following example extracts all the features (note parameter "ALL") from intensity images 'i1', 'i2', and 'i3' related with mask images 'm1' and 'm2' via a custom mapping:

fromnyxusimportNyxusnyx=Nyxus (["*ALL*"])
features=nyx.featurize_files(
[
"/path/to/images/intensities/i1.ome.tif", "/path/to/images/intensities/i2.ome.tif",
"/path/to/images/intensities/i3.ome.tif" ], [
"/path/to/images/labels/m1.ome.tif", "/path/to/images/labels/m2.ome.tif",
"/path/to/images/labels/m2.ome.tif"
],
False) # pass True to featurize intensity files as whole segments

The result variable features is a Pandas dataframe similar to what is shown below. Note that if multiple segments are stored in a segmentation mask file, each segment's features in the resultcan be identified by the mask file name and segment mask label.

mask_imageintensity_imagelabelMEANMEDIAN...GABOR_6
0p1_y2_r51_c0.ome.tifp1_y2_r51_c0.ome.tif145366.946887...0.873016
1p1_y2_r51_c0.ome.tifp1_y2_r51_c0.ome.tif227122.827124.5...1.000000
2p1_y2_r51_c0.ome.tifp1_y2_r51_c0.ome.tif334777.433659...0.942857
3p1_y2_r51_c0.ome.tifp1_y2_r51_c0.ome.tif435808.236924...0.824074
4p1_y2_r51_c0.ome.tifp1_y2_r51_c0.ome.tif536739.737798...0.854067
........................
734p5_y0_r51_c0.ome.tifp5_y0_r51_c0.ome.tif22354573.354573.3...0.980769

featurizing in-memory 2D images; featurizing a montage

Nyxus can also featurize in-memory intensity-mask pairs that are loaded as NumPy arrays using the featurize method. This method takes in either a single pair of 2D intensity-mask pairs or a pair of 3D arrays containing 2D intensity and mask images. There is also two optional parameters to supply names to the resulting dataframe, .

fromnyxusimportNyxusimportnumpyasnpnyx=Nyxus (["*ALL*"])
intens=np.array([
[[1, 4, 4, 1, 1],
[1, 4, 6, 1, 1],
[4, 1, 6, 4, 1],
[4, 4, 6, 4, 1]],
])
seg=np.array([
[[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[0, 1, 1, 1, 1],
[1, 1, 1, 1, 1]]
])
features=nyx.featurize(intens, seg)

Note: if array intens contains negative values similarly to intensities in Hounsfeld units observed in CT-scan datasets, method featurize() automatically adjusts values of of array intens while passing them to Nyxus backend so as to make them zero-based, like in the following example:

import numpy as np
import nyxus
I = np.array([
[-1024.74, -1019.67, -1005.70, -998.60, -998.66, -1005.82, -1019.65, -1024.72],
[-1019.44, -1001.22, -1023.82, -1034.34, -1035.81, -1027.00, -1001.89, -1019.62],
[-1011.86, -1002.17, -724.06, -521.43, -471.04, -671.30, -1006.98, -1010.62],
[-1008.78, -703.58, 21.66, 44.32, 130.35, 113.37, -608.11, -1056.33],
[-415.46, -106.08, 69.80, 59.70, 97.64, 120.62, -49.77, -480.57],
[-464.06, -176.81, 76.79, 93.34, 131.99, 73.16, -106.70, -348.06],
[-1012.75, -740.21, -502.72, -370.36, -377.42, -497.65, -719.82, -1000.82],
[-1032.57, -979.63, -867.71, -815.30, -830.90, -875.08, -983.76, -1033.78]], np.float64)
M = np.array([
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]], np.uint16)
nyx = nyxus.Nyxus (["*ALL_INTENSITY*"])
f = nyx.featurize (I, M, intensity_names=['I'], label_names=['M'])

The features variable is a Pandas dataframe similar to what is shown below.

mask_imageintensity_imagelabelMEANMEDIAN...GABOR_6
0Segmentation1Intensity1145366.946887...0.873016
1Segmentation1Intensity1227122.827124.5...1.000000
2Segmentation1Intensity1334777.433659...0.942857
3Segmentation1Intensity1435808.236924...0.824074
........................
14Segmentation2Intensity2654573.354573.3...0.980769

Note that in this case, default names of virtual image files were provided for the mask_image and intensity_image columns. To override default names 'Intensity' and 'Segmentation' appearing in these columns, the optional arguments intensity_names and label_names are used by passing lists of names in. The length of the lists must be the same as the length of the mask and intensity arrays. The following example sets mask and intensity images in the output to desired values:

intens_names= ['int1', 'int2']
seg_names= ['seg1', 'seg2']
features=nyx.featurize(intens, seg, intens_name, seg_name)

The features variable will now use the custom names, as shown below

mask_imageintensity_imagelabelMEANMEDIAN...GABOR_6
0seg1int1145366.946887...0.873016
1seg1int1227122.827124.5...1.000000
2seg1int1334777.433659...0.942857
3seg1int1435808.236924...0.824074
........................
14seg2int2654573.354573.3...0.980769

3D usage

Featurizing a directory of volume files is similar to the 2D case except class Nyxus3D should be used, and the "all" feature group nickname string should be passed as "3D_ALL":

importnyxusnyx=nyxus.Nyxus3D (["*3D_ALL*"])
# datasetidir="/dataset1/input"mdir="/dataset1/masks"# selecting only uncompressed NIFTI filesfeatures1=nyx.featurize_directory (idir, mdir, file_pattern=".*\.nii")
# selecting only compressed NIFTI filesfeatures2=nyx.featurize_directory (idir, mdir, file_pattern=".*\.nii\.gz")

Note on CT datasets: voxel intensities recorded in the Hounsfield units are automatically read by Nyxus as 0-based values by adding the minimum value of an original file (typically -1024).

Featurizing explicitly specified volume files is straightforward, too:

importnyxusnyx=nyxus.Nyxus3D (["*3D_ALL*"])
idir= [
"/patient123/mri.nii.gz", "/patient123/mri.nii.gz", "/patient123/mri.nii.gz"]
mdir= [
"/patient123/segmentation/kidney_right.nii.gz", "/patient123/segmentation/liver.nii.gz", "/patient123/segmentation/kidney_left.nii.gz"]
nyx.featurize_files (idir, mdir, False) # pass True to featurize intensity files as whole segments

Whole-slide and whole-volume feature extraction

Nyxus provides dedicated workflows for extracting features from whole 2D slides and volumes. The workflows scale across CPU cores as controlled by constructor parameter n_feature_calc_threads of classes Nyxus and Nyxus3D.

Example -- whole-slide featurization with 4 threads:

dir = "/2d_dataset/intensity"
import nyxus
nyx = nyxus.Nyxus (features=["*WHOLESLIDE*"], n_feature_calc_threads=4)
f = nyx.featurize_directory (intensity_dir=dir, label_dir=dir)

Note: feature group *WHOLESLIDE* but not *ALL* is used to avoid calculation of shape features meaningless in case of the trivial rectangular shape of unsegmented slides. particularly, group *WHOLESLIDE* disables the time-consuming group GLDZM, basic morphology features (AREA_PIXELS_COUNT, AREA_UM2, ASPECT_RATIO, BBOX_XMIN, BBOX_YMIN, BBOX_WIDTH, BBOX_HEIGHT, CENTROID_X, CENTROID_Y, COMPACTNESS, DIAMETER_EQUAL_AREA, EXTENT, MASS_DISPLACEMENT, WEIGHTED_CENTROID_X, WEIGHTED_CENTROID_Y), enclosing/inscribing/circumscribing circle features, convex hull based features (CONVEX_HULL_AREA, SOLIDITY, CIRCULARITY, POLYGONALITY_AVE, HEXAGONALITY_AVE, HEXAGONALITY_STDDEV), fractal dimension features, geodetic features, ROI neighbor features, ROI radius features, ellipse fitting features, extrema features, morphological erosion features, Caliper and chords features.

Disabled features can be requested by explicitly specifying them, for example enforcing calculation of the grey level distance zone matrix based (GLDZM) features:

dir = "/2d_dataset/intensity"
import nyxus
nyx = nyxus.Nyxus (features=["*WHOLESLIDE*", "*ALL_GLDZM*"], n_feature_calc_threads=4)
f = nyx.featurize_directory (intensity_dir=dir, label_dir=dir)

Further steps

For more information on all of the available options and features, check out the documentation.

Nyxus can also be built from source and used from the command line, or via a pre-built Docker container.

Getting and setting parameters of Nyxus

All parameters to configure Nyxus are available to set within the constructor. These parameters can also be updated after the object is created using the set_params method. This method takes in keyword arguments where the key is a valid parameter in Nyxus and the value is the updated value for the parameter. For example, to update the coarse_gray_depth to 256 and the gabor_f0 parameter to 0.1, the following can be done:

fromnyxusimportNyxusnyx=Nyxus(["*ALL*"])
intensityDir="/path/to/images/intensities/"maskDir="/path/to/images/labels/"features=nyx.featurize_directory (intensityDir, maskDir)
nyx.set_params(coarse_gray_depth=256, gabor_f0=0.1)

A list of valid parameters is included in the documentation for this method.

To get the values of the parameters in Nyxus, the get_params method is used. If no arguments are passed to this function, then a dictionary mapping all of the variable names to the respective value is returned. For example,

fromnyxusimportNyxusnyx=Nyxus(["*ALL*"])
intensityDir="/path/to/images/intensities/"maskDir="/path/to/images/labels/"features=nyx.featurize_directory (intensityDir, maskDir)
print(nyx.get_params())

will print the dictionary

{'coarse_gray_depth': 256, 'features': ['*ALL*'], 'gabor_f0': 0.1, 'gabor_freqs': [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0], 'gabor_gamma': 0.1, 'gabor_kersize': 16, 'gabor_sig2lam': 0.8, 'gabor_theta': 45.0, 'gabor_thold': 0.025, 'ibsi': 0, 'n_loader_threads': 1, 'n_feature_calc_threads': 4, 'neighbor_distance': 5, 'pixels_per_micron': 1.0}

There is also the option to pass arguments to this function to only receive a subset of parameter values. The arguments should be valid parameter names as string, separated by commas. For example,

fromnyxusimportNyxusnyx=Nyxus(["*ALL*"])
intensityDir="/path/to/images/intensities/"maskDir="/path/to/images/labels/"features=nyx.featurize_directory (intensityDir, maskDir)
print(nyx.get_params('coarse_gray_depth', 'features', 'gabor_f0'))

will print the dictionary

{ 'coarse_gray_depth': 256, 'features': ['*ALL*'], 'gabor_f0': 0.1 }

Using Arrow for feature results

Nyxus provides the ability to get the results of the feature calculations in Arrow IPC and Parquet formats.

To create an Arrow IPC or Parquet file, use output_type="arrowipc" or output_type="parquet" in Nyxus.featurize* calls. Optionally, an output_path argument can be passed to specify the location of the output file. For example,

fromnyxusimportNyxusimportnumpyasnpintens=np.array([
[[1, 4, 4, 1, 1],
[1, 4, 6, 1, 1],
[4, 1, 6, 4, 1],
[4, 4, 6, 4, 1]],
[[1, 4, 4, 1, 1],
[1, 1, 6, 1, 1],
[1, 1, 3, 1, 1],
[4, 4, 6, 1, 1]],
[[1, 4, 4, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 6, 1, 1],
[1, 1, 6, 1, 1]],
[[1, 4, 4, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 6, 1, 1]],
])
seg=np.array([
[[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]],
[[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[0, 1, 1, 1, 1],
[1, 1, 1, 1, 1]],
[[1, 1, 1, 0, 0],
[1, 1, 1, 1, 1],
[1, 1, 0, 1, 1],
[1, 1, 1, 1, 1]],
[[1, 1, 1, 0, 0],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]]
])
nyx=Nyxus(["*ALL_INTENSITY*"])
arrow_file=nyx.featurize(intens, seg, output_type="arrowipc", output_path="some_path")
print(arrow_file)

The output is:

 NyxusFeatures.arrow

This functionality is also available in the through the command line using the flag --outputType. If this flag is set to --outputType=arrowipc then the results will be written to an Arrow IPC file in the output directory and --outputType=parquet will write to a Parquet file.

Available 2D features

The feature extraction plugin extracts morphology and intensity based features from pairs of intensity/binary mask images and produces a csv file output. The input image should be in tiled OME TIFF format. The plugin extracts the following features:

Nyxus provides a set of pixel intensity, morphology, texture, intensity distribution features, digital filter based features and image moments


Nyxus feature codeDescription
INTEGRATED_INTENSITYIntegrated intensity of the region of interest (ROI)
MEAN, MAX, MEDIAN, STANDARD_DEVIATION, MODEMean/max/median/stddev/mode intensity value of the ROI
SKEWNESS, KURTOSIS, HYPERSKEWNESS, HYPERFLATNESShigher standardized moments
MEAN_ABSOLUTE_DEVIATIONMean absolute deviation
ENERGYROI energy
ROOT_MEAN_SQUAREDRoot of mean squared deviation
ENTROPYROI entropy - a measure of the amount of information in the ROI
UNIFORMITYUniformity - measures how uniform the distribution of ROI intensities is
UNIFORMITY_PIUPercent image uniformity, another measure of intensity distribution uniformity
P01, P10, P25, P75, P90, P991%, 10%, 25%, 75%, 90%, and 99% percentiles of intensity distribution
INTERQUARTILE_RANGEDistribution's interquartile range
ROBUST_MEAN_ABSOLUTE_DEVIATIONRobust mean absolute deviation
MASS_DISPLACEMENTROI mass displacement
AREA_PIXELS_COUNTROI area in the number of pixels
COMPACTNESSMean squared distance of the object’s pixels from the centroid divided by the area
BBOX_YMINY-position and size of the smallest axis-aligned box containing the ROI
BBOX_XMINX-position and size of the smallest axis-aligned box containing the ROI
BBOX_HEIGHTHeight of the smallest axis-aligned box containing the ROI
BBOX_WIDTHWidth of the smallest axis-aligned box containing the ROI
MAJOR/MINOR_AXIS_LENGTH, ECCENTRICITY, ORIENTATION, ROUNDNESSInertia ellipse features
NUM_NEIGHBORS, PERCENT_TOUCHINGThe number of neighbors bordering the ROI's perimeter and related neighbor methods
EXTENTProportion of the pixels in the bounding box that are also in the region
CONVEX_HULL_AREAArea of ROI's convex hull
SOLIDITYRatio of pixels in the ROI common with its convex hull image
PERIMETERNumber of pixels in ROI's contour
EQUIVALENT_DIAMETERDiameter of the circle having circumference equal to the ROI's perimeter
EDGE_MEAN/MAX/MIN/STDDEV_INTENSITYIntensity statistics of ROI's contour pixels
CIRCULARITYRepresents how similar a shape is to circle. Clculated based on ROI's area and its convex perimeter
EROSIONS_2_VANISHNumber of erosion operations for a ROI to vanish in its axis aligned bounding box
EROSIONS_2_VANISH_COMPLEMENTNumber of erosion operations for a ROI to vanish in its convex hull
FRACT_DIM_BOXCOUNT, FRACT_DIM_PERIMETERFractal dimension features
GLCMGrey level co-occurrence Matrix features
GLRLMGrey level run-length matrix based features
GLDZMGrey level distance zone matrix based features
GLSZMGrey level size zone matrix based features
GLDMGrey level dependency matrix based features
NGTDMNeighbouring grey tone difference matrix features
ZERNIKE2D, FRAC_AT_D, RADIAL_CV, MEAN_FRACRadial distribution features
GABORA set of Gabor filters of varying frequencies and orientations

For the complete list of features see Nyxus provided features

2D feature groups

Apart from defining your feature set by explicitly specifying comma-separated feature code, Nyxus lets a user specify popular feature groups. Supported feature groups are:


Group codeBelonging features
*all_intensity*integrated_intensity, mean, median, min, max, range, standard_deviation, standard_error, uniformity, skewness, kurtosis, hyperskewness, hyperflatness, mean_absolute_deviation, energy, root_mean_squared, entropy, mode, uniformity, p01, p10, p25, p75, p90, p99, interquartile_range, robust_mean_absolute_deviation, mass_displacement
*all_morphology*area_pixels_count, area_um2, centroid_x, centroid_y, weighted_centroid_y, weighted_centroid_x, compactness, bbox_ymin, bbox_xmin, bbox_height, bbox_width, major_axis_length, minor_axis_length, eccentricity, orientation, num_neighbors, extent, aspect_ratio, equivalent_diameter, convex_hull_area, solidity, perimeter, edge_mean_intensity, edge_stddev_intensity, edge_max_intensity, edge_min_intensity, circularity
*basic_morphology*area_pixels_count, area_um2, centroid_x, centroid_y, bbox_ymin, bbox_xmin, bbox_height, bbox_width
*geomoms*shape and intensity geometric moments, equivalent to *igeomoms* and *sgeomoms* combined
*igeomoms*intensity raw moments IMOM_RM_pq, central moments IMOM_CM_pq, normalized raw moments IMOM_NRM_pq, normalized central moments IMOM_NCM_pq, Hu invariants IMOM_HUk, weighted raw moments IMOM_WRM_pq, weighted central moments IMOM_WCM_pq, weighted normalized central moments IMOM_WNCM_pq, weighted Hu invariants IMOM_WHUk
*sgeomoms*shape raw moments SPAT_MOMENT_pq, central moments CENTRAL_MOMENT_pq, normalized raw moments NORM_SPAT_MOMENT_pq, normalized central moments NORM_CENTRAL_MOMENT_pq, Hu invariants HU_Mk, weighted raw moments WEIGHTED_SPAT_MOMENT_pq, weighted central moments WEIGHTED_CENTRAL_MOMENT_pq, weighted normalized central moments WT_NORM_CTR_MOM_pq, weighted Hu invariants WEIGHTED_HU_Mk
*all_glcm*glcm_asm, glcm_acor, glcm_cluprom, glcm_clushade, glcm_clutend, glcm_contrast, glcm_correlation, glcm_difave, glcm_difentro, glcm_difvar, glcm_dis, glcm_energy, glcm_entropy, glcm_hom1, glcm_hom2, glcm_id, glcm_idn, glcm_idm, glcm_idmn, glcm_infomeas1, glcm_infomeas2, glcm_iv, glcm_jave, glcm_je, glcm_jmax, glcm_jvar, glcm_sumaverage, glcm_sumentropy, glcm_sumvariance, glcm_variance
*all_glrlm*glrlm_sre, glrlm_lre, glrlm_gln, glrlm_glnn, glrlm_rln, glrlm_rlnn, glrlm_rp, glrlm_glv, glrlm_rv, glrlm_re, glrlm_lglre, glrlm_hglre, glrlm_srlgle, glrlm_srhgle, glrlm_lrlgle, glrlm_lrhgle
*all_glszm*glszm_sae, glszm_lae, glszm_gln, glszm_glnn, glszm_szn, glszm_sznn, glszm_zp, glszm_glv, glszm_zv, glszm_ze, glszm_lglze, glszm_hglze, glszm_salgle, glszm_sahgle, glszm_lalgle, glszm_lahgle
*all_gldm*gldm_sde, gldm_lde, gldm_gln, gldm_dn, gldm_dnn, gldm_glv, gldm_dv, gldm_de, gldm_lgle, gldm_hgle, gldm_sdlgle, gldm_sdhgle, gldm_ldlgle, gldm_ldhgle
*all_ngtdm*ngtdm_coarseness, ngtdm_contrast, ngtdm_busyness, ngtdm_complexity, ngtdm_strength
*wholeslide*Only features relevant to the whole-slides whose single ROIs match the images themselves, except shape features meaningless in the whole-slide use case and certain time-consuming texture features (GLDZM features).
*all*All the features

Available 3D features


Nyxus feature codeDescription
Intensity
3COVCoefficient of variation
3COVERED_IMAGE_INTENSITY_RANGECovered image intensity range
3ENERGYEnergy
3ENTROPYEntropy
3EXCESS_KURTOSISExcess kurtosis
3HYPERFLATNESSHyperflatness
3HYPERSKEWNESSHyperskewness
3INTEGRATED_INTENSITYIntegrated intensity
3INTERQUARTILE_RANGEInterquartile range
3KURTOSISKurtosis
3MAXMax
3MEANMean
3MEAN_ABSOLUTE_DEVIATIONMean absolute deviation
3MEDIANMedian
3MEDIAN_ABSOLUTE_DEVIATIONMedian absolute deviation
3MINMin
3MODEMode
3P01, 3P10, 3P25, 3P75, 3P90, 3P991%, 10%, 25%, 75%, 90%, 99% percentiles
3QCODQuantile coefficient of dispersion
3RANGERange
3ROBUST_MEANRobust mean
3ROBUST_MEAN_ABSOLUTE_DEVIATIONRobust mean absolute deviation
3ROOT_MEAN_SQUAREDRoot mean squared
3SKEWNESSSkewness
3STANDARD_DEVIATIONStandard deviation
3STANDARD_DEVIATION_BIASEDBiased standard deviation
3STANDARD_ERRORStandard error
3UNIFORMITYUniformity
3UNIFORMITY_PIUUniformity in PIU units
3VARIANCEVariance
3VARIANCE_BIASEDBiased variance
shape
3AREASurface area
3AREA_2_VOLUMESurface area to volume ratio
3COMPACTNESS1Compactness1
3COMPACTNESS2Compactness2
3MESH_VOLUMEMesh volume
3SPHERICAL_DISPROPORTIONSpherical disproportion
3SPHERICITYSphericity
3VOLUME_CONVEXHULLVolume of the convex hull
3VOXEL_VOLUMEVolume as total of volumes of voxels
3MAJOR_AXIS_LENMajor axis length
3MINOR_AXIS_LENMinor axis length
3LEAST_AXIS_LENLeast axis length
3ELONGATIONElongation
3FLATNESSFlatness
texture
3GLCM_ACORAutocorrelation (grey level co-occurrence matrix)
3GLCM_ASMAngular second moment (grey level co-occurrence matrix)
3GLCM_CLUPROMCluster prominence (grey level co-occurrence matrix)
3GLCM_CLUSHADECluster shade (grey level co-occurrence matrix)
3GLCM_CLUTENDCluster tendency (grey level co-occurrence matrix)
3GLCM_CONTRASTContrast (grey level co-occurrence matrix)
3GLCM_CORRELATIONCorrelation (grey level co-occurrence matrix)
3GLCM_DIFAVEDefference average (grey level co-occurrence matrix)
3GLCM_DIFENTRODifference entropy (grey level co-occurrence matrix)
3GLCM_DIFVARDifference variance (grey level co-occurrence matrix)
3GLCM_DISDissimilarity (grey level co-occurrence matrix)
3GLCM_ENERGYEnergy (grey level co-occurrence matrix)
3GLCM_ENTROPYEntropy (grey level co-occurrence matrix)
3GLCM_HOM1Homogeneity-1 (grey level co-occurrence matrix)
3GLCM_HOM2Homogeneity-2 (grey level co-occurrence matrix)
3GLCM_IDInverse difference (grey level co-occurrence matrix)
3GLCM_IDNNormalized inverse difference (grey level co-occurrence matrix)
3GLCM_IDMInverse difference moment (grey level co-occurrence matrix)
3GLCM_IDMNNormalized inverse difference moment (grey level co-occurrence matrix)
3GLCM_INFOMEAS11st information measure of correlation (grey level co-occurrence matrix)
3GLCM_INFOMEAS22nd information measure of correlation (grey level co-occurrence matrix)
3GLCM_IVInverse variance (grey level co-occurrence matrix)
3GLCM_JAVEJoint average (grey level co-occurrence matrix)
3GLCM_JEJoint entropy (grey level co-occurrence matrix)
3GLCM_JMAXJoint maximum aka "max probability" (grey level co-occurrence matrix)
3GLCM_JVARJoint variance aka "sum of squares" (grey level co-occurrence matrix)
3GLCM_SUMAVERAGESum average (grey level co-occurrence matrix)
3GLCM_SUMENTROPYSum entropy (grey level co-occurrence matrix)
3GLCM_SUMVARIANCESum variance (grey level co-occurrence matrix)
3GLCM_VARIANCEVariance (grey level co-occurrence matrix)
3GLCM_ASM_AVEdirectional average of 3GLCM_ASM
3GLCM_ACOR_AVEdirectional average of 3GLCM_ACOR
3GLCM_CLUPROM_AVEdirectional average of 3GLCM_CLUPROM
3GLCM_CLUSHADE_AVEdirectional average of 3GLCM_CLUSHADE
3GLCM_CLUTEND_AVEdirectional average of 3GLCM_CLUTEND
3GLCM_CONTRAST_AVEdirectional average of 3GLCM_CONTRAST
3GLCM_CORRELATION_AVEdirectional average of 3GLCM_CORRELATION
3GLCM_DIFAVE_AVEdirectional average of 3GLCM_DIFAVE
3GLCM_DIFENTRO_AVEdirectional average of 3GLCM_DIFENTRO
3GLCM_DIFVAR_AVEdirectional average of 3GLCM_DIFVAR
3GLCM_DIS_AVEdirectional average of 3GLCM_DIS
3GLCM_ENERGY_AVEdirectional average of 3GLCM_ENERGY
3GLCM_ENTROPY_AVEdirectional average of 3GLCM_ENTROPY
3GLCM_HOM1_AVEdirectional average of 3GLCM_HOM1
3GLCM_ID_AVEdirectional average of 3GLCM_ID
3GLCM_IDN_AVEdirectional average of 3GLCM_IDN
3GLCM_IDM_AVEdirectional average of 3GLCM_IDM
3GLCM_IDMN_AVEdirectional average of 3GLCM_IDMN
3GLCM_IV_AVEdirectional average of 3GLCM_IV
3GLCM_JAVE_AVEdirectional average of 3GLCM_JAVE
3GLCM_JE_AVEdirectional average of 3GLCM_JE
3GLCM_INFOMEAS1_AVEdirectional average of 3GLCM_INFOMEAS1
3GLCM_INFOMEAS2_AVEdirectional average of 3GLCM_INFOMEAS2
3GLCM_VARIANCE_AVEdirectional average of 3GLCM_VARIANCE
3GLCM_JMAX_AVEdirectional average of 3GLCM_JMAX
3GLCM_JVAR_AVEdirectional average of 3GLCM_JVAR
3GLCM_SUMAVERAGE_AVEdirectional average of 3GLCM_SUMAVERAGE
3GLCM_SUMENTROPY_AVEdirectional average of 3GLCM_SUMENTROPY
3GLCM_SUMVARIANCE_AVEdirectional average of 3GLCM_SUMVARIANCE
3GLDM_SDESmall dependence emphasis (grey level dependence matrix)
3GLDM_LDELarge dependence emphasis (grey level dependence matrix)
3GLDM_GLNGray level non-uniformity (grey level dependence matrix)
3GLDM_DNDependence non-uniformity (grey level dependence matrix)
3GLDM_DNNNormalized dependence non-uniformity (grey level dependence matrix)
3GLDM_GLVGray level variance (grey level dependence matrix)
3GLDM_DVDependence variance (grey level dependence matrix)
3GLDM_DEDependence entropy (grey level dependence matrix)
3GLDM_LGLELow gray level emphasis (grey level dependence matrix)
3GLDM_HGLEHigh gray level emphasis (grey level dependence matrix)
3GLDM_SDLGLESmall dependence low gray level emphasis (grey level dependence matrix)
3GLDM_SDHGLESmall dependence high gray level emphasis (grey level dependence matrix)
3GLDM_LDLGLELarge dependence low gray level emphasis (grey level dependence matrix)
3GLDM_LDHGLELarge dependence high gray level emphasis (grey level dependence matrix)
3GLDZM_SDESmall distance emphasis (grey level distance zone matrix)
3GLDZM_LDELarge distance emphasis (grey level distance zone matrix)
3GLDZM_LGLZELow grey level zone emphasis (grey level distance zone matrix)
3GLDZM_HGLZEHigh grey level zone emphasis (grey level distance zone matrix)
3GLDZM_SDLGLESmall distance low grey level emphasis (grey level distance zone matrix)
3GLDZM_SDHGLESmall distance high grey level emphasis (grey level distance zone matrix)
3GLDZM_LDLGLELarge distance low grey level emphasis (grey level distance zone matrix)
3GLDZM_LDHGLELarge distance high grey level emphasis (grey level distance zone matrix)
3GLDZM_GLNUGrey level non uniformity (grey level distance zone matrix)
3GLDZM_GLNUNNormalized grey level non uniformity (grey level distance zone matrix)
3GLDZM_ZDNUZone distance non uniformity (grey level distance zone matrix)
3GLDZM_ZDNUNNormalized zone distance non uniformity (grey level distance zone matrix)
3GLDZM_ZPZone percentage (grey level distance zone matrix)
3GLDZM_GLMGrey level mean (grey level distance zone matrix)
3GLDZM_GLVGrey level variance (grey level distance zone matrix)
3GLDZM_ZDMZone distance mean (grey level distance zone matrix)
3GLDZM_ZDVZone distance variance (grey level distance zone matrix)
3GLDZM_ZDEZone distance entropy (grey level distance zone matrix)
3GLRLM_SREShort run emphasis (grey level run length matrix)
3GLRLM_LRELong run emphasis (grey level run length matrix)
3GLRLM_GLNGray level non-uniformity (grey level run length matrix)
3GLRLM_GLNNNormalized gray level non-uniformity (grey level run length matrix)
3GLRLM_RLNRun length non-uniformity (grey level run length matrix)
3GLRLM_RLNNNormalized run length non-uniformity (grey level run length matrix)
3GLRLM_RPRun percentage (grey level run length matrix)
3GLRLM_GLVGray level variance (grey level run length matrix)
3GLRLM_RVRun variance (grey level run length matrix)
3GLRLM_RERun entropy (grey level run length matrix)
3GLRLM_LGLRELow gray level run emphasis (grey level run length matrix)
3GLRLM_HGLREHigh gray level run emphasis (grey level run length matrix)
3GLRLM_SRLGLEShort run low gray level emphasis (grey level run length matrix)
3GLRLM_SRHGLEShort run high gray level emphasis (grey level run length matrix)
3GLRLM_LRLGLELong run low gray level emphasis (grey level run length matrix)
3GLRLM_LRHGLELong run high gray level emphasis (grey level run length matrix)
3GLRLM_SRE_AVEdirectional average of 3GLRLM_SRE
3GLRLM_LRE_AVEdirectional average of 3GLRLM_LRE
3GLRLM_GLN_AVEdirectional average of 3GLRLM_GLN
3GLRLM_GLNN_AVEdirectional average of 3GLRLM_GLNN
3GLRLM_RLN_AVEdirectional average of 3GLRLM_RLN
3GLRLM_RLNN_AVEdirectional average of 3GLRLM_RLNN
3GLRLM_RP_AVEdirectional average of 3GLRLM_RP
3GLRLM_GLV_AVEdirectional average of 3GLRLM_GLV
3GLRLM_RV_AVEdirectional average of 3GLRLM_RV
3GLRLM_RE_AVEdirectional average of 3GLRLM_RE
3GLRLM_LGLRE_AVEdirectional average of 3GLRLM_LGLRE
3GLRLM_HGLRE_AVEdirectional average of 3GLRLM_HGLRE
3GLRLM_SRLGLE_AVEdirectional average of 3GLRLM_SRLGLE
3GLRLM_SRHGLE_AVEdirectional average of 3GLRLM_SRHGLE
3GLRLM_LRLGLE_AVEdirectional average of 3GLRLM_LRLGLE
3GLRLM_LRHGLE_AVEdirectional average of 3GLRLM_LRHGLE
3GLSZM_SAESmall area emphasis (grey level size zone matrix)
3GLSZM_LAELarge area emphasis (grey level size zone matrix)
3GLSZM_GLNGray level non-uniformity (grey level size zone matrix)
3GLSZM_GLNNNormalized gray level non-uniformity (grey level size zone matrix)
3GLSZM_SZNSize-zone non-uniformity (grey level size zone matrix)
3GLSZM_SZNNNormalized size-zone non-uniformity (grey level size zone matrix)
3GLSZM_ZPZone percentage (grey level size zone matrix)
3GLSZM_GLVGray level variance (grey level size zone matrix)
3GLSZM_ZVZone variance (grey level size zone matrix)
3GLSZM_ZEZone entropy (grey level size zone matrix)
3GLSZM_LGLZELow gray level zone emphasis (grey level size zone matrix)
3GLSZM_HGLZEHigh gray level zone emphasis (grey level size zone matrix)
3GLSZM_SALGLESmall area low gray level emphasis (grey level size zone matrix)
3GLSZM_SAHGLESmall area high gray level emphasis (grey level size zone matrix)
3GLSZM_LALGLELarge area low gray level emphasis (grey level size zone matrix)
3GLSZM_LAHGLELarge area high gray level emphasis (grey level size zone matrix)
3NGLDM_LDELow dependence emphasis (neighbouring grey level dependence matrix)
3NGLDM_HDEHigh dependence emphasis (neighbouring grey level dependence matrix)
3NGLDM_LGLCELow grey level count emphasis (neighbouring grey level dependence matrix)
3NGLDM_HGLCEHigh grey level count emphasis (neighbouring grey level dependence matrix)
3NGLDM_LDLGLELow dependence low grey level emphasis (neighbouring grey level dependence matrix)
3NGLDM_LDHGLELow dependence high grey level emphasis (neighbouring grey level dependence matrix)
3NGLDM_HDLGLEHigh dependence low grey level emphasis (neighbouring grey level dependence matrix)
3NGLDM_HDHGLEHigh dependence high grey level emphasis (neighbouring grey level dependence matrix)
3NGLDM_GLNUGrey level non-uniformity (neighbouring grey level dependence matrix)
3NGLDM_GLNUNGrey level non-uniformity normalised (neighbouring grey level dependence matrix)
3NGLDM_DCNUDependence count non-uniformity (neighbouring grey level dependence matrix)
3NGLDM_DCNUNDependence count non-uniformity normalised (neighbouring grey level dependence matrix)
3NGLDM_DCPDependence count percentage (neighbouring grey level dependence matrix)
3NGLDM_GLMGrey level mean (neighbouring grey level dependence matrix)
3NGLDM_GLVGrey level variance (neighbouring grey level dependence matrix)
3NGLDM_DCMDependence count mean (neighbouring grey level dependence matrix)
3NGLDM_DCVDependence count variance (neighbouring grey level dependence matrix)
3NGLDM_DCENTDependence count entropy (neighbouring grey level dependence matrix)
3NGLDM_DCENEDependence count energy (neighbouring grey level dependence matrix)
3NGTDM_COARSENESSCoarseness (neighbouring grey tone difference matrix)
3NGTDM_CONTRASTContrast (neighbouring grey tone difference matrix)
3NGTDM_BUSYNESSBusyness (neighbouring grey tone difference matrix)
3NGTDM_COMPLEXITYComplexity (neighbouring grey tone difference matrix)
3NGTDM_STRENGTHStrength (neighbouring grey tone difference matrix)

3D feature groups


Group codeBelonging features
*3D_ALL*All the 3D features
*3D_ALL_INTENSITY*3COV, 3COVERED_IMAGE_INTENSITY_RANGE, 3ENERGY, 3ENTROPY, 3EXCESS_KURTOSIS, 3HYPERFLATNESS, 3HYPERSKEWNESS, 3INTEGRATED_INTENSITY, 3INTERQUARTILE_RANGE, 3KURTOSIS, 3MAX, 3MEAN, 3MEAN_ABSOLUTE_DEVIATION, 3MEDIAN, 3MEDIAN_ABSOLUTE_DEVIATION, 3MIN, 3MODE, 3P01, 3P10, 3P25, 3P75, 3P90, 3P99, 3QCOD, 3RANGE, 3ROBUST_MEAN, 3ROBUST_MEAN_ABSOLUTE_DEVIATION, 3ROOT_MEAN_SQUARED, 3SKEWNESS, 3STANDARD_DEVIATION, 3STANDARD_DEVIATION_BIASED, 3STANDARD_ERROR, 3UNIFORMITY, 3UNIFORMITY_PIU, 3VARIANCE, and 3VARIANCE_BIASED
*3D_ALL_MORPHOLOGY*3AREA, 3AREA_2_VOLUME, 3COMPACTNESS1 and -2, 3MESH_VOLUME, 3SPHERICAL_DISPROPORTION, 3SPHERICITY, 3VOLUME_CONVEXHULL, 3VOXEL_VOLUME, 3MAJOR_AXIS_LEN, 3MINOR_AXIS_LEN, 3LEAST_AXIS_LEN, 3ELONGATION, and 3FLATNESS
*3D_ALL_TEXTURE*All the 3GLCM_... 3GLDM_... 3GLDZM_... 3GLSZM_... 3GLRLM_... 3NGLDM_... and 3NGTDM_... features
*3D_GLCM*All the 3GLCM_... features
*3D_GLDM*All the 3GLDM_... features
*3D_GLDZM*All the 3GLDZM_... features
*3D_GLSZM*All the 3GLSZM_... features
*3D_GLRLM*All the 3GLRLM_... features
*3D_NGLDM*All the 3NGLDM_... features
*3D_NGTDM*All the 3NGTDM_... features

Command line usage

Assuming you built the Nyxus binary as outlined below, the following parameters are available for the command line interface:

Parameter
DescriptionType
--outputTypeOutput type for feature values (speratecsv, singlecsv, arrow, parquet). Default value: '--outputType=separatecsv'string constant
--featuresString constant or comma-seperated list of constants requesting a group of features or particular feature. Default value: '--features=*ALL*'string
--filePatternRegular expression to match image files in directories specified by parameters '--intDir' and '--segDir'. To match all the files, use '--filePattern=.*'string
--intDirDirectory of intensity image collectionpath
--outDirOutput directorypath
--segDirDirectory of labeled image collectionpath
--useGpu${\color{red}\textsf{(optional)}}$ Calculate compute-expensive features on an NVIDIA GPU device specified by parameter --gpuDeviceID. Default: '--useGpu=false'. Example: --useGpu=trueboolean
--gpuDeviceID${\color{red}\textsf{(optional)}}$ ID of a GPU device to be used when '--useGpu=true'. Default: '--gpuDeviceID=0'. Example 1 (single GPU device): '--useGpu=true --gpuDeviceID=2' to strictly use device 2. Example 2 (multiple GPU devices, usually in SLURM scenarios): '--useGpu=true --gpuDeviceID=0,1,3' to use the GPU device having maximum free RAM of devices 0, 1, and 3.integer or list of integers
--coarseGrayDepth${\color{red}\textsf{(optional)}}$ Custom number of greyscale level bins used in texture features. Default: '--coarseGrayDepth=256'integer
--glcmAngles${\color{red}\textsf{(optional)}}$ Enabled direction angles of the GLCM feature. Superset of values: 0, 45, 90, and 135. Default: '--glcmAngles=0,45,90,135'list of integers
--intSegMapDir${\color{red}\textsf{(optional)}}$ Data collection of the ad-hoc intensity-to-mask file mapping. Must be used in combination with parameter '--intSegMapFile'path
--intSegMapFile${\color{red}\textsf{(optional)}}$ Name of the text file containing an ad-hoc intensity-to-mask file mapping. The files are assumed to reside in corresponding intensity and label collections. Must be used in combination with parameter '--intSegMapDir'string
--pixelDistance${\color{red}\textsf{(optional)}}$ Number of pixels to treat ROIs within specified distance as neighbors. Default value: '--pixelDistance=5'integer
--pixelsPerCentimeter${\color{red}\textsf{(optional)}}$ Number of pixels in centimeter used by unit length-related features. Default value: 0real
--ramLimit${\color{red}\textsf{(optional)}}$ Amount of memory not to exceed by Nyxus, in megabytes. Default value: 50% of available memory. Example: '--ramLimit=2000' to use 2,000 megabytesinteger
--reduceThreads${\color{red}\textsf{(optional)}}$ Number of CPU threads used on the feature calculation step. Default: '--reduceThreads=1'integer
--skiproi${\color{red}\textsf{(optional)}}$ Skip ROIs having specified labels. Example: '--skiproi=image1.tif:2,3,4;image2.tif:45,56'string
--tempDir${\color{red}\textsf{(optional)}}$ Directory used by temporary out-of-RAM objects. Default value: system temporary directorypath
--hsig${\color{red}\textsf{(optional)}}$ Channel signature Example: "--hsig=_c" to match images whose file names have channel info starting substring '_c' like in 'p0_y1_r1_c1.ome.tiff'string
--hpar${\color{red}\textsf{(optional)}}$ Channel number that should be used as a provider of parent segments. Example: '--hpar=1'integer
--hchi${\color{red}\textsf{(optional)}}$ Channel number that should be used as a provider of child segments. Example: '--hchi=0'integer
--hag${\color{red}\textsf{(optional)}}$ Name of a method how to aggregate features of segments recognized as children of same parent segment. Valid options are 'SUM', 'MEAN', 'MIN', 'MAX', 'WMA' (weighted mean average), and 'NONE' (no aggregation, instead, same parent child segments will be laid out horizontally)string
--fpimgdr${\color{red}\textsf{(optional)}}$ Desired dynamic range of voxels of a floating point TIFF image. Example: --fpimgdr=240 makes intensities be read in range 0-240. Default value: 10e4unsigned integer
--fpimgmin${\color{red}\textsf{(optional)}}$ Minimum intensity of voxels of a floating point TIFF image. Default value: 0.0real
--fpimgdr${\color{red}\textsf{(optional)}}$ Maximum intensity of voxels of a floating point TIFF image. Default value: 1.0real
--anisox${\color{red}\textsf{(optional)}}$ x-anisotropy. Default value: 1.0real
--anisoy${\color{red}\textsf{(optional)}}$ y-anisotropy. Default value: 1.0real
--anisoz${\color{red}\textsf{(optional)}}$ z-anisotropy (for 3D datasets). Default value: 1.0real

Examples

Example 1:Running Nyxus to process images of specific image channel

Suppose we need to process intensity/mask images of channel 1 :

./nyxus --features=*all_intensity*,*basic_morphology* --intDir=/path/to/intensity/images --segDir=/path/to/mask/images --outDir=/path/to/output --filePattern=.*_c1\.ome\.tif --outputType=singlecsv 

Example 2:Running Nyxus to process specific image

Suppose we need to process intensity/mask file p1_y2_r68_c1.ome.tif :

./nyxus --features=*all_intensity*,*basic_morphology* --intDir=/path/to/intensity/images --segDir=/path/to/mask/images --outDir=/path/to/output --filePattern=p1_y2_r68_c1\.ome\.tif --outputType=singlecsv 

Example 3:Running Nyxus to extract only intensity and basic morphology features

./nyxus --features=*all_intensity*,*basic_morphology* --intDir=/path/to/intensity/images --segDir=/path/to/mask/images --outDir=/path/to/output --filePattern=.* --outputType=singlecsv 

Example 4:Skipping specified ROIs while extracting features

Suppose we need to blacklist ROI labels 2 and 3 from the kurtosis feature extraction globally, in each image. The command line way to do that is using option --skiproi :

./nyxus --skiproi=2,3 --features=KURTOSIS --intDir=/path/to/intensity/images --segDir=/path/to/mask/images --outDir=/path/to/output --filePattern=.* --outputType=singlecsv 

As a result, the default feature extraction result produced without option --skiproi looking like

 mask_image intensity_image label KURTOSIS
0 p0_y1_r1_c0.tif p0_y1_r1_c0.tif 1 -0.134216
1 p0_y1_r1_c0.tif p0_y1_r1_c0.tif 2 -0.130024
2 p0_y1_r1_c0.tif p0_y1_r1_c0.tif 3 -1.259801
3 p0_y1_r1_c0.tif p0_y1_r1_c0.tif 4 -0.934786
4 p0_y1_r1_c0.tif p0_y1_r1_c0.tif 5 -1.072111
.. ... ... ... ...

will start looking like

 mask_image intensity_image label KURTOSIS
0 p0_y1_r1_c0.tif p0_y1_r1_c0.tif 1 -0.134216
1 p0_y1_r1_c0.tif p0_y1_r1_c0.tif 4 -0.934786
2 p0_y1_r1_c0.tif p0_y1_r1_c0.tif 5 -1.072111
3 p0_y1_r1_c0.tif p0_y1_r1_c0.tif 6 -0.347741
4 p0_y1_r1_c0.tif p0_y1_r1_c0.tif 7 -1.283468
.. ... ... ... ...

Note the comma character separator , in the blacklisted ROI label list.

If we need to blacklist ROI labels 15 and 16 only in image image421.tif ROI label 17 in image image422.tif, we can do it via a per-file blacklist :

./nyxus --skiproi=image421.tif:15,16;image421.tif:17 --features=KURTOSIS --intDir=/path/to/intensity/images --segDir=/path/to/mask/images --outDir=/path/to/output --filePattern=.* --outputType=singlecsv 

Note the colon character : between the file name and backlisted labels within this file and semicolon character separator ; of file blacklists.

Example 5:Skipping specified ROIs while extracting features (via Python API)

The Nyxus Python API equivalent of global ROI blacklisting is implemented by method blacklist_roi(string) called before a call of method featurize...(), for example, labels 15, 16, and 17 can be globally blacklisted as follows:

fromnyxusimportNyxusnyx=Nyxus(features=["KURTOSIS"])
nyx.blacklist_roi('15,16,17')
features=nyx.featurize_directory (intensity_dir="/path/to/intensity/images", label_dir="/path/to/mask/images", file_pattern=".*")

Similarly, per-file ROI blacklists are defined in a way similar to the command line interface:

fromnyxusimportNyxusnyx=Nyxus(features=["KURTOSIS"])
nyx.blacklist_roi('p0_y1_r1_c0.ome.tif:15,16;p0_y1_r2_c0.ome.tif:17')
features=nyx.featurize_directory (intensity_dir="/path/to/intensity/images", label_dir="/path/to/mask/images", file_pattern=".*")

See also methods clear_roi_blacklist() and roi_blacklist_get_summary() .

Example 6:Specifying anisotropy in 3D (via command line)

Applying a 1.5 x 2.0 x 2.5 anisotropy correction to all the volumes in a compressed NIFTI dataset:

--anisox=1.5 --anisoy=2 --anisoz=2.5 --dim=3 --filePattern="*\.nii\.gz" --features=*3D_ALL* --resultFname=3d-features --outputType=singlecsv --intDir=/data/patient123/intensity --segDir=/data/patient123/masks --outDir=/output/patient123

2D compatibility:

--anisox=1.5 --anisoy=2 --filePattern="*\.ome\.tiff" --features=*ALL* --resultFname=features1 --outputType=singlecsv --intDir=/data/plate123/int --segDir=/data/plate123/seg --outDir=/output/plate123

Nested ROIs

Hierarchical ROI analysis in a form of finding ROIs nested geometrically as nested AABBs and aggregating features of child ROIs within corresponding parent is available as an optional extra step after the feature extraction of the whole image set is finished. To enable this step, all the command line options '--hsig', '--hpar', '--hchi', and '--hag' need to have non-blank valid values.

Valid aggregation options are SUM, MEAN, MIN, MAX, WMA (weighted mean average), or NONE (no aggregation).

Example 6:Processing an image set with nested ROI postprocessing

nyxus --features=*ALL_intensity* --intDir=/path/to/intensity/images --segDir=/path/to/mask/images --outDir=/path/to/output/directory --filePattern=.* --outputType=separatecsv --reduceThreads=4 --hsig=_c --hpar=1 --hchi=0 --hag=WMA 

As a result, 2 additional CSV files will be produced for each mask image whose channel number matches the value of option '--hpar': file

<imagename>_nested_features.csv

where features of the detected child ROIs are laid next to their parent ROIs on same lines and auxiliary file

<imagename>_nested_relations.csv

serving as a relational table of parent and child ROI labels within parent ROI channel image <imagename>.

Nested features Python API

The nested features functionality can also be utilized in Python using the Nested class in nyxus. The Nested class contains two methods, find_relations and featurize.

The find_relations method takes in a path to the label files, along with a child filepattern to identify the files in the child channel and a parent filepattern to match the files in the parent channel. The find_relation method returns a Pandas DataFrame containing a mapping between parent ROIs and the respective child ROIs.

The featurize method takes in the parent-child mapping along with the features of the ROIs in the child channel. If a list of aggregate functions is provided to the constructor, this method will return a pivoted DataFrame where the rows are the ROI labels and the columns are grouped by the features.

Example 7: Using aggregate functions

fromnyxusimportNyxus, Nestedimportnumpyasnpint_path='path/to/intensity'seg_path='path/to/segmentation'nyx=Nyxus(['GABOR'])
child_features=nyx.featurize(int_path, seg_path, file_pattern='p[0-9]_y[0-9]_r[0-9]_c0\.ome\.tif')
nest=Nested(['sum', 'mean', 'min', ('nanmean', lambdax: np.nanmean(x))])
df=nest.find_relations(seg_path, 'p{r}_y{c}_r{z}_c1.ome.tif', 'p{r}_y{c}_r{z}_c0.ome.tif')
df2=nest.featurize(df, features)

The parent-child map is

 Image Parent_Label Child_Label
0 /path/to/image 72 65
1 /path/to/image 71 66
2 /path/to/image 70 64
3 /path/to/image 68 61
4 /path/to/image 67 65

and the aggregated DataFrame is

 GABOR_0 GABOR_1 GABOR_2 ... sum mean min nanmean sum mean min nanmean sum mean ...
label ... 1 24.010227 0.666951 0.000000 0.666951 19.096262 0.530452 0.001645 0.530452 17.037345 0.473260 ... 2 13.374170 0.445806 0.087339 0.445806 7.279187 0.242640 0.075000 0.242640 6.390529 0.213018 ... 3 5.941783 0.198059 0.000000 0.198059 3.364149 0.112138 0.000000 0.112138 2.426409 0.080880 ... 4 13.428773 0.559532 0.000000 0.559532 12.021938 0.500914 0.008772 0.500914 9.938915 0.414121 ... 5 6.535722 0.181548 0.000000 0.181548 1.833463 0.050930 0.000000 0.050930 2.083023 0.057862 ...

Example 8:Without aggregate functions

fromnyxusimportNyxus, Nestedimportnumpyasnpint_path='path/to/intensity'seg_path='path/to/segmentation'nyx=Nyxus(['GABOR'])
child_features=nyx.featurize(int_path, seg_path, file_pattern='p[0-9]_y[0-9]_r[0-9]_c0\.ome\.tif')
nest=Nested()
df=nest.find_relations(seg_path, 'p{r}_y{c}_r{z}_c1.ome.tif', 'p{r}_y{c}_r{z}_c0.ome.tif')
df2=nest.featurize(df, features)

the parent-child map remains the same but the featurize result becomes

 GABOR_0 ... Child_Label 1 2 3 4 5 6 7 8 9 10 ... label ...
1 0.666951 NaN NaN NaN NaN NaN NaN NaN NaN NaN ... 2 NaN 0.445806 NaN NaN NaN NaN NaN NaN NaN NaN ... 3 NaN NaN 0.198059 NaN NaN NaN NaN NaN NaN NaN ... 4 NaN NaN NaN 0.559532 NaN NaN NaN NaN NaN NaN ... 5 NaN NaN NaN NaN 0.181548 NaN NaN NaN NaN NaN ...

Building from source

Nyxus uses CMake as the build system and needs a C++17 supported compiler to build from the source.

Dependencies

To build Nyxus from source, several build dependencies are needed to be satisfied. These dependencies arise from Nyxus's need to read and write various data format. The dependencies are listed below.

  • Tiff Support: libtiff, libdeflate, zlib
  • Zarr Support: z5, xtensor, nlohman_json, blosc, zlib
  • Dicom Support: dcmtk, fmjpeg, zlib
  • Apache Arrow Support: arrow-cpp, pyarrow
  • Python Interface: pybind11

These packages also have underlying dependencies and at times, these dependency resolution may appear challenging. We prefer conda to help with resolving these dependencies. However, for users without access to a conda enviornment, we have also provided installation script to build and install all the dependencies except Apache Arrow.

By default, Nyxus can be built with a minimal set of dependecies (Tiff support and Python interface). To build Nyxus with all the supported IO options mentioned above, pass -DALLEXTRAS=ON in the cmake command.

Adding GPU Support

Nyxus also can be build with NVIDIA GPU support. To do so, a CUDA Development toolkit compatible with the host C++ compiler need to be present in the system. For building with GPU support, pass -DUSEGPU=ON flag in the cmake command.

Inside Conda

To build the command line interface, pass -DBUILD_CLI=ON in the cmake command.

Below is an example of how to build Nyxus inside a conda environment on Linux.

conda create -n nyxus_build python=3.12
conda activate nyxus_build
git clone https://github.com/PolusAI/nyxus.git
cd nyxus
conda install mamba -c conda-forge
mamba install -y -c conda-forge --file ci-utils/envs/conda_cpp.txt export NYXUS_DEP_DIR=$CONDA_PREFIX
mkdir build
cd build
cmake -DBUILD_CLI=ON -DALLEXTRAS=ON -DUSEGPU=ON ..
make -j4

To install the python package in the conda environment on Linux, use the following direction.

conda create -n nyxus_build python=3.12
conda activate nyxus_build
git clone https://github.com/PolusAI/nyxus.git
cd nyxus
conda install mamba -c conda-forge
mamba install -y -c conda-forge --file ci-utils/envs/conda_cpp.txt --file ci-utils/envs/conda_py.txt
export NYXUS_DEP_DIR=$CONDA_PREFIX
CMAKE_ARGS="-DUSEGPU=ON -DALLEXTRAS=ON -DPython_ROOT_DIR=$CONDA_PREFIX -DPython_FIND_VIRTUALENV=ONLY" python -m pip install . -vv

If there's no system wide compatible C++ compiler, we may install it using conda and the configuration script will pick it up.

...
conda activate nyxus_build
conda install cxx-compiler -y export NYXUS_DEP_DIR=$CONDA_PREFIX
...

Without Using Conda

To build Nyxus outside of a conda environment, we will first need to build and install all the required and optional dependecies. ci-utils/install_prereq_windwos.bat and ci-utils/install_prereq_linux.sh performs the task for Windows and Linux (and Mac) respectively. These script take a --min_build yes option to only build the minimal dependencies. Below, we provide an example for Windows OS.

git clone https://github.com/PolusAI/nyxus.git
cd nyxus
mkdir build
cd build
..\ci-utils\install_prereq_windows.bat
cmake -DBUILD_CLI=ON -DUSEGPU=ON -DALLEXTRAS=ON -DCMAKE_PREFIX_PATH=.\local_install -DCMAKE_INSTALL_PREFIX=.\local_install ..
cmake --build . --config Release
set PATH=%PATH%;%cd%\local_install\bin

To install the python package in the environment on Linux, use the following direction.

python -m virtualenv venv
venv\Scripts\activate.bat
git clone https://github.com/PolusAI/nyxus.git
cd nyxus
mkdir build_dep
cd build_dep
..\ci-utils\install_prereq_windows.bat
cd ..
set NYXUS_DEP_DIR=%cd%\build_dep\local_install
set CMAKE_ARGS=-DUSEGPU=ON -DALLEXTRAS=ON
python -m pip install . -vv
xcopy /E /I /y %NYXUS_DEP_DIR%\bin\*.dll %VIRTUAL_ENV%\lib\site-packages\nyxus

Note that, in both cases, the dlls of the dependencies need to be in the PATH (for CLI) or in the site-packages location (for Python package).

Running via Docker

Running Nyxus from a local directory freshly made Docker container is a good idea. It allows one to test-run conteinerized Nyxus before it reaches Docker cloud deployment.

To search available Nyxus images run command

docker search nyxus

and you'll be shown that it's available at least via organization 'polusai'. To pull it, run

docker pull polusai/nyxus

The following command line is an example of running the dockerized feature extractor (image hash 87f3b560bbf2) with only intensity features selected:

docker run -it [--gpus all] --mount type=bind,source=/images/collections,target=/data 87f3b560bbf2 --intDir=/data/c1/int --segDir=/data/c1/seg --outDir=/data/output --filePattern=.* --outputType=separatecsv --features=entropy,kurtosis,skewness,max_intensity,mean_intensity,min_intensity,median,mode,standard_deviation

WIPP Usage

Nyxus is available as plugin for WIPP.

Label image collection: The input should be a labeled image in tiled OME TIFF format (.ome.tif). Extracting morphology features, Feret diameter statistics, neighbors, hexagonality and polygonality scores requires the segmentation labels image. If extracting morphological features is not required, the label image collection can be not specified.

Intensity image collection: Extracting intensity-based features requires intensity image in tiled OME TIFF format. This is an optional parameter - the input for this parameter is required only when intensity-based features needs to be extracted.

File pattern: Enter file pattern to match the intensity and labeled/segmented images to extract features (https://pypi.org/project/filepattern/) Filepattern will sort and process files in the labeled and intensity image folders alphabetically if universal selector(.*.ome.tif) is used. If a more specific file pattern is mentioned as input, it will get matches from labeled image folder and intensity image folder based on the pattern implementation.

Pixel distance: Enter value for this parameter if neighbors touching cells needs to be calculated. The default value is 5. This parameter is optional.

Features: Comma separated list of features to be extracted. If all the features are required, then choose option all.

Outputtype: There are 4 options available under this category. Separatecsv - to save all the features extracted for each image in separate csv file. Singlecsv - to save all the features extracted from all the images in the same csv file. Arrow - to save all the features extracted from all the images in Apache Arrow format. Parquet - to save all the features extracted from all the images in Apache Parquet format

Embedded pixel size: This is an optional parameter. Use this parameter only if units are present in the metadata and want to use those embedded units for the features extraction. If this option is selected, value for the length of unit and pixels per unit parameters are not required.

Length of unit: Unit name for conversion. This is also an optional parameter. This parameter will be displayed in plugin's WIPP user interface only when embedded pixel size parameter is not selected (ckrresponding check box checked).

Pixels per unit: If there is a metric mentioned in Length of unit, then Pixels per unit cannot be left blank and hence the scale per unit value must be mentioned in this parameter. This parameter will be displayed in plugin's user interface only when embedded pixel size parameter is not selected.

Note: If Embedded pixel size is not selected and values are entered in Length of unit and Pixels per unit, then the metric unit mentioned in length of unit will be considered. If Embedded pixel size, Length of unit and Pixels per unit is not selected and the unit and pixels per unit fields are left blank, the unit will be assumed to be pixels.

Output: The output is a csv file containing the value of features required.

For more information on WIPP, visit the official WIPP page.

About

A fully scalable robust image feature extraction library.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages