BasicConvolveOp - Serabe/rinzelight GitHub Wiki

Basic convolve operators

In rinzelight.effects.convolve.ops you can find bassic support for convolve operators.

Since Java doesn’t allow using your own, rinzelight convolve operators must expand the image.

Introducing convolve operators.

A convolve operator is a function that, given an image and a kernel, returns an expanded image. It is defined using either convolve-op or convolve-op-by-location.

Using convolve-op

convolve-op expects a name for the operator, a vector containing symbols for the image and the kernel and the body that will be executed.

Inside the body, you have the image and the _kernel available but for getting and setting pixels you must use set-to-new-image and get-from-image. Since the images diffe, you need to use some help from auxiliar methods like helper-image-size and orig-img-starting-pixel.

Every convolve operator in rinzelight is implemented using this macro, look at the source code if you want a few examples of how it is used.

Using convolve-op-by-location

This macro only accepts two parameters: the name for the convolve operator and a function. The function, given the original image and the kernel, must return a function that maps the location of a pixel in the new image to a location in the original image.

For example, the function for creating a repeat-op with this macro is:

(defn repeat-fn [img kern] (let [[w h] (helper-image-size img kern) [ix iy] (orig-img-starting-pixel kern) iw (:width img) max-w (dec iw) ih (:height img) max-h (dec ih) right-x (+ ix iw) bot-y (+ iy ih) f-x (fn [x] (cond (< x ix) 0 (>= x right-x) max-w :else (- x ix))) f-y (fn [y] (cond (< y iy) 0 (>= y bot-y) max-h :else (- y iy)))] (fn [x y] [(f-x x) (f-y y)])))

Consider this option just for prototyping, since it is five times slower than convolve op for original repeat-op.

Convolve operators.

zero-fill-op

Fills the extra space with black pixels.


repeat-op

Repeat the borders.


thorus-op

Considers the image as a thorus when expanding the image.


⚠️ **GitHub.com Fallback** ⚠️