だから私はclojureで基本的な画像処理を行ってきました(RGBをグレースケールに変換するだけです)、amapに深刻な問題があります。つまり、私はそれを速くすることができません。
型ヒントで21000ミリ秒から8000ミリ秒程度まで下げることができましたが、それだけです。対照的に、法線マップは約 400ms で実行されます...
このような単純な操作をできるだけ速くするために、他にできることはありますか?
(defn setpxl [^BufferedImage image data]
(let [h (.getHeight image)
w (.getWidth image)]
(.setRGB image 0 0 w h ^ints data 0 w)
) )
(defn getrgb [rgb]
(let [r (bit-shift-right (bit-and rgb (int 0x00FF0000)) 16)
g (bit-shift-right (bit-and rgb (int 0x0000FF00)) 8)
b (bit-and rgb (int 0x000000FF))]
[r g b])
)
(defn graycalc [[r g b]]
(let [gray (int (/ (+ r g b) 3))
r (bit-shift-left gray 16)
g (bit-shift-left gray 8)
b gray
a (bit-shift-left 0x00 24)
]
(int (bit-or a r g b))))
(defn testrgb []
(let [img (time (javax.imageio.ImageIO/read (as-file "D:/cat.jpg")))
h (.getHeight img)
w (.getWidth img)
arr (time (int-array (getpxl img)))
gray (time
;;why is amap so slow?
;;400ms
(int-array (map #(graycalc (getrgb %1)) arr))
;;8000ms
;; (amap ^ints arr idx ret (graycalc (getrgb (aget ^ints arr idx))))
)
frame (JFrame. "grayscale image")
label (JLabel. (ImageIcon. img))
panel (.getContentPane frame)]
(-> panel (.add label))
(.setSize frame w h)
(.setVisible frame true)
(time (setpxl img gray))
(.repaint panel)
)
)