Mercurial > rlm
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:78a630e650d2 |
---|---|
1 (ns rlm.vision | |
2 (:use [clojure.contrib def trace]) | |
3 (:use [rlm image-utils]) | |
4 (:use [cantor]) | |
5 (:import java.awt.image.BufferedImage | |
6 [ij ImagePlus IJ] | |
7 | |
8 )) | |
9 | |
10 (defn select-last [& args] | |
11 (last args)) | |
12 | |
13 | |
14 ;this is to finally get these stupid color problems out of the way! | |
15 | |
16 (defmulti gen-color (fn [& args] | |
17 (class (last args)))) | |
18 | |
19 | |
20 | |
21 | |
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)))) | |
27 | |
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 key | |
33 (gen-color {:r 0 :g 0 :b 0}))) | |
34 | |
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})) | |
38 | |
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))) | |
51 | |
52 (def color (memoize gen-color)) | |
53 | |
54 | |
55 | |
56 | |
57 (defn black-lattice [x y] | |
58 (if (and | |
59 (< (rem y 500) 10) | |
60 (< (rem x 500) 10)) (color :black) (color :white))) | |
61 | |
62 | |
63 | |
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))] | |
67 | |
68 (color E E E))) | |
69 | |
70 | |
71 | |
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)] | |
76 | |
77 (doall | |
78 (for [y (range ymin ymax) x (range xmin xmax)] | |
79 (.setRGB image (- x xmin) (- y ymin) (f x y)))) | |
80 | |
81 (ImagePlus. "functionally-generated" image))) | |
82 | |
83 (defn better-function->image [[xmin xmax] [ymin ymax] f] | |
84 | |
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])] | |
90 | |
91 (dorun (pmap set-color domain)) | |
92 (ImagePlus. "functionally-generated" image))) | |
93 | |
94 | |
95 | |
96 | |
97 | |
98 (def a-face (normalize (cross | |
99 (vec3 1 0 0) | |
100 (sub | |
101 (vec3 0 0 (/ (* 2 (expt 3 1/2)))) | |
102 (vec3 (/ (- (sqrt 3)) 2) (- 1/2) 0))))) | |
103 | |
104 (def c-face (mul (normalize (cross | |
105 (vec3 (/ (sqrt 3) 2) 3/2 0) | |
106 (sub | |
107 (vec3 0 0 (/ (* 2 (expt 3 1/2)))) | |
108 (vec3 (/ (- (sqrt 3)) 2) (- 1/2) 0)))) -1)) | |
109 | |
110 | |
111 (def b-face (mul (normalize | |
112 (cross | |
113 (vec3 (/ (sqrt 3) 2) (- 3/2) 0) | |
114 (sub | |
115 (vec3 0 0 (/ (* 2 (expt 3 1/2)))) | |
116 (vec3 (/ (sqrt 3) 2) (- 1/2) 0)))) -1)) |