Python 3.x 中的 "bwlabeln (with 18 and 26-connected neighborhood)" 是什么?
What is equivalent to "bwlabeln (with 18 and 26-connected neighborhood)" in Python 3.x?
我已经使用 Matlab 的 bwlabeln
进行三维连接,18-connected neighborhood
如下代码:
[labeledImage, ~] = bwlabeln(maskImageVolume, 18); # maskImageVolume is 3D. e.g.:(200, 200, 126)
在Python中的等价物是:
from skimage import measure
labeledImage = measure.label(maskImageVolume, 8)
然而,bwlabeln
在 Matlab 中支持 Three-dimensional connectives
(具有 18 和 26 连接的邻域)但 skimage.measure.label
仅支持 4- or 8-“connectivity”
。
Python 中 18 and 26-connected neighborhood
的 bwlabeln
等价于什么?
skimage.measure.label
的文档指出参数 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.
对于参数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.
这意味着,在 3D 中,连通性可以是 1、2 或 3,表示 6、18 或 26 个邻居。
翻看各个版本的文档,好像scikit-image 0.11就引入了这种语法(0.10没有)。
对于您的案例,有 18 个相连的邻居:
labeledImage = measure.label(maskImageVolume, connectivity=2)
我已经使用 Matlab 的 bwlabeln
进行三维连接,18-connected neighborhood
如下代码:
[labeledImage, ~] = bwlabeln(maskImageVolume, 18); # maskImageVolume is 3D. e.g.:(200, 200, 126)
在Python中的等价物是:
from skimage import measure
labeledImage = measure.label(maskImageVolume, 8)
然而,bwlabeln
在 Matlab 中支持 Three-dimensional connectives
(具有 18 和 26 连接的邻域)但 skimage.measure.label
仅支持 4- or 8-“connectivity”
。
Python 中 18 and 26-connected neighborhood
的 bwlabeln
等价于什么?
skimage.measure.label
的文档指出参数 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, useconnectivity
instead.
对于参数connectivity
:
connectivity : int, optional
Maximum number of orthogonal hops to consider a pixel/voxel as a neighbor. Accepted values are ranging from 1 toinput.ndim
. IfNone
, a full connectivity ofinput.ndim
is used.
这意味着,在 3D 中,连通性可以是 1、2 或 3,表示 6、18 或 26 个邻居。
翻看各个版本的文档,好像scikit-image 0.11就引入了这种语法(0.10没有)。
对于您的案例,有 18 个相连的邻居:
labeledImage = measure.label(maskImageVolume, connectivity=2)