-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
148 lines (92 loc) · 4.03 KB
/
main.py
File metadata and controls
148 lines (92 loc) · 4.03 KB
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
"""
module:: Main File - RLE+HUFFMAN and LZW compressors
:synopsis: Here it's called each codec.
moduleauthor:: Miguel Dinis <miguelbarroso@student.dei.uc.pt>
Both libs are imported as well as the Time library so we can measure how long each algorithm takes.
Just select the right image to encode/decode and uncomment it.
Notes:
RLEHuffmanCodec needs to store a tree in a separate JSON file.
LZWCodec accepts a chunk size as parameter but it has a default value.
Both accept a "vertical" parameter which, when transforming (predictive), does it in a horizontal or vertical direction. Default is horizontal.
When decoding, the option must be the same as when encoded.
More information on how to run this in the README file and in the Article.
"""
from rlehuff import RLEHuffmanCodec
from lzw import LZWCodec
import time
if __name__ == '__main__':
# Both algorithm instances.
codecRLEHUFF = RLEHuffmanCodec()
codecLZW = LZWCodec()
# EGG - RLE + HUFF
"""
t1 = time.time()
codecRLEHUFF.encode("data/original/egg.bmp", "data/egg.rlehuff", "data/egg-RLEHUFF.json")
print("Encoder time elapsed: ", time.time() - t1)
t1 = time.time()
codecRLEHUFF.decode("data/egg.rlehuff", "data/egg-RLEHUFF-DECODED.bmp", "data/egg-RLEHUFF.json")
print("Decoder time elapsed: ", time.time() - t1)
"""
# EGG - LZW
"""
t1 = time.time()
codecLZW.encode("data/original/egg.bmp", "data/egg.lzw", 100000)
print("Encoder time elapsed: ", time.time() - t1)
t1 = time.time()
codecLZW.decode("data/egg.lzw.npy", "data/egg-LZW-DECODED.bmp")
print("Decoder time elapsed: ", time.time() - t1)
"""
# PATTERN - RLE + HUFF
"""
t1 = time.time()
codecRLEHUFF.encode("data/original/pattern.bmp", "data/pattern.rlehuff", "data/pattern-RLEHUFF.json")
print("Encoder time elapsed: ", time.time() - t1)
t1 = time.time()
codecRLEHUFF.decode("data/pattern.rlehuff", "data/pattern-RLEHUFF-DECODED.bmp", "data/pattern-RLEHUFF.json")
print("Decoder time elapsed: ", time.time() - t1)
"""
# PATTERN - LZW
"""
t1 = time.time()
codecLZW.encode("data/original/pattern.bmp", "data/pattern.lzw", 250000)
print("Encoder time elapsed: ", time.time() - t1)
t1 = time.time()
codecLZW.decode("data/egg.pattern.npy", "data/pattern-LZW-DECODED.bmp")
print("Decoder time elapsed: ", time.time() - t1)
"""
# ZEBRA - RLE + HUFF
"""
t1 = time.time()
codecRLEHUFF.encode("data/original/zebra.bmp", "data/zebra.rlehuff", "data/zebra-RLEHUFF.json", vertical=True)
print("Encoder time elapsed: ", time.time() - t1)
t1 = time.time()
codecRLEHUFF.decode("data/zebra.rlehuff", "data/zebra-RLEHUFF-DECODED.bmp", "data/zebra-RLEHUFF.json", vertical=True)
print("Decoder time elapsed: ", time.time() - t1)
"""
# ZEBRA - LZW
"""
t1 = time.time()
codecLZW.encode("data/original/zebra.bmp", "data/zebra.lzw", vertical=True)
print("Encoder time elapsed: ", time.time() - t1)
t1 = time.time()
codecLZW.decode("data/zebra.lzw.npy", "data/zebra-LZW-DECODED.bmp", vertical=True)
print("Decoder time elapsed: ", time.time() - t1)
"""
# LANDSCAPE - RLE + HUFF
"""
t1 = time.time()
codecRLEHUFF.encode("data/original/landscape.bmp", "data/landscape.rlehuff", "data/landscape-RLEHUFF.json", vertical=True)
print("Encoder time elapsed: ", time.time() - t1)
t1 = time.time()
codecRLEHUFF.decode("data/landscape.rlehuff", "data/landscape-RLEHUFF-DECODED.bmp", "data/landscape-RLEHUFF.json", vertical=True)
print("Decoder time elapsed: ", time.time() - t1)
"""
# LANDSCAPE - LZW
"""
t1 = time.time()
codecLZW.encode("data/original/landscape.bmp", "data/landscape.lzw", 100000, vertical=True)
print("Encoder time elapsed: ", time.time() - t1)
t1 = time.time()
codecLZW.decode("data/landscape.lzw.npy", "data/landscape-LZW-DECODED.bmp", vertical=True)
print("Decoder time elapsed: ", time.time() - t1)
"""