diff 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
line wrap: on
line diff
     1.1 --- a/src/laser/rasterize.clj	Mon Aug 30 00:09:06 2010 -0400
     1.2 +++ b/src/laser/rasterize.clj	Mon Aug 30 01:01:35 2010 -0400
     1.3 @@ -65,7 +65,41 @@
     1.4  ;    (vector (first sorted-row) (last sorted-row))))
     1.5  
     1.6  
     1.7 +(comment
     1.8  
     1.9 +  (import 'org.im4java.core.ConvertCmd)
    1.10 +  (import 'org.im4java.core.IMOperation)
    1.11 +  (import 'org.im4java.core.Stream2BufferedImage)			
    1.12 +
    1.13 +  (def target (.getBufferedImage (ImagePlus. sing)))
    1.14 + (def shiv (IMOperation.))
    1.15 +(.addImage shiv)
    1.16 +(.addImage shiv (into-array String ["png:-"]))
    1.17 +(def conv-shiv (ConvertCmd.))
    1.18 +(def s2b (Stream2BufferedImage.))
    1.19 +(.setOutputConsumer conv-shiv s2b)
    1.20 +(.run conv-shiv shiv (into-array Object [target]))
    1.21 +(def result (.getImage s2b ))
    1.22 +
    1.23 +  )
    1.24 +
    1.25 +(defn mirror [#^ImagePlus img]
    1.26 +  (let [title (.getTitle img)
    1.27 +	target (.getBufferedImage img)
    1.28 +	s2b (Stream2BufferedImage.)
    1.29 +	shiv (doto (IMOperation.)
    1.30 +	       ;(.blur 2.0)
    1.31 +	       (.flip)
    1.32 +	       (.addImage)
    1.33 +	       (.addImage (into-array String ["png:-"])))
    1.34 +	conv-shiv (doto (ConvertCmd.)
    1.35 +		    (.setOutputConsumer s2b))]
    1.36 +
    1.37 +    (.run conv-shiv shiv (into-array Object [target]))
    1.38 +    (ImagePlus. title (.getImage s2b))))
    1.39 +	
    1.40 +    
    1.41 + 
    1.42  (defn row->gcode [{:keys [x-dpi y-dpi margin x-offset y-offset]} forward? row]
    1.43    
    1.44    (let [[x1 y1] (if forward? (last row) (first row))
    1.45 @@ -74,13 +108,14 @@
    1.46      (let [x1 (* x1 (/ x-dpi))
    1.47  	  x2 (* x2 (/ x-dpi))
    1.48  	  y1 (* y1 (/ y-dpi))
    1.49 -	  y2  (* y2(/ y-dpi))]
    1.50 +	  y2 (* y2 (/ y-dpi))]
    1.51  
    1.52      (let [x1 (+ x1 x-offset)
    1.53  	  x2 (+ x2 x-offset)
    1.54  	  y1 (+ y1 y-offset)
    1.55  	  y2 (+ y2 y-offset)]
    1.56 -	  
    1.57 +
    1.58 +      
    1.59            
    1.60        (str (format "G0 X%.3f Y%.3f\n"
    1.61  		   (float x1 )
    1.62 @@ -188,7 +223,7 @@
    1.63  
    1.64  (defn update-state []
    1.65    (def sing "/home/r/kevin/sing.png")
    1.66 -  (def pic (frame-hash (rotate 180 (ImagePlus. sing))))  
    1.67 +  (def pic (frame-hash (mirror (ImagePlus. sing))))
    1.68    (def pic (b&w pic)))
    1.69  
    1.70  (defn compare-gen-fn [n f cmp]