def blob_labels(centers_of_mass, blob_image):
"""
label nuclei with segmentation - so labels are in the same order as the outer layer
:param list centers_of_mass: centers of target blobs/cells
:param np.array blob_image: image of the target cells, or nuclei of cells
:return segmented_blobs: a labelled image where each index is a different cell
:return distance: image where each pixel's value is related to how far away from a blob center it is
"""
image = np.abs(blob_image-1)
distance = ndimage.distance_transform_edt(np.abs(image-1))
local_maxi = np.zeros_like(image)
for c in centers_of_mass:
local_maxi[int(c[0]), int(c[1])] = 1
markers = ndimage.label(local_maxi)[0]
segmented_blobs = segmentation.random_walker(distance, markers, beta=20)
return segmented_blobs, distance
评论列表
文章目录