 ;(println "saving as" (str (string/replace (string/replace orig-name ".tif" "") " " "_") "_labeled_branches.tif"))
 ;(ij.IJ/saveAsTiff imp (str directory "/" (string/replace orig-name ".tif" "") "_labeled_branches.tif"))
 
-;(ij.IJ/run "Close All")+;(ij.IJ/run "Close All")

  (let [rt (ij.measure.ResultsTable/getResultsTable)]
    {:num-regions (.getCounter rt)
     :area (apply + (map #(.getValue rt "Area" %) (range (.getCounter rt))))}))
  
;(let [rm (ij.plugin.frame.RoiManager.)
;      num-rois (.getCount rm)]
  

(def new-mask (ij.WindowManager/getImage (str "Mask of " (str "C2-" orig-name ))))


(def directory (ij.IJ/getDirectory "image"))

; Requires the plugin from:
; morphology update site
; and
; http://jvsmicroscope.uta.fi/?q=skeleton_intersections


(if (= (.getType imp) ij.ImagePlus/COLOR_RGB)
  (do (ij.IJ/run imp "8-bit" "")
    (def mask imp))
  (do (def channels (ij.plugin.ChannelSplitter/split imp))

    (def mask (second channels))
    (.setTitle mask (str "C2-" orig-name ))))

(ij.IJ/run mask "Subtract Background..." "rolling=25")

(dotimes [step smoothing-steps]
  (ij.IJ/run mask "Smooth" ""))
