File: testutils.py

package info (click to toggle)
python-pycudwt 1.0.2-5
  • links: PTS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 504 kB
  • sloc: cpp: 6,173; python: 798; sh: 9; makefile: 5
file content (196 lines) | stat: -rw-r--r-- 3,662 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np
from pywt import wavedec, wavedec2, waverec, waverec2, swt, swt2
try:
    from pywt import iswt, iswt2
except ImportError: # nigma/pywt
    iswt = None
    iswt2 = None

try:
    from scipy.misc import ascent
    scipy_img = ascent()
except ImportError:
    from scipy.misc import lena
    scipy_img = lena()


def iDivUp(a, b):
    return (a + (b - 1))//b



def create_data_to_good_size(data, size):
    """
    From a numpy array, create a second numpy array with a given size.
    The result contains the tiled data, which is then cropped to the wanted size.
    """
    # For 1D
    if min(size) == 1:
        sz = max(size)
        clip = iDivUp(sz, data.shape[0])
        res = np.tile(data[0], clip)[:sz]
        return res[:, np.newaxis].T

    clip_r = iDivUp(size[0], data.shape[0])
    clip_c = iDivUp(size[1], data.shape[1])
    res = np.tile(data, (clip_r, clip_c))
    return res[:size[0], :size[1]]



what_to_params = {
    "dwt2": {
        "name": "2D Forward DWT",
        "do_swt": 0,
        "ndim": 2,
        "pywt_function": wavedec2,
     },
    "idwt2": {
        "name": "2D Inverse DWT",
        "do_swt": 0,
        "ndim": 2,
        "pywt_function": waverec2,
     },
    "dwt": {
        "name": "1D Forward DWT",
        "do_swt": 0,
        "ndim": 1,
        "pywt_function": wavedec,
     },
    "idwt": {
        "name": "1D Inverse DWT",
        "do_swt": 0,
        "ndim": 1,
        "pywt_function": waverec,
     },
    "batched dwt": {
        "name": "Batched 1D Forward DWT",
        "do_swt": 0,
        "ndim": 1,
        "pywt_function": wavedec,
     },
    "batched idwt": {
        "name": "Batched 1D Inverse DWT",
        "do_swt": 0,
        "ndim": 1,
        "pywt_function": waverec,
     },
    "swt2": {
        "name": "2D Forward SWT",
        "do_swt": 1,
        "ndim": 2,
        "pywt_function": swt2,
     },
    "iswt2": {
        "name": "2D Inverse SWT",
        "do_swt": 1,
        "ndim": 2,
        "pywt_function": iswt2,
     },
    "swt": {
        "name": "1D Forward SWT",
        "do_swt": 0,
        "ndim": 2,
        "pywt_function": swt,
     },
    "iswt": {
        "name": "1D Inverse SWT",
        "do_swt": 1,
        "ndim": 1,
        "pywt_function": iswt,
     },
    "batched swt": {
        "name": "Batched 1D Forward SWT",
        "do_swt": 1,
        "ndim": 1,
        "pywt_function": swt,
     },
    "batched iswt": {
        "name": "Batched 1D Inverse SWT",
        "do_swt": 1,
        "ndim": 1,
        "pywt_function": iswt,
     },
}




# See ppdwt/filters.h
available_filters = [
    "haar",
    "db2",
    "db3",
    "db4",
    "db5",
    "db6",
    "db7",
    "db8",
    "db9",
    "db10",
    "db11",
    "db12",
    "db13",
    "db14",
    "db15",
    "db16",
    "db17",
    "db18",
    "db19",
    "db20",
    "sym2",
    "sym3",
    "sym4",
    "sym5",
    "sym6",
    "sym7",
    "sym8",
    "sym9",
    "sym10",
    "sym11",
    "sym12",
    "sym13",
    "sym14",
    "sym15",
    "sym16",
    "sym17",
    "sym18",
    "sym19",
    "sym20",
    "coif1",
    "coif2",
    "coif3",
    "coif4",
    "coif5", # pywt 0.5 has a problem with this one
    "bior1.3",
    "bior1.5",
    "bior2.2",
    "bior2.4",
    "bior2.6",
    "bior2.8",
    "bior3.1",
    "bior3.3",
    "bior3.5",
    "bior3.7",
    "bior3.9",
    "bior4.4",
    "bior5.5",
    "bior6.8",
    "rbio1.3",
    "rbio1.5",
    "rbio2.2",
    "rbio2.4",
    "rbio2.6",
    "rbio2.8",
    "rbio3.1",
    "rbio3.3",
    "rbio3.5",
    "rbio3.7",
    "rbio3.9",
    "rbio4.4",
    "rbio5.5",
    "rbio6.8"]
# ------