【问题标题】:is there a way in gimp to find points on the layer?有没有办法在 gimp 中找到图层上的点?
【发布时间】:2013-10-20 19:48:01
【问题描述】:

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

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

【问题讨论】:

    标签: gimp script-fu python-fu


    【解决方案1】:

    我认为在 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 或其他可编译语言的外部程序进行计算。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-30
      • 2019-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-16
      相关资源
      最近更新 更多