rlm@356
|
1 #+title: Fun with Gabor Filters
|
rlm@356
|
2 #+author: Robert McIntyre
|
rlm@356
|
3 #+email: rlm@mit.edu
|
rlm@356
|
4 #+description: gabor filters in clojure with opencv
|
rlm@356
|
5 #+keywords: computer vision, jMonkeyEngine3, clojure, opencv
|
rlm@356
|
6 #+SETUPFILE: ../../aurellem/org/setup.org
|
rlm@356
|
7 #+INCLUDE: ../../aurellem/org/level-0.org
|
rlm@356
|
8 #+babel: :mkdirp yes :noweb yes :exports both
|
rlm@356
|
9
|
rlm@356
|
10
|
rlm@356
|
11
|
rlm@356
|
12 #+name: gabor
|
rlm@356
|
13 #+begin_src clojure
|
rlm@357
|
14 (ns cortex.gabor
|
rlm@357
|
15 (:import org.opencv.core.CvType)
|
rlm@357
|
16 (:import java.awt.image.BufferedImage)
|
rlm@357
|
17 (:import ij.ImagePlus)
|
rlm@358
|
18 (:import org.opencv.core.Mat)
|
rlm@357
|
19 (:use cortex.sense)
|
rlm@357
|
20 (:use cortex.util)
|
rlm@357
|
21 )
|
rlm@356
|
22
|
rlm@356
|
23 (defn load-opencv
|
rlm@356
|
24 "Load the opencv native library. Must be called before any OpenCV
|
rlm@356
|
25 stuff is used."
|
rlm@356
|
26 []
|
rlm@356
|
27 (clojure.lang.RT/loadLibrary "opencv_java249"))
|
rlm@356
|
28
|
rlm@358
|
29 (defn make-kernel []
|
rlm@358
|
30 (let [r (org.opencv.core.Mat. 5 5 CvType/CV_32F)]
|
rlm@358
|
31 (.put r 0 0 (float-array (map (fn [_] (rand)) (range 25))))
|
rlm@358
|
32 (println (.dump r))
|
rlm@358
|
33
|
rlm@358
|
34 ;;r
|
rlm@358
|
35
|
rlm@358
|
36 (org.opencv.core.MatOfFloat. (float-array [1]))
|
rlm@358
|
37 ))
|
rlm@356
|
38
|
rlm@357
|
39 (defn convolve-practice []
|
rlm@357
|
40 (let [input "/home/r/proj/cortex/images/dominos.jpg"
|
rlm@357
|
41
|
rlm@357
|
42
|
rlm@357
|
43 output "/home/r/ppp.png"
|
rlm@356
|
44
|
rlm@357
|
45 i (org.opencv.highgui.Highgui/imread input)
|
rlm@358
|
46
|
rlm@358
|
47 kernel (make-kernel)
|
rlm@358
|
48
|
rlm@358
|
49 new-mat (Mat.)
|
rlm@358
|
50
|
rlm@357
|
51 ]
|
rlm@356
|
52
|
rlm@358
|
53 (org.opencv.imgproc.Imgproc/filter2D i new-mat CvType/CV_32F (make-kernel))
|
rlm@358
|
54
|
rlm@358
|
55 (org.opencv.highgui.Highgui/imwrite "/home/r/ppp.png" new-mat)
|
rlm@358
|
56
|
rlm@357
|
57 (view (ImagePlus. input))
|
rlm@357
|
58 (view (ImagePlus. output))
|
rlm@358
|
59
|
rlm@357
|
60 ))
|
rlm@357
|
61
|
rlm@357
|
62
|
rlm@357
|
63
|
rlm@357
|
64
|
rlm@357
|
65
|
rlm@357
|
66
|
rlm@357
|
67
|
rlm@357
|
68 (comment
|
rlm@357
|
69 ;; these work
|
rlm@357
|
70 (def i (org.opencv.highgui.Highgui/imread
|
rlm@357
|
71 "/home/r/proj/cortex/images/dominos.jpg"))
|
rlm@357
|
72
|
rlm@357
|
73 (org.opencv.highgui.Highgui/imwrite "/home/r/ppp.png" i)
|
rlm@357
|
74 )
|
rlm@356
|
75 #+end_src
|
rlm@356
|
76
|
rlm@356
|
77
|
rlm@356
|
78
|
rlm@356
|
79 * COMMENT Generate Source
|
rlm@356
|
80 #+begin_src clojure :tangle ../src/cortex/gabor.clj
|
rlm@356
|
81 <<gabor>>
|
rlm@356
|
82 #+end_src
|