python - 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
编写时可以指定任意数量的类,但如果您查看文档中的注释部分,它会指定复杂性随着类的数量呈指数增长。这是我的 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之类的算法!
推荐阅读
- javascript - 无法在字符串上创建属性“onload”
- python - pygame:我想计算玩家精灵和敌人1之间的距离
- sql-server - SQL server: 将数据库从 LINUX 版本复制到 Win 版本
- android - 为什么我在创建 Intent 时会出现此错误,并且必须从第二个屏幕上 RecyclerView 中的 Firebase 传递数据
- angular - Angular Services:Promise 返回奇怪的结果
- cofoundry - 如何使用 Cofoundry 在程序集中嵌入视图文件
- javascript - JavaScript 中无法解释的浮点除法行为
- php - 使用 Simplesamlphp 在 AuthnRequest 中为 Extensions 标签添加命名空间
- r - 如何在 R 中使用 xpath 获得评论
- python - 获取树线输入