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.NaNvalues. Output type isint.
- 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_dimsis not provided, the core dimensions are inferred automatically from DataArray.dims. If the xarray DataArray has more than two dimensions,core_dimsmust 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), usecore_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 = 0orNone, no dilation occur. Iffootprintis a positive integer, it create adisk(footprint)Iffootprintis a 2D array, it must represent the neighborhood expressed as a 2-D array of 1’s and 0’s. The default isNone(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 decreasingsort_byvalue. The default isTrue.labeled_comprehension_kwargs (dict, optional) – Additional arguments to be passed to dask_image.ndmeasure.labeled_comprehension. if
sort_byis 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:
- 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_indicesisNone, it takes the unique values oflabel_arr. Iflabel_indicescontains a 0, it is discarded ! Iflabel_indicesis not unique, raise an error !Native label values not present in label_indices are set to 0. The first label in
label_indicesbecomes 1, the second 2, and so on.
ximage.labels.plot_labels module#
Utilities to plot labels.
Module contents#
Labels module.