Subscribe RSS

Posts Tagged ‘clojure’

A minimal ImageJ Plugin in Clojure: image inversion

January 15th, 2010 by fmn | 3 Comments | Filed in Enseignement, Research

I show in this post how to write an ImageJ plugin with Clojure. This example is taken from Digital Image Processing: An Algorithmic Introduction Using Java: an image inversion (page 32).

The goal is to invert all the pixels of a 8-bit grayscale image, turning an image into its negative. As a pixel value is coded with 8 bits, the higher possible value is 255. The operation is thus to transform each pixel value v into 255-v.

I first present the plugin in Java, with a description of the essentials elements of an ImageJ plugin. Then, i give several Clojure versions. The last is as fast as the Java one, but more reusable.

(more…)

Tags: , , , , , , , ,

Clojure functions with meta-data. Image representation #3

October 20th, 2009 by fmn | No Comments | Filed in Enseignement, Research

Previously on Pixel Shaker : an image is a bounded function that can be coded as a Java-class. This Java-class involves a lots codelines, even in Clojure. Today is an exploration of this concept in a more idiomatic way.

A bounded function is a function with an additional information : its definition domain. Clojure provides an handy way to deals with extra data : the metadata. The metadata is a map of data that can be added using the with-meta function. Let’s try to add a definition domain as a metadata :

user> (defn indom? [dom pt]
        (let [[start end] dom
              [x y] pt]
          (and (>= x (first start))
               (<= x (first end))
               (>= y (second start))
               (<= y (second end)))))
#'user/indom?
user> (defn f [x y] (+ x y))
#'user/f
user> (def dom [[0 0] [4 4]])
#'user/dom
user> (def bf (with-meta f {:domain dom}))
java.lang.UnsupportedOperationException (NO_SOURCE_FILE:10)

(more…)

Tags: , , ,

Image representation (Clojure and Java) #2

October 14th, 2009 by fmn | No Comments | Filed in Enseignement, Research

Last time was given an image representation as a bounded function (see this post). This java class was completely written in Clojure. This representation is the equivament of an image from a mathematical view. It is not very efficient. Usually an image is stored as a 2-d array. This data structure allows short access time to the pixel values.

So, in java with ImageJ, an image is an abstract class named ImageProcessor. Four concretes implementation are proposed : ByteProcessor, ShortProcessor, FloatProcessor et ColorProcessor (see api). As previously discussed on this blog, the drawback of these kind of representation is the difficulty to handle negative negatives coordinates.

This post is thus devoted to an image representation based on an ImageProcessor, but allowing negatives coordinates. The proposed class Image is heriting from previous class Imfun.

Tags: , , , , ,