[python-dtcwt] 301/497: move plotting-related functions to dedicated module

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Jul 21 18:06:17 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 6e037fbf99395f186a0fb7d1e4ba9f7fa9869e96
Author: Rich Wareham <rjw57 at cam.ac.uk>
Date:   Fri Jan 31 14:34:43 2014 +0000

    move plotting-related functions to dedicated module
---
 docs/reference.rst |  6 +++++
 dtcwt/plotting.py  | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 dtcwt/utils.py     | 56 -------------------------------------------
 3 files changed, 76 insertions(+), 56 deletions(-)

diff --git a/docs/reference.rst b/docs/reference.rst
index 823efe3..8ac3b73 100644
--- a/docs/reference.rst
+++ b/docs/reference.rst
@@ -59,6 +59,12 @@ Image registration
 .. automodule:: dtcwt.registration
     :members:
 
+Plotting functions
+``````````````````
+
+.. automodule:: dtcwt.plotting
+    :members:
+
 Miscellaneous and low-level support functions
 `````````````````````````````````````````````
 
diff --git a/dtcwt/plotting.py b/dtcwt/plotting.py
new file mode 100644
index 0000000..994aee2
--- /dev/null
+++ b/dtcwt/plotting.py
@@ -0,0 +1,70 @@
+"""
+Convenience functions for plotting DTCWT-related objects.
+
+The usage examples for functions in this module assume the following boilerplate:
+
+.. ipython::
+
+    In [0]: from pylab import *
+
+    In [0]: import datasets
+
+    In [0]: import dtcwt.plotting as dtcwtplt
+
+    In [1]: import dtcwt.backend.backend_numpy as backend
+
+    In [0]: transform2d = backend.Transform2d()
+
+"""
+
+import numpy as np
+from matplotlib.pyplot import *
+
+__all__ = (
+    'overlay_quiver_DTCWT',
+)
+
+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.
+
+    Usage example:
+
+    .. ipython::
+
+        In [0]: lena = datasets.lena()
+
+        In [0]: lena_t = transform2d.forward(lena, nlevels=3)
+
+        In [0]: figure()
+
+        @savefig gen-overlay_quiver_DTCWT.png
+        In [0]: dtcwtplt.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
+    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)))))
+
+    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)
+        quiverkey(hq, image.shape[1]+75, 50 + sb*50, 200, "subband " + np.str(sb), coordinates='data', color=thiscolour)
+        hold(True)
+
+    return hq
+
diff --git a/dtcwt/utils.py b/dtcwt/utils.py
index 9109489..f18fd6b 100644
--- a/dtcwt/utils.py
+++ b/dtcwt/utils.py
@@ -56,62 +56,6 @@ 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 
-    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.
-
-    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
-    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)))))
-
-    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)
-        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