首页 > 解决方案 > 什么相当于 Python 3.x 中的“bwlabeln(具有 18 和 26 连接的邻域)”?

问题描述

标签: pythonmatlabscikit-image

解决方案


The documentation to skimage.measure.label states for parameter neighbors:

neighbors : {4, 8}, int, optional
Whether to use 4- or 8-“connectivity”. In 3D, 4-“connectivity” means connected pixels have to share face, whereas with 8-“connectivity”, they have to share only edge or vertex.
Deprecated, use connectivity instead.

And for parameter connectivity:

connectivity : int, optional
Maximum number of orthogonal hops to consider a pixel/voxel as a neighbor. Accepted values are ranging from 1 to input.ndim. If None, a full connectivity of input.ndim is used.

What this means is that, in 3D, the connectivity can be either 1, 2 or 3, indicating 6, 18 or 26 neighbors.

Looking back through the various versions of the documentation, this syntax seems to have been introduced in scikit-image 0.11 (0.10 doesn't have it).

For your case, with 18 connected neighbors:

labeledImage = measure.label(maskImageVolume, connectivity=2) 

推荐阅读