threshold_multiotsu永远不会加载

问题描述

现在我正在尝试使用skimage.filters.threshold_multiotsu方法将n个点过滤到k个组中。要找到将组划分的阈值,我正在做

arr=np.asarray([93,86,164,234,310,384,461,538,610,167,245,311,394,470,544,620])
thresholds = threshold_multiotsu(arr,classes=8,nbins=32)

即使经过一分钟的等待,它最终也永远不会加载。有人有解决这个问题的想法吗?

解决方法

尽管threshold_multiotsu可以指定任意数量的类,但是如果您查看documentation中的“ Notes”部分,它会指定复杂度随类的数量呈指数增长。这是我针对2、3和4个班级的计时结果:

In [6]: %timeit threshold_multiotsu(arr,classes=2,nbins=32)
174 µs ± 1.35 µs per loop (mean ± std. dev. of 7 runs,10000 loops each)

In [7]: %timeit threshold_multiotsu(arr,classes=3,nbins=32)
5 ms ± 98.1 µs per loop (mean ± std. dev. of 7 runs,100 loops each)

In [8]: %timeit threshold_multiotsu(arr,classes=4,nbins=32)
873 ms ± 10.9 ms per loop (mean ± std. dev. of 7 runs,1 loop each)

这是读者的练习,它使指数适合这三个点并计算出classes=8的值,但是如果我们每次将增加量近似为100倍,我将获得1100天以上的运行时间。 (classes=5仍在为我运行。)

换句话说,如果k> 4,threshold_multiotsu对您来说是错误的工具。我可能会建议您使用kmeans之类的算法来解决您的问题!

相关问答

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