首页 > 解决方案 > 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)

即使等待一分钟,这最终也不会加载。有没有人有一些想法来解决这个问题?

标签: pythonnumpyimage-processingscikit-image

解决方案


尽管threshold_multiotsu编写时可以指定任意数量的类,但如果您查看文档中的注释部分,它会指定复杂性随着类的数量呈指数增长。这是我的 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仍在为我运行。)

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


推荐阅读