Mercurial > cortex
comparison org/gabor.org @ 361:09461dce2e2f
cleanup.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 07 Mar 2013 03:27:42 +0000 |
parents | fc5bb270596a |
children | 4b229dc028b6 |
comparison
equal
deleted
inserted
replaced
360:fc5bb270596a | 361:09461dce2e2f |
---|---|
15 (:import org.opencv.core.CvType) | 15 (:import org.opencv.core.CvType) |
16 (:import java.awt.image.BufferedImage) | 16 (:import java.awt.image.BufferedImage) |
17 (:import ij.ImagePlus) | 17 (:import ij.ImagePlus) |
18 (:import org.opencv.core.Mat) | 18 (:import org.opencv.core.Mat) |
19 (:use cortex.sense) | 19 (:use cortex.sense) |
20 (:use cortex.util) | 20 (:use cortex.util)) |
21 ) | |
22 | 21 |
23 (defn load-opencv | 22 (defn load-opencv |
24 "Load the opencv native library. Must be called before any OpenCV | 23 "Load the opencv native library. Must be called before any OpenCV |
25 stuff is used." | 24 stuff is used." |
26 [] | 25 [] |
53 (let [[x' y'] (rotated [x y])] | 52 (let [[x' y'] (rotated [x y])] |
54 (Math/cos | 53 (Math/cos |
55 (+ (* 2 Math/PI (/ x' wavelength)) | 54 (+ (* 2 Math/PI (/ x' wavelength)) |
56 phase-offset)))) | 55 phase-offset)))) |
57 | 56 |
58 half-width (max | 57 half-width |
59 (int (* 5 (/ sigma aspect-ratio))) | 58 (let [std-dev-capture 5] |
60 (int (* 5 sigma)) | 59 (max |
61 (int (* 5 (/ aspect-ratio sigma)))) | 60 (int (* std-dev-capture (/ sigma aspect-ratio))) |
61 (int (* std-dev-capture sigma)) | |
62 (int (* std-dev-capture (/ aspect-ratio sigma))))) | |
62 | 63 |
63 grid (let [axis (range (- half-width) (inc half-width))] | 64 grid (let [axis (range (- half-width) (inc half-width))] |
64 (for [y (reverse axis) x axis] (vector x y))) | 65 (for [y (reverse axis) x axis] (vector x y))) |
65 | 66 |
66 scale (reduce + (map gaussian grid)) | 67 scale (reduce + (map gaussian grid)) |
68 gabor (fn [[x y :as coord]] | 69 gabor (fn [[x y :as coord]] |
69 (* (sinusoid coord) (gaussian coord) (/ scale))) | 70 (* (sinusoid coord) (gaussian coord) (/ scale))) |
70 | 71 |
71 mat-width (+ 1 (* 2 half-width)) | 72 mat-width (+ 1 (* 2 half-width)) |
72 mat (Mat. mat-width mat-width CvType/CV_32F)] | 73 mat (Mat. mat-width mat-width CvType/CV_32F)] |
73 | |
74 | 74 |
75 (.put mat 0 0 (float-array (map gabor grid))) | 75 (.put mat 0 0 (float-array (map gabor grid))) |
76 mat | 76 mat)) |
77 | |
78 ;;(map gabor grid) | |
79 | |
80 )) | |
81 | 77 |
82 | 78 |
83 (defn show-kernel [kernel] | 79 (defn draw-kernel! [kernel img-path] |
84 (let [output "/home/r/proj/cortex/tmp/kernel.png" | 80 (let [output img-path |
85 size (.size kernel) | 81 size (.size kernel) |
86 width (int (.width size)) | 82 width (int (.width size)) |
87 height (int (.height size)) | 83 height (int (.height size)) |
88 tmp-array (float-array (* width height))] | 84 tmp-array (float-array (* width height))] |
89 | 85 |
95 low (apply min vals) | 91 low (apply min vals) |
96 high (apply max vals) | 92 high (apply max vals) |
97 scaled-vals (map #(* 255 (- % low) (/ (- high low))) vals) | 93 scaled-vals (map #(* 255 (- % low) (/ (- high low))) vals) |
98 new-mat (Mat. height width CvType/CV_32F)] | 94 new-mat (Mat. height width CvType/CV_32F)] |
99 (.put new-mat 0 0 (float-array scaled-vals)) | 95 (.put new-mat 0 0 (float-array scaled-vals)) |
100 (org.opencv.highgui.Highgui/imwrite output new-mat) | 96 (org.opencv.highgui.Highgui/imwrite output new-mat)))) |
101 (view (ImagePlus. output))))) | 97 |
98 (defn show-kernel [kernel] | |
99 (let [img-path "/home/r/proj/cortex/tmp/kernel.png"] | |
100 (draw-kernel kernel img-path) | |
101 (view (ImagePlus. output)))) | |
102 | 102 |
103 (defn print-kernel [kernel] | 103 (defn print-kernel [kernel] |
104 (println (.dump kernel))) | 104 (println (.dump kernel))) |
105 | 105 |
106 | 106 |
128 (org.opencv.imgproc.Imgproc/filter2D i new-mat CvType/CV_32F kernel) | 128 (org.opencv.imgproc.Imgproc/filter2D i new-mat CvType/CV_32F kernel) |
129 | 129 |
130 (org.opencv.highgui.Highgui/imwrite "/home/r/ppp.png" new-mat) | 130 (org.opencv.highgui.Highgui/imwrite "/home/r/ppp.png" new-mat) |
131 | 131 |
132 (view (ImagePlus. input)) | 132 (view (ImagePlus. input)) |
133 (view (ImagePlus. output)) | 133 (view (ImagePlus. output)))) |
134 | |
135 )) | |
136 | 134 |
137 | 135 |
138 | 136 |
139 | 137 |
140 | 138 |