在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批量編輯(腳本-FU/Python的-FU)
- 2. GIMP Python-Fu腳本不能運行超過4個參數
- 3. 在Gimp script-fu中,如何訪問QuickMask功能?
- 4. 在Gimp腳本中替換字符串Fu
- 5. Gimp script-fu with illegal function error
- 6. script-fu腳本無法在gimp 2.0下載入圖像
- 7. 自動功能腳本
- 8. Bash腳本添加日期閾值到S3`cp`功能
- 9. LabVIEW自動閾值
- 10. GIMP script-fu改變編輯器UI
- 11. GIMP Python-fu嵌套組圖層
- 12. fail2ban自定義腳本啓動功能
- 13. 使用GPUImageAdaptiveThresholdFilter自動閾值?
- 14. 如何獲取自動閾值使用的閾值插件
- 15. 此方案/ script-fu/gimp代碼中的錯誤是什麼?
- 16. 你如何用Python-fu在Gimp中描繪一箇中風?
- 17. 啓動.zshrc自動加載bash腳本的功能
- 18. jenkins閾值插件shell腳本
- 19. 如何在GIMP Python-fu插件中調用pdb.gimp_pencil
- 20. 從GIMP中選擇刪除透明像素(Script-Fu)
- 21. 使用python-fu在Gimp中統一縮放圖像層
- 22. 如何在Python腳本中使用GIMP?
- 23. Gimp,Script-Fu:我如何直接在顏色表中設置一個值
- 24. 帖子功能腳本:設置自定義字段的值
- 25. 帶腳本的動畫點擊功能
- 26. GIMP Script-FU - 錯誤:沒有足夠的參數
- 27. cognos性能閾值
- 28. Python的福GIMP腳本不糊圖像
- 29. 問題有關的簡單GIMP腳本
- 30. Gimp-如何在另一個腳本中使用腳本(``noise-noise``)?
正是我在找的,謝謝。我必須將get-hist的chan參數更改爲5,即GIMP_HISTOGRAM_RGB以使其與UI中調用的值相匹配。 –