Skip to content

Instantly share code, notes, and snippets.

@duncanmak
Created October 29, 2010 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duncanmak/652780 to your computer and use it in GitHub Desktop.
Save duncanmak/652780 to your computer and use it in GitHub Desktop.
(defn render! [section transforms]
(let [image (-> section load-section .getAbsolutePath IJ/openImage)
result (BufferedImage. *width* *height* BufferedImage/TYPE_BYTE_GRAY)
transform (->affine-transform (get transforms section))
graphics (.createGraphics result)
title (.getTitle image)]
(doto graphics
(.setTransform (doto transform (.translate *tx* *ty*)))
(.drawImage (.getBufferedImage image) 0 0 nil))
(IJ/save (ImagePlus. title result) (.getAbsolutePath (file *root* title)))))
(defn run [all-sections transforms]
(let [number-of-sections (count all-sections)
chunk (/ number-of-sections 4)
tasks (agent (sorted-map))]
(dorun (pmap (fn [sections]
(map #(send tasks assoc % (future (render! % transforms))) sections))
(partition chunk all-sections)))
tasks))
(defn render! [section transforms tasks]
(send tasks assoc section :working)
(let [image (-> section load-section .getAbsolutePath IJ/openImage)
result (BufferedImage. *width* *height* BufferedImage/TYPE_BYTE_GRAY)
transform (->affine-transform (get transforms section))
graphics (.createGraphics result)
title (.getTitle image)]
(assert (not (nil? transform)))
(doto graphics
(.setTransform (doto transform (.translate *tx* *ty*)))
(.drawImage (.getBufferedImage image) 0 0 nil))
(IJ/save (ImagePlus. title result) (.getAbsolutePath (file *root* title)))
(send tasks assoc section :done)))
(defn run-parallel []
(let [number-of-sections (count *sections*)
chunk (/ number-of-sections 4)
tasks (agent {})]
(pmap
(fn [sections]
(doseq [s sections]
(render! s *transforms* tasks)))
(partition chunk (sort *sections*)))
tasks))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment