合并注释标签#

在这个笔记本中,我们演示如何通过注释应该合并的标签来对标签图像进行后处理。

import apoc
from skimage.io import imread, imshow, imsave
import pyclesperanto_prototype as cle
import numpy as np

我们的起点是一个过度分割的(合成的)标签图像。

oversegmented = cle.asarray(imread('../../data/syntetic_cells.tif')).astype(np.uint32)
oversegmented
cle._ image
shape(512, 512)
dtypeuint32
size1024.0 kB
min0.0
max49.0

此外,我们需要一个注释,其中像素强度 = 1 表示应该合并标签。

annotation = cle.asarray(imread('../../data/syntetic_cells_merge_annotation.tif')).astype(np.uint32)

# binarize the image
annotation = annotation == 1

annotation
cle._ image
shape(512, 512)
dtypeuint8
size256.0 kB
min0.0
max1.0

为了可视化,我们将两者叠加。

cle.imshow(oversegmented, labels=True, continue_drawing=True)
cle.imshow(annotation, alpha=0.5)
../_images/2f1880ffefc1b3184e3c73ac9a2031afdeb0d774ebde96a8cd77f3e78e8c3b1d.png

现在我们可以合并所有边界被注释的细胞。

result = cle.merge_annotated_touching_labels(oversegmented, annotation)
result
cle._ image
shape(512, 512)
dtypeuint32
size1024.0 kB
min0.0
max18.0

它是如何工作的?#

在底层,有一个函数用于从标签图像和注释生成接触矩阵,还有一个函数用于根据接触矩阵合并标签。

should_touch_matrix = cle.generate_should_touch_matrix(oversegmented, annotation)
should_touch_matrix
cle._ image
shape(50, 50)
dtypefloat32
size9.8 kB
min0.0
max1.0
result = cle.merge_labels_according_to_touch_matrix(oversegmented, should_touch_matrix)
result
cle._ image
shape(512, 512)
dtypeuint32
size1024.0 kB
min0.0
max18.0