diff org/gabor.org @ 360:fc5bb270596a

completed kernel visualization code.
author Robert McIntyre <rlm@mit.edu>
date Thu, 07 Mar 2013 03:12:25 +0000
parents 744ae7ef9b14
children 09461dce2e2f
line wrap: on
line diff
     1.1 --- a/org/gabor.org	Thu Mar 07 02:37:49 2013 +0000
     1.2 +++ b/org/gabor.org	Thu Mar 07 03:12:25 2013 +0000
     1.3 @@ -31,9 +31,9 @@
     1.4      (.put r 0 0 (float-array (map (fn [_] (rand)) (range 25))))
     1.5      (println (.dump r))
     1.6  
     1.7 -    ;;r
     1.8 +    r
     1.9  
    1.10 -    (org.opencv.core.MatOfFloat. (float-array [0.5]))
    1.11 +
    1.12      ))
    1.13  
    1.14  (defn gabor-kernel [sigma aspect-ratio theta wavelength phase-offset]
    1.15 @@ -66,7 +66,7 @@
    1.16          scale (reduce + (map gaussian grid))
    1.17          
    1.18          gabor (fn [[x y :as coord]]
    1.19 -                (* (sinusoid coord) (gaussian coord) scale))
    1.20 +                (* (sinusoid coord) (gaussian coord) (/ scale)))
    1.21  
    1.22          mat-width (+ 1 (* 2 half-width))
    1.23          mat (Mat. mat-width mat-width CvType/CV_32F)]
    1.24 @@ -81,9 +81,24 @@
    1.25  
    1.26  
    1.27  (defn show-kernel [kernel]
    1.28 -  (let [output "/home/r/proj/cortex/tmp/kernel.png"]
    1.29 -    (org.opencv.highgui.Highgui/imwrite output kernel)
    1.30 -    (view (ImagePlus. output))))
    1.31 +  (let [output "/home/r/proj/cortex/tmp/kernel.png"
    1.32 +        size (.size kernel)
    1.33 +        width (int (.width size))
    1.34 +        height (int (.height size))
    1.35 +        tmp-array (float-array (* width height))]
    1.36 +
    1.37 +    ;; read values from matrix.
    1.38 +    (.get kernel 0 0 tmp-array)
    1.39 +
    1.40 +    ;; find overall dynamic range of the filter
    1.41 +    (let [vals (vec tmp-array)
    1.42 +          low (apply min vals)
    1.43 +          high (apply max vals)
    1.44 +          scaled-vals (map #(* 255 (- % low) (/ (- high low))) vals)
    1.45 +          new-mat (Mat. height width CvType/CV_32F)]
    1.46 +      (.put new-mat 0 0 (float-array scaled-vals))
    1.47 +      (org.opencv.highgui.Highgui/imwrite output new-mat)
    1.48 +      (view (ImagePlus. output)))))
    1.49  
    1.50  (defn print-kernel [kernel]
    1.51    (println (.dump kernel)))
    1.52 @@ -91,8 +106,7 @@
    1.53  
    1.54          
    1.55                        
    1.56 -        
    1.57 -        
    1.58 +         
    1.59          
    1.60    
    1.61  
    1.62 @@ -105,13 +119,13 @@
    1.63  
    1.64          i (org.opencv.highgui.Highgui/imread input)
    1.65  
    1.66 -        kernel (make-kernel)
    1.67 +        kernel (gabor-kernel 10 1 (/ Math/PI 2) 10 0)
    1.68  
    1.69          new-mat (Mat.)
    1.70                  
    1.71          ]
    1.72  
    1.73 -    (org.opencv.imgproc.Imgproc/filter2D  i new-mat CvType/CV_32F (make-kernel))
    1.74 +    (org.opencv.imgproc.Imgproc/filter2D  i new-mat CvType/CV_32F kernel)
    1.75      
    1.76      (org.opencv.highgui.Highgui/imwrite "/home/r/ppp.png" new-mat)
    1.77