As part of a python simulation I have I take a 2d array and take the gradient of this array. This is done in scipy/numpy by convolving the 2d array with a filter with the appropriate weights.
So my question is if I want to do this in clojure reasonably fast does it make sense to do this in pure clojure, or is it better to use a Java image processing library and call into it from clojure?
A well optimized loop in Clojure will have performance close to Java code.
I will advise using either the primitive vectors or directly arrays from clojure to get very good performance.
I have read a blogpost on the subject: http://www.bestinclass.dk/index.clj/2010/03/functional-fluid-dynamics-in-clojure.html
The good process is to start with code that is clear and works and tweek in for perfomance afterwards.
Often, performance in Clojure revolves around getting rid of reflection and using primitives. This is explained here: http://clojure.org/java_interop
You can use Java image processing libraries from Clojure. Here is something to get started.
(defn getPixels [^BufferedImage image] (-> image .getRaster .getDataBuffer .getData))
I don't know if this will compile(some help I am) I just translated it from some Scala code of mine in my head.
http://clojure.org/java_interop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With