Skip to content

Commit

Permalink
rename scale -> rescale in sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
rjw57 committed Aug 20, 2013
1 parent 49a03a7 commit ba88e6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
9 changes: 5 additions & 4 deletions dtcwt/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"""

__all__ = (
'sample', 'sample_highpass', 'scale', 'scale_highpass',
'sample', 'sample_highpass',
'rescale', 'rescale_highpass',
'upsample', 'upsample_highpass',
)

Expand Down Expand Up @@ -115,7 +116,7 @@ def sample(im, xs, ys, method=None):

raise NotImplementedError('Sampling method "{0}" is not implemented.'.format(method))

def scale(im, shape, method=None):
def rescale(im, shape, method=None):
"""Return a resampled version of *im* scaled to *shape*.
Since the centre of pixel (x,y) has co-ordinate (x,y) the extent of *im* is
Expand Down Expand Up @@ -176,8 +177,8 @@ def sample_highpass(im, xs, ys, method=None):
# re-wrap
return _phase_image(xs, ys, False) * im_sampled

def scale_highpass(im, shape, method=None):
"""As :py:func:`sample` except that the highpass image is first phase
def rescale_highpass(im, shape, method=None):
"""As :py:func:`rescale` except that the highpass image is first phase
shifted to be centred on approximately DC.
"""
Expand Down
20 changes: 10 additions & 10 deletions tests/testsampling.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
from dtcwt.sampling import scale
from dtcwt.sampling import rescale

import numpy as np

def test_scale_lanczos():
def test_rescale_lanczos():
# Create random 100x120 image
X = np.random.rand(100,120)

# Re size up
Xrs = scale(X, (300, 210), 'lanczos')
Xrs = rescale(X, (300, 210), 'lanczos')
assert Xrs.shape == (300, 210)

# And down
Xrecon = scale(Xrs, X.shape, 'lanczos')
Xrecon = rescale(Xrs, X.shape, 'lanczos')
assert Xrecon.shape == X.shape

# Got back roughly the same thing to within 5%?
assert np.all(np.abs(X-Xrecon) < 5e-2)

def test_scale_bilinear():
def test_rescale_bilinear():
# Create random 100x120 image
X = np.random.rand(100,120)

# Re size up
Xrs = scale(X, (300, 210), 'bilinear')
Xrs = rescale(X, (300, 210), 'bilinear')
assert Xrs.shape == (300, 210)

# And down
Xrecon = scale(Xrs, X.shape, 'bilinear')
Xrecon = rescale(Xrs, X.shape, 'bilinear')
assert Xrecon.shape == X.shape

# Got back roughly the same thing to within 30% (bilinear sucks)
assert np.all(np.abs(X-Xrecon) < 3e-1)

def test_scale_nearest():
def test_rescale_nearest():
# Create random 100x120 image
X = np.random.rand(100,120)

# Re size up
Xrs = scale(X, (200, 240), 'nearest')
Xrs = rescale(X, (200, 240), 'nearest')
assert Xrs.shape == (200, 240)

# And down
Xrecon = scale(Xrs, X.shape, 'nearest')
Xrecon = rescale(Xrs, X.shape, 'nearest')
assert Xrecon.shape == X.shape

# Got back roughly the same thing to within 1% (nearest neighbour should be exact)
Expand Down

0 comments on commit ba88e6e

Please sign in to comment.