[python-dtcwt] 289/497: Added quiver overlay function

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Jul 21 18:06:15 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 f3c459be41d04bfb6440fa80e3476d067d309b54
Author: scf32 <scf32 at cam.ac.uk>
Date:   Fri Jan 31 12:55:24 2014 +0000

    Added quiver overlay function
---
 dtcwt/utils.py | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/dtcwt/utils.py b/dtcwt/utils.py
index f18fd6b..73adce0 100644
--- a/dtcwt/utils.py
+++ b/dtcwt/utils.py
@@ -56,6 +56,40 @@ 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
 
+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 
+    coefficients, level specifies the transform level of vectorField. Offset for DTCWT coefficients
+    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.
+
+    .. 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)
+    
+    # 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)))))
+
+    for sb in range(0, vectorField.shape[2]):
+        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)
+        hold(True)
+    
+    return hq
+
 def asfarray(X):
     """Similar to :py:func:`numpy.asfarray` except that this function tries to
     preserve the original datatype of X if it is already a floating point type

-- 
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