在gimp中有没有办法在图层上找到点?

时间:2013-10-20 19:48:02

标签: gimp script-fu python-fu

假设我有一个带有多个点的图像(如附件中所示)。有没有办法让脚本找到这些点并给我一个数组呢?

我想我可以通过图像处理来做到这一点,但我希望有一个脚本可以做到这一点。 attached file

1 个答案:

答案 0 :(得分:0)

我不认为在Script-Fu中这样做是个好主意。使用Script-Fu迭代像素非常慢,因为它涉及为每个像素分配数组和列表的开销。

我已经快速编写脚本来执行此操作,但速度非常慢 - 我的计算机上需要大约5分钟才能生成图像:

; Returns an array of cons pairs
(define (count-points image)
  (let* ((duplicate (car (gimp-image-duplicate image)))
     (layer (car (gimp-image-flatten duplicate)))
     (width (car (gimp-image-width duplicate)))
     (heigth (car (gimp-image-height duplicate))))
    (display (gimp-drawable-is-gray layer)) (newline)
    (if (not (equal? (car (gimp-drawable-is-gray layer)) 1))
      (gimp-image-convert-grayscale duplicate))
    (plug-in-blur 0 duplicate layer)
    (gimp-threshold layer 0 127)
    (let loop ((x 0) (y 0) (result '()))
      (if (>= y heigth)
      result
      (if (>= x width)
          (loop 0 (+ y 1) result)
          (loop (+ x 1)
            y
            (let ((vals (cadr (gimp-drawable-get-pixel layer x y))))
              (if (< (aref vals 0) 127)
              result
              (cons (cons x y) result)))))))))

;; Call in Script-Fu Console like this (to calculate points
;; of the last image opened/created):
;; 
;;   (let ((imgs (gimp-image-list)))
;;     (count-points (vector-ref (cadr imgs) 0)))

我建议将图像导出(模糊并使用之前的treschold)到某些哑格式,如PGB / PBM,然后使用C或其他可编译语言的外部程序进行计算。

相关问题