Mercurial > rlm
view src/rlm/vision.clj @ 0:78a630e650d2
initial import
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 18 Oct 2011 00:57:08 -0700 |
parents | |
children |
line wrap: on
line source
1 (ns rlm.vision2 (:use [clojure.contrib def trace])3 (:use [rlm image-utils])4 (:use [cantor])5 (:import java.awt.image.BufferedImage6 [ij ImagePlus IJ]8 ))10 (defn select-last [& args]11 (last args))14 ;this is to finally get these stupid color problems out of the way!16 (defmulti gen-color (fn [& args]17 (class (last args))))22 (defmethod gen-color (class 5)23 ([r g b]24 (gen-color (vector r g b 255)))25 ([r g b a]26 (gen-color (vector r g b a))))28 (defmethod gen-color (class :black)29 [key]30 (get {:black (gen-color {:r 0 :g 0 :b 0})31 :white (gen-color {:r 255 :g 255 :b 255})}32 key33 (gen-color {:r 0 :g 0 :b 0})))35 (defmethod gen-color (class [5 10 255 50])36 [[r g b a]]37 (gen-color {:r r :g g :b b :a a}))39 (defmethod gen-color (class {:r 5 :g 10 :b 255 :a 50})40 [{:keys [r g b a] :or {r 0 g 0 b 0 a 255}}]41 (let [r (int (rem r 256))42 g (int (rem g 256))43 b (int (rem b 256))44 a (int (rem a 256))45 ]46 (+47 (bit-shift-left a 24)48 (bit-shift-left r 16)49 (bit-shift-left g 8)50 b)))52 (def color (memoize gen-color))57 (defn black-lattice [x y]58 (if (and59 (< (rem y 500) 10)60 (< (rem x 500) 10)) (color :black) (color :white)))64 (defn snake-problem-2 [x y]65 (let [E (+ 4 (* 3 (java.lang.Math/cos x)) (java.lang.Math/cos (* 3 x)))66 E (int (* E 255/9))]68 (color E E E)))72 (defn function->image [[xmin xmax] [ymin ymax] f]73 (let [width (- xmax xmin)74 height (- ymax ymin)75 image (BufferedImage. width height BufferedImage/TYPE_INT_RGB)]77 (doall78 (for [y (range ymin ymax) x (range xmin xmax)]79 (.setRGB image (- x xmin) (- y ymin) (f x y))))81 (ImagePlus. "functionally-generated" image)))83 (defn better-function->image [[xmin xmax] [ymin ymax] f]85 (let [width (- xmax xmin)86 height (- ymax ymin)87 image (BufferedImage. width height BufferedImage/TYPE_INT_RGB)88 set-color (fn [[x y]] (.setRGB image (- x xmin) (- y ymin) (f x y)))89 domain (for [x (range xmin xmax) y (range ymin ymax)] [x y])]91 (dorun (pmap set-color domain))92 (ImagePlus. "functionally-generated" image)))98 (def a-face (normalize (cross99 (vec3 1 0 0)100 (sub101 (vec3 0 0 (/ (* 2 (expt 3 1/2))))102 (vec3 (/ (- (sqrt 3)) 2) (- 1/2) 0)))))104 (def c-face (mul (normalize (cross105 (vec3 (/ (sqrt 3) 2) 3/2 0)106 (sub107 (vec3 0 0 (/ (* 2 (expt 3 1/2))))108 (vec3 (/ (- (sqrt 3)) 2) (- 1/2) 0)))) -1))111 (def b-face (mul (normalize112 (cross113 (vec3 (/ (sqrt 3) 2) (- 3/2) 0)114 (sub115 (vec3 0 0 (/ (* 2 (expt 3 1/2))))116 (vec3 (/ (sqrt 3) 2) (- 1/2) 0)))) -1))