comparison org/gabor.org @ 359:744ae7ef9b14

gabor filter looks right.
author Robert McIntyre <rlm@mit.edu>
date Thu, 07 Mar 2013 02:37:49 +0000
parents b72fea69b2e1
children fc5bb270596a
comparison
equal deleted inserted replaced
358:b72fea69b2e1 359:744ae7ef9b14
31 (.put r 0 0 (float-array (map (fn [_] (rand)) (range 25)))) 31 (.put r 0 0 (float-array (map (fn [_] (rand)) (range 25))))
32 (println (.dump r)) 32 (println (.dump r))
33 33
34 ;;r 34 ;;r
35 35
36 (org.opencv.core.MatOfFloat. (float-array [1])) 36 (org.opencv.core.MatOfFloat. (float-array [0.5]))
37 )) 37 ))
38
39 (defn gabor-kernel [sigma aspect-ratio theta wavelength phase-offset]
40
41 ;; first, find the size of the kernel which is required
42 (let [square #(expt % 2)
43 rotated (fn [[x y]]
44 [(+ (* x (Math/cos theta)) (* y (Math/sin theta)))
45 (- (* y (Math/cos theta)) (* x (Math/sin theta)))])
46
47 gaussian (fn [[x y]]
48 (let [[x' y'] (rotated [x y])]
49 (Math/exp (- (/ (+ (square x')
50 (square (* aspect-ratio y')))
51 (* 2 (square sigma)))))))
52 sinusoid (fn [[x y]]
53 (let [[x' y'] (rotated [x y])]
54 (Math/cos
55 (+ (* 2 Math/PI (/ x' wavelength))
56 phase-offset))))
57
58 half-width (max
59 (int (* 5 (/ sigma aspect-ratio)))
60 (int (* 5 sigma))
61 (int (* 5 (/ aspect-ratio sigma))))
62
63 grid (let [axis (range (- half-width) (inc half-width))]
64 (for [y (reverse axis) x axis] (vector x y)))
65
66 scale (reduce + (map gaussian grid))
67
68 gabor (fn [[x y :as coord]]
69 (* (sinusoid coord) (gaussian coord) scale))
70
71 mat-width (+ 1 (* 2 half-width))
72 mat (Mat. mat-width mat-width CvType/CV_32F)]
73
74
75 (.put mat 0 0 (float-array (map gabor grid)))
76 mat
77
78 ;;(map gabor grid)
79
80 ))
81
82
83 (defn show-kernel [kernel]
84 (let [output "/home/r/proj/cortex/tmp/kernel.png"]
85 (org.opencv.highgui.Highgui/imwrite output kernel)
86 (view (ImagePlus. output))))
87
88 (defn print-kernel [kernel]
89 (println (.dump kernel)))
90
91
92
93
94
95
96
97
98
38 99
39 (defn convolve-practice [] 100 (defn convolve-practice []
40 (let [input "/home/r/proj/cortex/images/dominos.jpg" 101 (let [input "/home/r/proj/cortex/images/dominos.jpg"
41 102
42 103