ximage.labels package#

Submodules#

ximage.labels.labels module#

Labels identification.

ximage.labels.labels.check_core_dims(core_dims, data_array)[source][source]#

Check core_dims argument and infer if needed.

ximage.labels.labels.get_data_array(xr_obj, variable=None)[source][source]#

Check xarray object and variable validity.

ximage.labels.labels.get_label_indices(arr)[source][source]#

Get label indices from numpy.ndarray, dask.Array and xarray.DataArray.

It removes 0 and np.NaN values. Output type is int.

ximage.labels.labels.highlight_label(xr_obj, label_name, label_id)[source][source]#

Set all labels values to 0 except for ‘label_id’.

ximage.labels.labels.label(xr_obj, *, variable=None, core_dims=None, min_value_threshold=-inf, max_value_threshold=inf, min_area_threshold=1, max_area_threshold=inf, footprint=None, sort_by='area', sort_decreasing=True, labeled_comprehension_kwargs=None, label_name='label')[source][source]#

Compute labels and and add as a coordinates to an xarray object.

Parameters:
  • xr_obj (xarray.DataArray or xarray.Dataset) – xarray object.

  • variable (str, optional) – Dataset variable to exploit to derive the labels array. Must be specified only if the input object is an xarray.Dataset.

  • core_dims (tuple of str, optional) – Names of the two dimensions along which the labeling is applied. If the xarray DataArray is two-dimensional and core_dims is not provided, the core dimensions are inferred automatically from DataArray.dims. If the xarray DataArray has more than two dimensions, core_dims must be specified explicitly. In this case, labeling is applied independently over all remaining (non-core) dimensions. Example: for a 3D DataArray with dimensions (x, y, time), use core_dims=("x", "y") to apply labeling to each timestep.

  • min_value_threshold (float, optional) – The minimum value to define the interior of a label. The default is -np.inf.

  • max_value_threshold (float, optional) – The maximum value to define the interior of a label. The default is np.inf.

  • min_area_threshold (float, optional) – The minimum number of connected pixels to be defined as a label. The default is 1.

  • max_area_threshold (float, optional) – The maximum number of connected pixels to be defined as a label. The default is np.inf.

  • footprint (int, numpy.ndarray or None, optional) – This argument enables to dilate the mask derived after applying min_value_threshold and max_value_threshold. If footprint = 0 or None, no dilation occur. If footprint is a positive integer, it create a disk(footprint) If footprint is a 2D array, it must represent the neighborhood expressed as a 2-D array of 1’s and 0’s. The default is None (no dilation).

  • sort_by (callable or str, optional) – A function or statistics to define the order of the labels. Valid string statistics are "area", "maximum", "minimum", "mean", "median", "sum", "standard_deviation", "variance". The default is "area".

  • sort_decreasing (bool, optional) – If True, sort labels by decreasing sort_by value. The default is True.

  • labeled_comprehension_kwargs (dict, optional) – Additional arguments to be passed to dask_image.ndmeasure.labeled_comprehension. if sort_by is a callable.

Returns:

xr_obj – xarray object with the new label coordinate. In the label coordinate, non-labels values are set to np.nan.

Return type:

(xarray.DataArray or xarray.Dataset)

ximage.labels.labels.redefine_label_array(data, label_indices=None)[source][source]#

Redefine labels of a label array from 0 to len(label_indices).

If label_indices is None, it takes the unique values of label_arr. If label_indices contains a 0, it is discarded ! If label_indices is not unique, raise an error !

Native label values not present in label_indices are set to 0. The first label in label_indices becomes 1, the second 2, and so on.

ximage.labels.plot_labels module#

Utilities to plot labels.

ximage.labels.plot_labels.get_label_colorbar_settings(label_indices, cmap='Paired')[source][source]#

Return plot and cbar kwargs to plot properly a label array.

ximage.labels.plot_labels.plot_labels(dataarray, x=None, y=None, ax=None, max_n_labels=50, add_colorbar=True, cmap='Paired', use_imshow=False, **plot_kwargs)[source][source]#

Plot labels.

The maximum allowed number of labels to plot is ‘max_n_labels’.

Module contents#

Labels module.