Skip to content

Instantly share code, notes, and snippets.

@clojj
Last active August 29, 2015 14:07
Show Gist options
  • Save clojj/646e6b3e002e49d0996f to your computer and use it in GitHub Desktop.
Save clojj/646e6b3e002e49d0996f to your computer and use it in GitHub Desktop.
combinating ppm images
(defn process []
(let [file-data (IOUtils/toByteArray (io/input-stream "resources/img1.ppm"))
ppm-head (subvec (vec file-data) 0 32)
img-data (partition 3 (subvec (vec file-data) 32))
file-data2 (IOUtils/toByteArray (io/input-stream "resources/img2.ppm"))
img-data2 (partition 3 (subvec (vec file-data2) 32))]
(let [result (map #(map (fn [n] (/ n 2)) (map + %1 %2)) img-data img-data2) ;(r/fold (r/monoid into vector) conj (r/map #(/ (+ % %) 2) img-data img-data2))
result-data (flatten result)
ba (byte-array (concat ppm-head result-data))]
(IOUtils/write ba (io/output-stream "resources/out.ppm")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment