标签图像优化#

类似于对二值图像进行形态学操作,对标签图像也可以进行优化。本notebook展示了如何实现这一点。

另请参阅

import pyclesperanto_prototype as cle
import numpy as np
from skimage.io import imread
label_image = cle.gauss_otsu_labeling(imread("../../data/mitosis_mod.tif"), outline_sigma=0)
label_image
cle._ image
shape(70, 70)
dtypeuint32
size19.1 kB
min0.0
max13.0

侵蚀标签#

在侵蚀标签时,我们需要注意对象可能会分裂成两个。这可能是有意为之的,例如为了区分上面例子中接触的细胞核。

eroded_label_image = cle.erode_labels(label_image,
                                      radius=2,
                                      relabel_islands=False)
eroded_label_image
cle._ image
shape(70, 70)
dtypeuint32
size19.1 kB
min0.0
max9.0
eroded_label_image2 = cle.erode_labels(label_image,
                                      radius=2,
                                      relabel_islands=True)
eroded_label_image2
cle._ image
shape(70, 70)
dtypeuint32
size19.1 kB
min0.0
max10.0

膨胀标签#

然后我们可以再次膨胀标签,使其大致恢复到原始大小。如果分割的对象普遍太小,这也可能很有用。

dilated_label_image = cle.dilate_labels(eroded_label_image2, 
                                        radius=2)
dilated_label_image
cle._ image
shape(70, 70)
dtypeuint32
size19.1 kB
min0.0
max10.0

开运算和闭运算标签#

标签图像的开运算和闭运算与二值图像类似。唯一的区别是当标签接触时,它们不能再扩展。

请注意,开运算标签可能会使小标签消失。

opened_label_image = cle.opening_labels(label_image,
                                        radius=2)
opened_label_image
cle._ image
shape(70, 70)
dtypeuint32
size19.1 kB
min0.0
max9.0
closed_label_image = cle.closing_labels(label_image,
                                        radius=2)
closed_label_image
cle._ image
shape(70, 70)
dtypeuint32
size19.1 kB
min0.0
max13.0

练习#

使用上面介绍的操作,使这个标签图像中的小对象消失。

label_blobs = cle.asarray(imread("../../data/blobs_labeled.tif")).astype(np.uint32)
label_blobs
cle._ image
shape(254, 256)
dtypeuint32
size254.0 kB
min0.0
max63.0