Fusión de etiquetas#

En principio, todos los algoritmos de segmentación tienen limitaciones. En caso de que los resultados sean subóptimos y no haya disponible un mejor algoritmo de segmentación, el post-procesamiento de etiquetas puede ser una opción. Hay algunas funciones disponibles para fusionar etiquetas según sus propiedades, como la intensidad a lo largo del borde donde las etiquetas se tocan o el recuento de píxeles de etiquetas combinadas por pares.

import pyclesperanto_prototype as cle
from napari_segment_blobs_and_things_with_membranes import local_minima_seeded_watershed
import numpy as np
cle.select_device("TX")
<NVIDIA GeForce RTX 3050 Ti Laptop GPU on Platform: NVIDIA CUDA (1 refs)>

Fusión de etiquetas que se tocan#

El caso de uso más trivial podría ser fusionar objetos etiquetados que se tocan.

blobs = cle.imread("../../data/blobs.tif")
blobs_labels = cle.voronoi_otsu_labeling(blobs, spot_sigma=3)
blobs_labels
cle._ image
shape(254, 256)
dtypeuint32
size254.0 kB
min0.0
max72.0
cle.merge_touching_labels(blobs_labels)
cle._ image
shape(254, 256)
dtypeuint32
size254.0 kB
min0.0
max61.0

Fusión de etiquetas según la intensidad del borde#

Como ejemplo, utilizamos un corte recortado del conjunto de datos de ejemplo cells3d en scikit-image.

image = cle.imread("../../data/membranes_2d.tif")[30:130, 0:100]
image
cle._ image
shape(100, 100)
dtypefloat32
size39.1 kB
min1062.0
max20614.0

En el siguiente ejemplo, nuestra célula en el centro de la imagen fue segmentada erróneamente como dos células:

labels = local_minima_seeded_watershed(image, spot_sigma=5, outline_sigma=0)
labels
nsbatwm made image
shape(100, 100)
dtypeint32
size39.1 kB
min1
max12

Esto se puede corregir fusionando células con intensidad de borde por debajo de un umbral dado.

merged_labels = cle.merge_labels_with_border_intensity_within_range(image, labels, maximum_intensity=5000)
merged_labels
c:\structure\code\pyclesperanto_prototype\pyclesperanto_prototype\_tier3\_generate_touch_mean_intensity_matrix.py:30: UserWarning: generate_touch_mean_intensity_matrix is supposed to work with images of integer type only.
Loss of information is possible when passing non-integer images.
  warnings.warn("generate_touch_mean_intensity_matrix is supposed to work with images of integer type only.\n" +
cle._ image
shape(100, 100)
dtypeuint32
size39.1 kB
min1.0
max8.0