在GIMP UI中,有一个应用阈值功能(GIMP 2.6),它具有一个名为Auto的选项。这会自动为图像计算适当的下限阈值。该功能/选项是否可用于插件? gimp-threshold和gimp-histogram函数似乎没有这个选项。gimp脚本中的自动阈值功能-fu
回答
这是我最终使用的解决方案。仅适用于灰度图像。其相同的算法作为gimp_histogram_get_threshold功能gimphistogram.c
http://git.gnome.org/browse/gimp/tree/app/base/gimphistogram.c
(define (auto-threshold imagePath)
(let*
(
(theImage (car (gimp-file-load
RUN-NONINTERACTIVE
imagePath
imagePath
)
)
)
(theDrawable (car (gimp-image-get-active-drawable theImage)))
(hist (get-hist theDrawable 0))
)
(get-auto-threshold hist)
)
)
;returns the threshold
(define (get-auto-threshold hist)
(let*
(
(hist_max (vector-ref hist 0))
(chist (make-vector 256))
(cmom (make-vector 256))
(maxval 255) ;end - start
(i 1)
(tmp)
(chist_max)
(cmom_max)
(bvar_max 0)
(threshold 127)
)
(vector-set! chist 0 (vector-ref hist 0))
(vector-set! cmom 0 0)
(set! i 1)
(while (<= i maxval)
(if (> (vector-ref hist i) hist_max)
(set! hist_max (vector-ref hist i))
)
(vector-set! chist i (+ (vector-ref chist (- i 1)) (vector-ref hist i)))
(vector-set! cmom i (+ (vector-ref cmom (- i 1)) (* i (vector-ref hist i))))
(set! i (+ i 1))
)
(set! chist_max (vector-ref chist maxval))
(set! cmom_max (vector-ref cmom maxval))
(set! i 0)
(while (< i maxval)
(if (and (> (vector-ref chist i) 0) (< (vector-ref chist i) chist_max))
(let*
((bvar (/ (vector-ref cmom i) (vector-ref chist i))))
(set! bvar (- bvar (/ (- cmom_max (vector-ref cmom i)) (- chist_max (vector-ref chist i)))))
(set! bvar (* bvar bvar))
(set! bvar (* bvar (vector-ref chist i)))
(set! bvar (* bvar (- chist_max (vector-ref chist i))))
(if (> bvar bvar_max)
(begin
(set! threshold i)
(set! bvar_max bvar)
)
)
)
)
(set! i (+ i 1))
)
threshold
)
)
;returns the raw histogram with values 0-1 as an array
(define (get-hist drawable chan)
(let* (
(i 0)
(hist (make-vector 256))
)
(set! i 0)
(while (< i 256)
(vector-set! hist i (car (cddddr (gimp-histogram drawable chan i i))))
(set! i (+ i 1))
)
hist
)
)
不幸的是,从GIMP版本2.6开始,此功能不会暴露给程序数据库(API),因此无法在脚本-fu或Python脚本中使用。
是的,我来到了同样的结论。但我搜索了GIMP源代码,并在gimphistogram.c中看到了这个函数gimp_histogram_get_threshold,这看起来可以做到这一切。我试图将该算法转换为脚本。但是,对Scheme的不熟悉会让我放慢脚步。尽快尝试并发布解决方案。 – aldrin
我最近查找了这个函数,并决定不要试图在script-fu中实现它。我将它留给用户,将自动按钮从阈值对话框计算的值复制到脚本的参数对话框中,叹息一声。如果你想出可用的代码,我肯定我不是唯一可以使用它的人。最佳阈值是一种基本的图像处理技术。 – mgkrebbs
@aldrin:我以前实际上已经在PDB中添加了一些缺失的条目 - 感谢您的研究 - 可能很难及时将其添加到GIMP 2.8中(应该在几周内完成) – jsbueno
- 1. GIMP Python-Fu脚本不能运行超过4个参数
- 2. 在Gimp script-fu中,如何访问QuickMask功能?
- 3. 在Gimp脚本中替换字符串Fu
- 4. 自动功能脚本
- 5. Bash脚本添加日期阈值到S3`cp`功能
- 6. GIMP script-fu改变编辑器UI
- 7. fail2ban自定义脚本启动功能
- 8. 如何获取自动阈值使用的阈值插件
- 9. 此方案/ script-fu/gimp代码中的错误是什么?
- 10. 你如何用Python-fu在Gimp中描绘一个中风?
- 11. jenkins阈值插件shell脚本
- 12. 如何在Python脚本中使用GIMP?
- 13. 从GIMP中选择删除透明像素(Script-Fu)
- 14. 使用python-fu在Gimp中统一缩放图像层
- 15. cognos性能阈值
- 16. 问题有关的简单GIMP脚本
- 17. Python的福GIMP脚本不糊图像
- 18. GIMP Script-FU - 错误:没有足够的参数
- 19. 用于自动插入功能的Vim脚本
- 20. 有bash的自动完成功能从python脚本
- 21. 自动化的DDL脚本:预测多少功能?
- 22. 在emgu cv中查找otsu阈值的功能是什么?
- 23. TensorFlow中的硬限制/阈值激活功能
- 24. OpenCV中的自适应阈值(版本1 - swig版本)
- 25. 功能来确定组合的值是小于一个阈值
- 26. 使用自动阈值分割
- 27. 动作脚本睡眠功能
- 28. Flash动作脚本3功能范围
- 29. Python动态脚本转换功能
- 30. GIMP,python-fu:如何禁用“输入图像”和“输入绘制”
正是我在找的,谢谢。我必须将get-hist的chan参数更改为5,即GIMP_HISTOGRAM_RGB以使其与UI中调用的值相匹配。 –