-
Notifications
You must be signed in to change notification settings - Fork 0
/
decompose.py
executable file
·68 lines (51 loc) · 1.54 KB
/
decompose.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016, Gabriele Facciolo <facciolo@cmla.ens-cachan.fr>
import os
import sys
import numpy as np
import piio
import pywt
def pick_option(argv, option, default):
# it's a parameter or just a flag?
if default == '':
id = 0
else:
id = 1
for i in range(len(argv)-id):
if argv[i] == '-'+option:
r = argv[i+id]
argv.pop(i+id)
if id:
argv.pop(i)
return r
return default
def decompose(image, prefix, levels, suffix, wtype, cur=0):
print prefix+str(cur)+suffix
piio.write(prefix+str(cur)+suffix, image)
print image.shape
if levels==1:
return
ret, _ = pywt.dwt2(image,wtype,axes=(0,1))
decompose(ret/2.0,prefix,levels-1,suffix, wtype, cur+1)
def main():
# verify input
wtype = pick_option(sys.argv, 't', 'db7')
if len(sys.argv) > 4:
image = piio.read(sys.argv[1])
prefix = sys.argv[2]
levels = int(sys.argv[3])
suffix = sys.argv[4]
else:
print("Incorrect syntax, use:")
print(" > " + sys.argv[0] + " input prefix levels suffix [-t type]")
print(" multiscale decomposition using wavelets")
print(" available types:")
for family in pywt.families():
print "%s family:" % family, ', '.join(pywt.wavelist(family))
sys.exit(1)
if pywt.Wavelet(wtype).orthogonal == False:
print "Warning \'%s\' is not orthogonal"%wtype
decompose(image, prefix, levels, suffix, wtype)
if __name__ == '__main__':
main()