[python-dtcwt] 74/497: implement ext_mode
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Tue Jul 21 18:05:51 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 ce203c495e3886ad5d3d2e3d5f6447c6ca087f53
Author: Rich Wareham <rjw57 at cam.ac.uk>
Date: Thu Aug 8 20:12:15 2013 +0100
implement ext_mode
---
dtcwt/transform3d.py | 25 ++++++++++++++-----------
tests/testxfm3.py | 39 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 52 insertions(+), 12 deletions(-)
diff --git a/dtcwt/transform3d.py b/dtcwt/transform3d.py
index 21f7286..9fcd111 100644
--- a/dtcwt/transform3d.py
+++ b/dtcwt/transform3d.py
@@ -38,11 +38,6 @@ def dtwavexfm3(X, nlevels=3, biort=DEFAULT_BIORT, qshift=DEFAULT_QSHIFT, ext_mod
2nd level onwards, the coeffs can be divided by 8. If any dimension size is
not a multiple of 8, append extra coeffs by repeating the edges twice.
- .. note::
-
- The *ext_mode* == 8 behaviour has not yet been implemented in
- :py:func:`dtwaveifm3`.
-
Example::
# Performs a 3-level transform on the real 3D array X using the 13,19-tap
@@ -243,7 +238,12 @@ def _level2_xfm(X, h0a, h0b, h1a, h1b, ext_mode):
if X.shape[2] % 4 != 0:
X = np.concatenate((X[:,:,0], X, X[:,:,-1]), 2)
elif ext_mode == 8:
- raise NotImplementedError('')
+ if X.shape[0] % 8 != 0:
+ X = np.concatenate((X[(0,0),:,:], X, X[(-1,-1),:,:]), 0)
+ if X.shape[1] % 8 != 0:
+ X = np.concatenate((X[:,(0,0),:], X, X[:,(-1,-1),:]), 1)
+ if X.shape[2] % 8 != 0:
+ X = np.concatenate((X[:,:,(0,0)], X, X[:,:,(-1,-1)]), 2)
# Create work area
work_shape = np.asarray(X.shape)
@@ -387,12 +387,15 @@ def _level2_ifm(Yl, Yh, g0a, g0b, g1a, g1b, ext_mode, prev_level_size):
y = work[:, f, :].T
work[:, f, :] = (colifilt(y[s2a, :], g0b, g0a) + colifilt(y[s2b, :], g1b, g1a)).T
- # Now check if the size of the previous level is exactly twice the size of
- # the current level. If YES, this means we have not done the extension in
- # the previous level. If NO, then we have to remove the appended row /
- # column / frame from the previous level DTCWT coefs.
+ # FIXME: Original dtcwt3dC_xa.m has a comment to this effect but,
+ # unfortunately, I can't trigger the need for this behaviour:
+ #
+ # Now check if the size of the previous level is exactly twice the size
+ # of the current level. If YES, this means we have not done the extension
+ # in the previous level. If NO, then we have to remove the appended row /
+ # column / frame from the previous level DTCWT coefs.
- return work#[-prev_level_size[0]:, -prev_level_size[1]:, -prev_level_size[2]:]
+ return work
#==========================================================================================
# ********** INTERNAL FUNCTIONS **********
diff --git a/tests/testxfm3.py b/tests/testxfm3.py
index 74c1f56..2383418 100644
--- a/tests/testxfm3.py
+++ b/tests/testxfm3.py
@@ -3,7 +3,7 @@ from nose.tools import raises
from nose.plugins.attrib import attr
import numpy as np
-from dtcwt import dtwavexfm3, dtwaveifm3
+from dtcwt import dtwavexfm3, dtwaveifm3, biort, qshift
GRID_SIZE=32
SPHERE_RAD=0.4 * GRID_SIZE
@@ -85,4 +85,41 @@ def test_simple_level_4_recon():
assert ellipsoid.size == ellipsoid_recon.size
assert np.max(np.abs(ellipsoid - ellipsoid_recon)) < TOLERANCE
+def test_simple_level_4_recon_custom_wavelets():
+ # Test for perfect reconstruction with 3 levels
+ b = biort('legall')
+ q = qshift('qshift_06')
+ Yl, Yh = dtwavexfm3(ellipsoid, 4, biort=b, qshift=q)
+ ellipsoid_recon = dtwaveifm3(Yl, Yh, biort=b, qshift=q)
+ assert ellipsoid.size == ellipsoid_recon.size
+ assert np.max(np.abs(ellipsoid - ellipsoid_recon)) < TOLERANCE
+
+def test_simple_level_4_xfm_ext_mode_8():
+ # Just tests that the transform broadly works and gives expected size output
+ crop_ellipsoid = ellipsoid[:62,:58,:54]
+ Yl, Yh = dtwavexfm3(crop_ellipsoid, 4, ext_mode=8)
+ assert len(Yh) == 4
+
+def test_simple_level_4_recon_ext_mode_8():
+ # Test for perfect reconstruction with 3 levels
+ crop_ellipsoid = ellipsoid[:62,:58,:54]
+ Yl, Yh = dtwavexfm3(crop_ellipsoid, 4, ext_mode=8)
+ ellipsoid_recon = dtwaveifm3(Yl, Yh)
+ assert crop_ellipsoid.size == ellipsoid_recon.size
+ assert np.max(np.abs(crop_ellipsoid - ellipsoid_recon)) < TOLERANCE
+
+def test_simple_level_4_xfm_ext_mode_4():
+ # Just tests that the transform broadly works and gives expected size output
+ crop_ellipsoid = ellipsoid[:62,:54,:58]
+ Yl, Yh = dtwavexfm3(crop_ellipsoid, 4, ext_mode=4)
+ assert len(Yh) == 4
+
+def test_simple_level_4_recon_ext_mode_4():
+ # Test for perfect reconstruction with 3 levels
+ crop_ellipsoid = ellipsoid[:62,:54,:58]
+ Yl, Yh = dtwavexfm3(crop_ellipsoid, 4, ext_mode=4)
+ ellipsoid_recon = dtwaveifm3(Yl, Yh)
+ assert crop_ellipsoid.size == ellipsoid_recon.size
+ assert np.max(np.abs(crop_ellipsoid - ellipsoid_recon)) < TOLERANCE
+
# 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