Created
October 29, 2010 02:36
-
-
Save duncanmak/652780 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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