Mercurial > lasercutter
comparison src/laser/rasterize.clj @ 20:6bed8ceb51a9
obtained a linear relation between output and target.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 30 Aug 2010 01:01:35 -0400 |
parents | 3b255dcd6c50 |
children | e72220627685 |
comparison
equal
deleted
inserted
replaced
19:3b255dcd6c50 | 20:6bed8ceb51a9 |
---|---|
63 ;(defn span [row] | 63 ;(defn span [row] |
64 ; (let [sorted-row (sort #(< (first %1) (first %2)) row)] | 64 ; (let [sorted-row (sort #(< (first %1) (first %2)) row)] |
65 ; (vector (first sorted-row) (last sorted-row)))) | 65 ; (vector (first sorted-row) (last sorted-row)))) |
66 | 66 |
67 | 67 |
68 | 68 (comment |
69 | |
70 (import 'org.im4java.core.ConvertCmd) | |
71 (import 'org.im4java.core.IMOperation) | |
72 (import 'org.im4java.core.Stream2BufferedImage) | |
73 | |
74 (def target (.getBufferedImage (ImagePlus. sing))) | |
75 (def shiv (IMOperation.)) | |
76 (.addImage shiv) | |
77 (.addImage shiv (into-array String ["png:-"])) | |
78 (def conv-shiv (ConvertCmd.)) | |
79 (def s2b (Stream2BufferedImage.)) | |
80 (.setOutputConsumer conv-shiv s2b) | |
81 (.run conv-shiv shiv (into-array Object [target])) | |
82 (def result (.getImage s2b )) | |
83 | |
84 ) | |
85 | |
86 (defn mirror [#^ImagePlus img] | |
87 (let [title (.getTitle img) | |
88 target (.getBufferedImage img) | |
89 s2b (Stream2BufferedImage.) | |
90 shiv (doto (IMOperation.) | |
91 ;(.blur 2.0) | |
92 (.flip) | |
93 (.addImage) | |
94 (.addImage (into-array String ["png:-"]))) | |
95 conv-shiv (doto (ConvertCmd.) | |
96 (.setOutputConsumer s2b))] | |
97 | |
98 (.run conv-shiv shiv (into-array Object [target])) | |
99 (ImagePlus. title (.getImage s2b)))) | |
100 | |
101 | |
102 | |
69 (defn row->gcode [{:keys [x-dpi y-dpi margin x-offset y-offset]} forward? row] | 103 (defn row->gcode [{:keys [x-dpi y-dpi margin x-offset y-offset]} forward? row] |
70 | 104 |
71 (let [[x1 y1] (if forward? (last row) (first row)) | 105 (let [[x1 y1] (if forward? (last row) (first row)) |
72 [x2 y2] (if forward? (first row) (last row))] | 106 [x2 y2] (if forward? (first row) (last row))] |
73 | 107 |
74 (let [x1 (* x1 (/ x-dpi)) | 108 (let [x1 (* x1 (/ x-dpi)) |
75 x2 (* x2 (/ x-dpi)) | 109 x2 (* x2 (/ x-dpi)) |
76 y1 (* y1 (/ y-dpi)) | 110 y1 (* y1 (/ y-dpi)) |
77 y2 (* y2(/ y-dpi))] | 111 y2 (* y2 (/ y-dpi))] |
78 | 112 |
79 (let [x1 (+ x1 x-offset) | 113 (let [x1 (+ x1 x-offset) |
80 x2 (+ x2 x-offset) | 114 x2 (+ x2 x-offset) |
81 y1 (+ y1 y-offset) | 115 y1 (+ y1 y-offset) |
82 y2 (+ y2 y-offset)] | 116 y2 (+ y2 y-offset)] |
83 | 117 |
118 | |
84 | 119 |
85 (str (format "G0 X%.3f Y%.3f\n" | 120 (str (format "G0 X%.3f Y%.3f\n" |
86 (float x1 ) | 121 (float x1 ) |
87 (float y1)) | 122 (float y1)) |
88 | 123 |
186 (println "/home/r/kevin/out.gmask") | 221 (println "/home/r/kevin/out.gmask") |
187 pic) | 222 pic) |
188 | 223 |
189 (defn update-state [] | 224 (defn update-state [] |
190 (def sing "/home/r/kevin/sing.png") | 225 (def sing "/home/r/kevin/sing.png") |
191 (def pic (frame-hash (rotate 180 (ImagePlus. sing)))) | 226 (def pic (frame-hash (mirror (ImagePlus. sing)))) |
192 (def pic (b&w pic))) | 227 (def pic (b&w pic))) |
193 | 228 |
194 (defn compare-gen-fn [n f cmp] | 229 (defn compare-gen-fn [n f cmp] |
195 (let [theirs (re-split #"\n" (slurp cmp)) | 230 (let [theirs (re-split #"\n" (slurp cmp)) |
196 ours (re-split #"\n" (f pic))] | 231 ours (re-split #"\n" (f pic))] |