[python-dtcwt] 300/497: overlay_quiver_DTCWT: add usage example

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Jul 21 18:06:16 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/sid
in repository python-dtcwt.

commit b83688cd95a64c0767da2f667c65e925de09a2d4
Author: Rich Wareham <rjw57 at cam.ac.uk>
Date:   Fri Jan 31 14:29:18 2014 +0000

    overlay_quiver_DTCWT: add usage example
---
 dtcwt/utils.py | 40 +++++++++++++++++++++++++++++++---------
 1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/dtcwt/utils.py b/dtcwt/utils.py
index 73adce0..9109489 100644
--- a/dtcwt/utils.py
+++ b/dtcwt/utils.py
@@ -56,6 +56,8 @@ def drawcirc(r,w,du,dv,N):
     p = 0.5 + 0.5 * np.sin(np.minimum(np.maximum((np.exp(np.array([-0.5]) * (x**2 + y**2)).T - np.exp((-0.5))) * (r * 3 / w), np.pi/(-2)), np.pi/2))
     return p
 
+from matplotlib.pyplot import *
+
 def overlay_quiver_DTCWT(image, vectorField, level, offset):
     """Overlays nicely coloured quiver plot of complex coefficients over original full-size image,
     providing a useful phase visualisation. vectorField is a single [MxNx6] numpy array of DTCWT 
@@ -63,20 +65,40 @@ def overlay_quiver_DTCWT(image, vectorField, level, offset):
     is typically 0.5. Should also work with other types of complex arrays (e.g., SLP coefficients),
     as long as the format is the same.
 
+    Usage example:
+
+    .. ipython::
+
+        In [0]: from pylab import *
+
+        In [0]: import datasets
+
+        In [0]: lena = datasets.lena()
+
+        In [1]: import dtcwt.backend.backend_numpy as backend
+
+        In [0]: t = backend.Transform2d()
+
+        In [0]: lena_t = t.forward(lena, nlevels=3)
+
+        In [0]: figure()
+
+        In [0]: import dtcwt.utils as utils
+
+        @savefig gen-overlay_quiver_DTCWT.png
+        In [0]: utils.overlay_quiver_DTCWT(lena, lena_t.subbands[-1], 3, 0.5)
+
     .. codeauthor:: R. Anderson, 2005 (MATLAB)
     .. codeauthor:: S. C. Forshaw, 2014 (Python)
     """
-        
+
     # You may wish to uncomment the following so that imshow() uses the full range of greyscale values
-    #image[0,0] = 0
-    #image[0,1] = 255
-    
-    imshow(image, cmap=cm.gray)
-    
+    imshow(image, cmap=cm.gray, clim=(0,1))
+
     # Set up the grid for the quiver plot
     g1 = np.kron(np.arange(0, vectorField[:,:,0].shape[0]).T, np.ones((1,vectorField[:,:,0].shape[1])))
     g2 = np.kron(np.ones((vectorField[:,:,0].shape[0], 1)), np.arange(0, vectorField[:,:,0].shape[1]))
-    
+
     # Choose a coloUrmap
     cmap = cm.jet
     scalefactor = vectorField[-1,-1,:] = np.max(np.max(np.max(np.max(np.abs(vectorField)))))
@@ -85,9 +107,9 @@ def overlay_quiver_DTCWT(image, vectorField, level, offset):
         thiscolour = cmap(sb / float(vectorField.shape[2])) # Select colour for this subband
         hq = quiver(g2*(2**level) + offset*(2**level), g1*(2**level) + offset*(2**level), np.real(vectorField[:,:,sb]), \
         np.imag(vectorField[:,:,sb]), color=thiscolour, scale=scalefactor*2**level)
-        plt.quiverkey(hq, image.shape[1]+75, 50 + sb*50, 200, "subband " + np.str(sb), coordinates='data', color=thiscolour)
+        quiverkey(hq, image.shape[1]+75, 50 + sb*50, 200, "subband " + np.str(sb), coordinates='data', color=thiscolour)
         hold(True)
-    
+
     return hq
 
 def asfarray(X):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-dtcwt.git



More information about the debian-science-commits mailing list