[python-dtcwt] 69/497: add an example on showing directional selectivity of 3D transform

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Jul 21 18:05:50 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 67cb11e9283c57fae2d07ee455388c61d7814e8e
Author: Rich Wareham <rjw57 at cam.ac.uk>
Date:   Thu Aug 8 19:23:33 2013 +0100

    add an example on showing directional selectivity of 3D transform
---
 docs/3d_dtcwt_directionality.png    | Bin 0 -> 113360 bytes
 docs/examples.rst                   |  18 ++++++++++
 docs/index.rst                      |   1 +
 examples/3d_dtcwt_directionality.py |  68 ++++++++++++++++++++++++++++++++++++
 4 files changed, 87 insertions(+)

diff --git a/docs/3d_dtcwt_directionality.png b/docs/3d_dtcwt_directionality.png
new file mode 100644
index 0000000..ca0e9e3
Binary files /dev/null and b/docs/3d_dtcwt_directionality.png differ
diff --git a/docs/examples.rst b/docs/examples.rst
new file mode 100644
index 0000000..ca4e472
--- /dev/null
+++ b/docs/examples.rst
@@ -0,0 +1,18 @@
+Example scripts
+===============
+
+Showing direcional sensitivity of 3D transform
+----------------------------------------------
+
+The
+:download:`3d_dtcwt_directionality.py<../examples/3d_dtcwt_directionality.py>`
+script in the examples directory shows how one may demonstrate the directional
+sensitivity of the 3D DT-CWT complex subband coefficients. It computes
+empirically the maximally sensitive directions for each subband and plots them
+in an interactive figure using matplotlib. A screenshot is reproduced below:
+
+.. image:: 3d_dtcwt_directionality.png
+
+The source for the script is shown below:
+
+.. literalinclude:: ../examples/3d_dtcwt_directionality.py
diff --git a/docs/index.rst b/docs/index.rst
index 2dc006f..70f20e2 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -25,6 +25,7 @@ Table of Contents
     :maxdepth: 2
 
     gettingstarted
+    examples
     reference
 
 Indices and tables
diff --git a/examples/3d_dtcwt_directionality.py b/examples/3d_dtcwt_directionality.py
new file mode 100644
index 0000000..9512635
--- /dev/null
+++ b/examples/3d_dtcwt_directionality.py
@@ -0,0 +1,68 @@
+#!/bin/python
+
+"""
+An example of the directional selectivity of 3D DT-CWT coefficients.
+
+This example creates a 3D array holding an image of a sphere and performs the
+3D DT-CWT transform on it. The locations of maxima (and their images about the
+mid-point of the image) are determined for each complex coefficient at level 2.
+These maxima points are then shown on a single plot to demonstrate the
+directions in which the 3D DT-CWT transform is selective.
+
+"""
+
+# Import the libraries we need
+from matplotlib.pyplot import *
+import numpy as np
+from mpl_toolkits.mplot3d import Axes3D
+from dtcwt import dtwavexfm3, dtwaveifm3, biort, qshift
+
+# Specify details about sphere and grid size
+GRID_SIZE = 128
+SPHERE_RAD = 0.33 * GRID_SIZE
+
+# Compute an image of the sphere
+grid = np.arange(-(GRID_SIZE>>1), GRID_SIZE>>1)
+X, Y, Z = np.meshgrid(grid, grid, grid)
+r = np.sqrt(X*X + Y*Y + Z*Z)
+sphere = 0.5 + np.clip(SPHERE_RAD-r, -0.5, 0.5)
+
+# Specify number of levels and wavelet family to use
+nlevels = 2
+b = biort('near_sym_a')
+q = qshift('qshift_a')
+
+# Form the DT-CWT of the sphere
+Yl, Yh = dtwavexfm3(sphere, nlevels, b, q)
+
+# Plot maxima
+figure(figsize=(8,8))
+
+ax = gcf().add_subplot(1,1,1, projection='3d')
+ax.set_aspect('equal')
+locs = []
+scale = 1.1
+for idx in xrange(Yh[-1].shape[3]):
+    Z = Yh[-1][:,:,:,idx]
+    C = np.abs(Z)
+    max_loc = np.asarray(np.unravel_index(np.argmax(C), C.shape)) - np.asarray(C.shape)*0.5
+    max_loc /= np.sqrt(np.sum(max_loc * max_loc))
+    locs.append(max_loc)
+
+    ax.text(max_loc[0] * scale, max_loc[1] * scale, max_loc[2] * scale, str(idx+1))
+    ax.text(-max_loc[0] * scale, -max_loc[1] * scale, -max_loc[2] * scale, str(idx+1))
+                        
+locs = np.asarray(locs)
+ax.scatter(locs[:,0], locs[:,1], locs[:,2], c=np.arange(locs.shape[0]))
+ax.scatter(-locs[:,0], -locs[:,1], -locs[:,2], c=np.arange(locs.shape[0]))
+
+w = scale * 1.2
+ax.auto_scale_xyz([-w, w], [-w, w], [-w, w])
+
+legend()
+title('Subband directional selectivity for 3D DT-CWT')
+tight_layout()
+
+show()
+
+# vim:sw=4:sts=4:et

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