当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python skimage.measure.profile_line用法及代码示例


用法:

skimage.measure.profile_line(image, src, dst, linewidth=1, order=None, mode='reflect', cval=0.0, *, reduce_func=<function mean>)

返回沿扫描线测量的图像的强度分布。

参数

imagendarray,形状(M,N[,C])

图像,灰度(2D 阵列)或多通道(3D 阵列,其中最后一个轴包含通道信息)。

src数组, 形状 (2, )

扫描线起点的坐标。

dst数组, 形状 (2, )

扫描线终点的坐标。与标准 numpy 索引相比,目标点包含在配置文件中。

linewidthint 可选

扫描的宽度,垂直于线

orderint in {0, 1, 2, 3, 4, 5},可选

样条插值的顺序,如果 image.dtype 为 bool 则默认为 0,否则为 1。顺序必须在 0-5 范围内。有关详细信息,请参阅 skimage.transform.warp

mode{‘constant’, ‘nearest’, ‘reflect’, ‘mirror’, ‘wrap’},可选

如何计算图像之外的任何值。

cval浮点数,可选

如果模式是‘constant’,在图像外使用什么常量值。

reduce_func可调用的,可选的

当 linewidth > 1 时,用于计算垂直于profile_line 方向的像素值聚合的函数。如果设置为 None,将返回未归约的数组。

返回

return_value数组

沿扫描线的强度分布。轮廓的长度是计算出的扫描线长度的上限。

例子

>>> x = np.array([[1, 1, 1, 2, 2, 2]])
>>> img = np.vstack([np.zeros_like(x), x, x, x, np.zeros_like(x)])
>>> img
array([[0, 0, 0, 0, 0, 0],
       [1, 1, 1, 2, 2, 2],
       [1, 1, 1, 2, 2, 2],
       [1, 1, 1, 2, 2, 2],
       [0, 0, 0, 0, 0, 0]])
>>> profile_line(img, (2, 1), (2, 4))
array([1., 1., 2., 2.])
>>> profile_line(img, (1, 0), (1, 6), cval=4)
array([1., 1., 1., 2., 2., 2., 2.])

与标准 numpy 索引相比,目标点包含在配置文件中。例如:

>>> profile_line(img, (1, 0), (1, 6))  # The final point is out of bounds
array([1., 1., 1., 2., 2., 2., 2.])
>>> profile_line(img, (1, 0), (1, 5))  # This accesses the full first row
array([1., 1., 1., 2., 2., 2.])

对于不同的 reduce_func 输入:

>>> profile_line(img, (1, 0), (1, 3), linewidth=3, reduce_func=np.mean)
array([0.66666667, 0.66666667, 0.66666667, 1.33333333])
>>> profile_line(img, (1, 0), (1, 3), linewidth=3, reduce_func=np.max)
array([1, 1, 1, 2])
>>> profile_line(img, (1, 0), (1, 3), linewidth=3, reduce_func=np.sum)
array([2, 2, 2, 4])

当reduce_func 为 None 或当reduce_func 单独作用于每个像素值时,将返回未归约的数组。

>>> profile_line(img, (1, 2), (4, 2), linewidth=3, order=0,
...     reduce_func=None)
array([[1, 1, 2],
       [1, 1, 2],
       [1, 1, 2],
       [0, 0, 0]])
>>> profile_line(img, (1, 0), (1, 3), linewidth=3, reduce_func=np.sqrt)
array([[1.        , 1.        , 0.        ],
       [1.        , 1.        , 0.        ],
       [1.        , 1.        , 0.        ],
       [1.41421356, 1.41421356, 0.        ]])

相关用法


注:本文由纯净天空筛选整理自scikit-image.org大神的英文原创作品 skimage.measure.profile_line。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。