def cells_voxel_layer(self, labels, region_boundingbox = False, single_frame = False):
"""
This function extract the first layer of voxel surrounding a cell defined by `label`
Args:
label: (int|list) - cell-label for which we want to extract the first layer of voxel;
region_boundingbox: (bool) - if True, consider a boundingbox surrounding all labels, instead of each label alone.
single_frame: (bool) - if True, return only one array with all voxels position defining cell walls.
:Output:
returns a binary image: 1 where the cell-label of interest is, 0 elsewhere
"""
if isinstance(labels,int):
labels = [labels]
if single_frame:
region_boundingbox=True
if not isinstance(region_boundingbox,bool):
if sum([isinstance(s,slice) for s in region_boundingbox])==3:
bbox = region_boundingbox
else:
print "TypeError: Wong type for 'region_boundingbox', should either be bool or la tuple of slices"
return None
elif isinstance(region_boundingbox,bool) and region_boundingbox:
bbox = self.region_boundingbox(labels)
else:
bboxes = self.boundingbox(labels, real=False)
# Generate the smaller eroding structure possible:
struct = nd.generate_binary_structure(3, 2)
if single_frame:
vox_layer = np.zeros_like(self.image[bbox], dtype=int)
else:
vox_layer = {}
for clabel in labels:
if region_boundingbox:
bbox_im = self.image[bbox]
else:
bbox_im = self.image[bboxes[clabel]]
# Creating a mask (1 where the cell-label of interest is, 0 elsewhere):
mask_bbox_im = (bbox_im == clabel)
# Erode the cell using the structure:
eroded_mask_bbox_im = nd.binary_erosion(mask_bbox_im, structure=struct)
if single_frame:
vox_layer += np.array(mask_bbox_im - eroded_mask_bbox_im, dtype=int)
else:
vox_layer[clabel] = np.array(mask_bbox_im - eroded_mask_bbox_im, dtype=int)
if len(labels)==1:
return vox_layer[clabel]
else:
return vox_layer
spatial_image_analysis.py 文件源码
python
阅读 28
收藏 0
点赞 0
评论 0
评论列表
文章目录