# HG changeset patch # User Robert McIntyre # Date 1362623869 0 # Node ID 744ae7ef9b1424b3685e7f1948564db9b698c3d7 # Parent b72fea69b2e1010995774c176a1334bf53e225ca gabor filter looks right. diff -r b72fea69b2e1 -r 744ae7ef9b14 org/gabor.org --- a/org/gabor.org Wed Mar 06 18:50:35 2013 +0000 +++ b/org/gabor.org Thu Mar 07 02:37:49 2013 +0000 @@ -33,9 +33,70 @@ ;;r - (org.opencv.core.MatOfFloat. (float-array [1])) + (org.opencv.core.MatOfFloat. (float-array [0.5])) )) +(defn gabor-kernel [sigma aspect-ratio theta wavelength phase-offset] + + ;; first, find the size of the kernel which is required + (let [square #(expt % 2) + rotated (fn [[x y]] + [(+ (* x (Math/cos theta)) (* y (Math/sin theta))) + (- (* y (Math/cos theta)) (* x (Math/sin theta)))]) + + gaussian (fn [[x y]] + (let [[x' y'] (rotated [x y])] + (Math/exp (- (/ (+ (square x') + (square (* aspect-ratio y'))) + (* 2 (square sigma))))))) + sinusoid (fn [[x y]] + (let [[x' y'] (rotated [x y])] + (Math/cos + (+ (* 2 Math/PI (/ x' wavelength)) + phase-offset)))) + + half-width (max + (int (* 5 (/ sigma aspect-ratio))) + (int (* 5 sigma)) + (int (* 5 (/ aspect-ratio sigma)))) + + grid (let [axis (range (- half-width) (inc half-width))] + (for [y (reverse axis) x axis] (vector x y))) + + scale (reduce + (map gaussian grid)) + + gabor (fn [[x y :as coord]] + (* (sinusoid coord) (gaussian coord) scale)) + + mat-width (+ 1 (* 2 half-width)) + mat (Mat. mat-width mat-width CvType/CV_32F)] + + + (.put mat 0 0 (float-array (map gabor grid))) + mat + + ;;(map gabor grid) + + )) + + +(defn show-kernel [kernel] + (let [output "/home/r/proj/cortex/tmp/kernel.png"] + (org.opencv.highgui.Highgui/imwrite output kernel) + (view (ImagePlus. output)))) + +(defn print-kernel [kernel] + (println (.dump kernel))) + + + + + + + + + + (defn convolve-practice [] (let [input "/home/r/proj/cortex/images/dominos.jpg"