def wall_voxels_between_two_cells(self, label_1, label_2, bbox=None, verbose=False):
"""
Return the voxels coordinates defining the contact wall between two labels.
Args:
image: (ndarray of ints) - Array containing objects defined by labels
label_1: (int) - object id #1
label_2: (int) - object id #2
bbox: (dict, optional) - If given, contain a dict of slices
Returns:
- xyz 3xN array.
"""
if bbox is not None:
if isinstance(bbox, dict):
label_1, label_2 = sort_boundingbox(bbox, label_1, label_2)
boundingbox = bbox[label_1]
elif isinstance(bbox, tuple) and len(bbox)==3:
boundingbox = bbox
else:
try:
boundingbox = find_smallest_boundingbox(self.image, label_1, label_2)
except:
print "Could neither use the provided value of `bbox`, nor gess it!"
boundingbox = tuple([(0,s-1,None) for s in self.image.shape])
dilated_bbox = dilation( boundingbox )
dilated_bbox_img = self.image[dilated_bbox]
else:
try:
boundingbox = find_smallest_boundingbox(self.image, label_1, label_2)
except:
dilated_bbox_img = self.image
mask_img_1 = (dilated_bbox_img == label_1)
mask_img_2 = (dilated_bbox_img == label_2)
struct = nd.generate_binary_structure(3, 2)
dil_1 = nd.binary_dilation(mask_img_1, structure=struct)
dil_2 = nd.binary_dilation(mask_img_2, structure=struct)
x,y,z = np.where( ( (dil_1 & mask_img_2) | (dil_2 & mask_img_1) ) == 1 )
if bbox is not None:
return np.array( (x+dilated_bbox[0].start, y+dilated_bbox[1].start, z+dilated_bbox[2].start) )
else:
return np.array( (x, y, z) )
spatial_image_analysis.py 文件源码
python
阅读 26
收藏 0
点赞 0
评论 0
评论列表
文章目录