-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
71 lines (51 loc) · 1.55 KB
/
main.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
69
70
71
from math import *
from PIL import Image
from numpy import *
import matplotlib.pyplot as plt
import cv2
from output_images import *
from haar import *
def printstr(str):
print(str, end='', flush=True)
recursive = False
threshold = 0.45
# filename = 'img/hello_small.jpg'
# filename = 'img/lena.png'
filename = 'img/pearl.png'
image = Image.open(filename)#.convert('L')
print(filename, ":", image.size, "*", len(image.getbands()))
w, h = image.size
colormode = "".join(image.getbands())
depth = len(colormode)
total_size = w * h * depth
def fht_2d_image(image, steps=None):
colormode = "".join(image.getbands())
depth = len(colormode)
printstr("Processing ")
channels = []
for i in range(depth):
printstr(colormode[i])
def append(x, a):
x.append(Image.fromarray(a).convert('L'))
a = array(image.getchannel(i)) * float(1.0)
a = fht_2d(a, steps)
append(channels, a)
print()
return Image.merge(colormode, channels)
# plt_output_images([fht_2d_image(image, steps) for steps in range(3)], 5)
printstr("Processing ")
channels_spectre = []
channels_restored = []
for i in range(depth):
printstr(colormode[i])
def append(x, a):
x.append(Image.fromarray(a).convert('L'))
a = array(image.getchannel(i)) * float(1.0)
a = fht_2d(a)
append(channels_spectre, a)
a = inv_fht_2d(a)
append(channels_restored, a)
print()
spectre = Image.merge(colormode, channels_spectre)
restored = Image.merge(colormode, channels_restored)
plt_output_images([spectre, restored])