Created
July 20, 2011 21:08
-
-
Save jhickner/1095939 to your computer and use it in GitHub Desktop.
tablecup image slicing
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
(import (java.io File FileInputStream) | |
'javax.imageio.ImageIO) | |
(use '[clojure.contrib.string :only (split)]) | |
(def x-values [117 279 440 599 763 923 1083 1245]) | |
(def base-path "/Users/jhickner/Desktop/") | |
(defn file-basename [file] (first (split #"\." (.getName file)))) | |
(defn files-in-dir [dir] | |
(filter #(not (.isDirectory %)) | |
(.listFiles (File. dir)))) | |
(defn save-slice [base-name img start-x] | |
(let [subimg (.getSubimage img (- start-x 70) 0 155 860) | |
f (File. (str base-path "out/" base-name "-" start-x ".png"))] | |
(ImageIO/write subimg "png" f))) | |
(defn make-slices [file-list] | |
(dorun (pmap (fn [file] | |
(with-open [r (FileInputStream. file)] | |
(let [img (ImageIO/read r)] | |
[base-name (file-basename file)] | |
(doseq [x x-values] | |
(save-slice base-name img x))))) | |
file-list))) | |
(time (make-slices (files-in-dir (str base-path "players/")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment