Skip to content

Instantly share code, notes, and snippets.

@duncanmak
Created June 28, 2010 16:06
Show Gist options
  • Select an option

  • Save duncanmak/456022 to your computer and use it in GitHub Desktop.

Select an option

Save duncanmak/456022 to your computer and use it in GitHub Desktop.
(ns edu.harvard.connectome.convert-tiff-to-png
(:gen-class)
(:import [ij IJ ImagePlus])
(:use [clojure.contrib io seq string :as s]))
(defn only-tiff (proxy [java.io.FilenameFilter] []
(accept [file name] (.endsWith name "tif"))))
(defn replace-extension [file old-ext new-ext]
(.replace (str file) old-ext new-ext))
(defn convert [in-dir out-dir]
(loop [tiffs (seq (.listFiles in-dir only-tiff))]
(-> (first tiffs)
.getAbsolutePath
IJ/openImage
(IJ/save (str out-dir (replace-extension tiff "tif" "png"))))
(recur (rest tiffs))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment