1 ; A set of test functions for Patch class
3 ; In fiji, load this file to the Clojure Interpter like:
4 ; (load-file (str (System/getProperty "user.dir") "/TrakEM2/test/patch.clj"))
6 ; ... and then enter its namespace with:
7 ; (in-ns 'fiji.trakem2.tests.patch)
9 ; Then just execute any of the functions.
13 (:import (ij.gui OvalRoi Roi ShapeRoi)
15 (ij.process ByteProcessor)
16 (ini.trakem2.display Display Patch Selection)
17 (mpicbg.trakem2.transform MovingLeastSquaresTransform)))
19 (defn punch-alpha-hole
20 "Create an alpha hole right in the middle of an image."
22 (let [ip (.getImageProcessor patch)
23 w (int (.getOWidth patch))
24 h (int (.getOHeight patch))
25 mask (ByteProcessor. w h)
26 sroi (.not (ShapeRoi. (Roi. 0 0 w h))
27 (ShapeRoi. (OvalRoi. (/ w 4) (/ h 4) (/ w 2) (/ h 2))))]
31 (.fill (.getMask mask)))
32 (.setAlphaMask patch mask)))
36 "Punch an alpha hole into the selected and active Patch, if any,
37 and update its mipmaps and repaint."
39 (if-let [front (Display/getFront)]
40 (if-let [p (.getActive front)]
41 (if (isa? (class p) Patch)
46 (println "Not a Patch:" p))
47 (println "Nothing selected"))
48 (println "No Display open")))
51 "Regenerate mipmaps for all selected Patch, if any."
53 (if-let [front (Display/getFront)]
54 (if-let [patches (.. front getSelection (getSelected Patch))]
56 (println "No Patch selected")
61 (println "No Display open")))
64 "Returns the active Patch, if any."
66 (if-let [front (Display/getFront)]
67 (if-let [a (.getActive front)]
68 (if (isa? (class a) Patch)
70 (println "Active is not a Patch."))
71 (println "No active!"))
72 (println "No Display open")))
75 "Puts a new CoordinateTransform, a new Alpha mask and min,max values as desired."
77 (punch-alpha-hole patch)
78 (.setMinAndMax patch (double ip-min) (double ip-max))
79 (let [w (int (.getOWidth patch))
80 h (int (.getOHeight patch))
81 mls (MovingLeastSquaresTransform.)]
82 ; Intrude top-left and bottom-right corners by 100,100 pixels
83 (.init mls (str "rigid 1 "
85 w " " h " " (- w 100) " " (- h 100)))
86 (.setCoordinateTransform patch mls)))
89 "Executes the function on the active patch, if any,
90 and then updates the mipmaps and repaints.
94 `(if-let [patch# (get-active)]
97 (.updateMipmaps patch#)
102 "Restores an image min,max, removes any alpha,
103 and removes any coordinate transform."
105 ; 1 - Set min and max to defaults
106 (let [type (.getType patch)]
108 (== type ImagePlus/GRAY8)
109 (== type ImagePlus/COLOR_256)
110 (== type ImagePlus/COLOR_RGB))
111 (.setMinAndMax patch 0 255)
112 (let [ip (.getImageProcessor patch)]
114 (.setMinAndMax patch (.getMin ip) (.getMax ip)))))
116 (.setAlphaMask patch nil)
117 ; Remove CoordinateTransform
118 (.setCoordinateTransform patch nil))