[python-dtcwt] 398/497: update example of 3D transform
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Tue Jul 21 18:06:32 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 912af1f121b6547a86fc816b473fb464d3f4d0c4
Author: Rich Wareham <rjw57 at cam.ac.uk>
Date: Mon Feb 10 17:31:06 2014 +0000
update example of 3D transform
Use the new transform API and also generate the various figures at
docs compile time.
---
docs/3d-complex-coeffs.png | Bin 418214 -> 0 bytes
docs/3dtransform.rst | 67 +++++++++++++++++++++++++++------------------
docs/sphere-slice.png | Bin 6382 -> 0 bytes
3 files changed, 40 insertions(+), 27 deletions(-)
diff --git a/docs/3d-complex-coeffs.png b/docs/3d-complex-coeffs.png
deleted file mode 100644
index bfdf2b9..0000000
Binary files a/docs/3d-complex-coeffs.png and /dev/null differ
diff --git a/docs/3dtransform.rst b/docs/3dtransform.rst
index fe50656..a09ea81 100644
--- a/docs/3dtransform.rst
+++ b/docs/3dtransform.rst
@@ -2,14 +2,21 @@
------------
In the examples below I assume you've imported pyplot and numpy and, of course,
-the ``dtcwt`` library itself::
+the ``dtcwt`` library itself
- import numpy as np
- from matplotlib.pyplot import *
- from dtcwt.compat import *
+.. plot::
+ :include-source: true
+ :context:
+
+ from matplotlib.pylab import *
+ import dtcwt
We can demonstrate the 3D transform by generating a 64x64x64 array which
-contains the image of a sphere::
+contains the image of a sphere
+
+.. plot::
+ :include-source: true
+ :context:
GRID_SIZE = 64
SPHERE_RAD = int(0.45 * GRID_SIZE) + 0.5
@@ -20,44 +27,52 @@ contains the image of a sphere::
sphere = 0.5 + 0.5 * np.clip(SPHERE_RAD-r, -1, 1)
-If we look at the central slice of this image, it looks like a circle::
-
- imshow(sphere[:,:,GRID_SIZE>>1], interpolation='none', cmap=cm.gray)
+ trans = dtcwt.Transform3d()
+ sphere_t = trans.forward(sphere, nlevels=2)
-.. figure:: sphere-slice.png
+The function returns a :py:class:`dtcwt.Pyramid` instance containing the
+lowpass image and a tuple of complex highpass coefficients
-Performing the 3 level DT-CWT with the defaul wavelet selection is easy::
+.. code-block:: python
- Yl, Yh = dtwavexfm3(sphere, 3)
-
-The function returns the lowest level low pass image and a tuple of complex
-subband coefficients::
-
- >>> print(Yl.shape)
+ >>> print(sphere_t.lowpass.shape)
(16, 16, 16)
- >>> for highpasses in Yh:
+ >>> for highpasses in sphere_t.highpasses:
... print(highpasses.shape)
(32, 32, 32, 28)
(16, 16, 16, 28)
(8, 8, 8, 28)
-Performing the inverse transform should result in perfect reconstruction::
+Performing the inverse transform should result in perfect reconstruction
+
+.. code-block:: python
- >>> Z = dtwaveifm3(Yl, Yh)
- >>> print(np.abs(Z - ellipsoid).max()) # Should be < 1e-12
+ >>> Z = trans.inverse(sphere_t)
+ >>> print(np.abs(Z - sphere).max()) # Should be < 1e-12
8.881784197e-15
If you plot the locations of the large complex coefficients, you can see the
-directional sensitivity of the transform::
+directional sensitivity of the transform
+
+.. plot::
+ :include-source: true
+ :context:
from mpl_toolkits.mplot3d import Axes3D
- figure(figsize=(16,16))
+ figure()
+ imshow(sphere[:,:,GRID_SIZE>>1], interpolation='none', cmap=cm.gray)
+ title('2d slice from input sphere')
+
+ # Plot large magnitude wavelet coefficients' position in 3D.
+
+ figure(figsize=(16,9))
+ Yh = sphere_t.highpasses
nplts = Yh[-1].shape[3]
nrows = np.ceil(np.sqrt(nplts))
ncols = np.ceil(nplts / nrows)
W = np.max(Yh[-1].shape[:3])
- for idx in xrange(Yh[-1].shape[3]):
+ for idx in range(Yh[-1].shape[3]):
C = np.abs(Yh[-1][:,:,:,idx])
ax = gcf().add_subplot(nrows, ncols, idx+1, projection='3d')
ax.set_aspect('equal')
@@ -65,10 +80,8 @@ directional sensitivity of the transform::
x,y,z = np.nonzero(good)
ax.scatter(x, y, z, c=C[good].ravel())
ax.auto_scale_xyz((0,W), (0,W), (0,W))
-
+
tight_layout()
-
-For a further directional sensitivity example, see :ref:`3d-directional-example`.
-.. figure:: 3d-complex-coeffs.png
+For a further directional sensitivity example, see :ref:`3d-directional-example`.
diff --git a/docs/sphere-slice.png b/docs/sphere-slice.png
deleted file mode 100644
index ec7903b..0000000
Binary files a/docs/sphere-slice.png and /dev/null differ
--
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