Search code examples
clojurescientific-computing

What's the best way to process an image in clojure?


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?


Solution

  • 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