在 scikit-image 中使用分水岭

问题描述

说明

分水岭函数产生了一个意想不到的结果:它似乎无法对我的数组进行分段,尽管我希望它能做到。

我的例子

from skimage.segmentation import watershed
import numpy as np
myarray = np.array([
       [ 2.50148667,9.44388663,3.44389182,3.02727774,2.40108087,1.61053155,0.82294687],[ 3.31356207,10.55797911,4.69412493,4.41801194,3.80963218,2.70408164,1.35735552],[ 3.28787642,4.59215029,4.97735914,11.08993154,4.7925308,9.6116032,1.79749649],[ 2.87281939,4.15976317,4.70572275,10.95797537,4.73970551,9.56800396,1.7571604 ],[ 1.98065752,2.97293194,3.42830952,3.56329229,3.27749856,2.33718172,1.1267278 ]])
isLocalMaxArray = np.array([
       [False,False,False],[False,True,False]])
watershed(-myarray,isLocalMaxArray,watershed_line=True)

生产

array([
       [1,1,1],[1,1]],dtype=int32)

正如我所料

array([
       [1,3,2,2],2]],dtype=int32)

问题

我做错了什么?

版本信息

from __future__ import print_function
import sys; print(sys.version)
import platform; print(platform.platform())
import skimage; print("scikit-image version: {}".format(skimage.__version__))
import numpy; print("numpy version: {}".format(numpy.__version__))

3.8.8(默认,2021 年 2 月 24 日,21:46:12)

[海湾合作委员会 7.3.0]

Linux-5.4.0-67-generic-x86_64-with-glibc2.10

scikit-image 版本:0.17.2

numpy 版本:1.19.2

解决方法

仅仅提供某个位置是否有峰是不够的,而是提供一个表明哪些峰属于一起的标签。这可以通过 skimage.measure.label:

完成
from skimage import measure
watershed(-myarray,measure.label(isLocalMaxArray,background=0),watershed_line=True)

或者 scipy.ndimage.label 可用于具有 3 个以上维度的图像。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...