def signed_distance_transform(pmap, pmin, minMembraneSize, out_debug_image_dict, ppitch = None):
"""
Performs a threshold on the given image 'pmap' > pmin, and performs
a distance transform to the threshold region border for all pixels outside the
threshold boundaries (positive distances) and also all pixels *inside*
the boundary (negative distances).
The result is a signed float32 image.
"""
# get the thresholded pmap
binary_membranes = (pmap >= pmin).view(numpy.uint8)
# delete small CCs
labeled = vigra.analysis.labelMultiArrayWithBackground(binary_membranes)
save_debug_image('thresholded membranes', labeled, out_debug_image_dict)
del binary_membranes
remove_wrongly_sized_connected_components(labeled, minMembraneSize, in_place=True)
save_debug_image('filtered membranes', labeled, out_debug_image_dict)
# perform signed dt on mask
logger.debug("positive distance transform...")
if ppitch != None:
distance_to_membrane = vigra.filters.distanceTransform(labeled, pixel_pitch = ppitch)
else:
distance_to_membrane = vigra.filters.distanceTransform(labeled)
# Save RAM with a sneaky trick:
# Use distanceTransform in-place, despite the fact that the input and output don't have the same types!
# (We can just cast labeled as a float32, since uint32 and float32 are the same size.)
logger.debug("negative distance transform...")
distance_to_nonmembrane = labeled.view(numpy.float32)
if ppitch != None:
vigra.filters.distanceTransform(labeled, background=False, out=distance_to_nonmembrane, pixel_pitch = ppitch)
else:
vigra.filters.distanceTransform(labeled, background=False, out=distance_to_nonmembrane, pixel_pitch = ppitch)
del labeled # Delete this name, not the array
# Combine the inner/outer distance transforms
distance_to_nonmembrane[distance_to_nonmembrane>0] -= 1
distance_to_membrane[:] -= distance_to_nonmembrane
save_debug_image('distance transform', distance_to_membrane, out_debug_image_dict)
return distance_to_membrane
wsDtSegmentation.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录