File: test_sampling.py

package info (click to toggle)
python-dtcwt 0.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,588 kB
  • sloc: python: 6,287; sh: 29; makefile: 13
file content (48 lines) | stat: -rw-r--r-- 1,265 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from dtcwt.sampling import rescale

import numpy as np

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

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

    # And down
    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_rescale_bilinear():
    # Create random 100x120 image
    X = np.random.rand(100,120)

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

    # And down
    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_rescale_nearest():
    # Create random 100x120 image
    X = np.random.rand(100,120)

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

    # And down
    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)
    assert np.all(np.abs(X-Xrecon) < 1e-2)