This repository has been archived by the owner on Nov 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
56 lines (43 loc) · 1.61 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
import logging
from matplotlib import pyplot as plt
import numpy as np
from prototype_jpeg.utils import psnr
from tests.test_prototype_jpeg import compress_and_extract
logging.basicConfig(level=logging.INFO)
def read_img(filename):
with open(filename, 'rb') as file_object:
ret = np.fromfile(file_object, dtype=np.uint8)
return ret
filenames = (
'tests/images/rgb/Baboon.raw',
'tests/images/rgb/Lena.raw',
'tests/images/grey_level/Baboon.raw',
'tests/images/grey_level/Lena.raw'
)
qualities = (90, 80, 50, 20, 10, 5)
def main():
(_, axarr) = plt.subplots(len(filenames), len(qualities) + 1)
for i, fn in enumerate(filenames):
logging.getLogger(__name__).info('-- FN: %s ------------' % fn)
original = read_img(fn).reshape(
(512, 512) if ('grey_level' in fn) else (512, 512, 3)
)
axarr[i][0].imshow(original, cmap='gray', vmin=0, vmax=255)
for j, q in enumerate(qualities):
logging.getLogger(__name__).info('------- QF: %s -------' % q)
extracted = compress_and_extract({
'fn': fn,
'size': (512, 512),
'grey_level': ('grey_level' in fn),
'quality': q,
'subsampling_mode': 1
}).reshape(
(512, 512) if ('grey_level' in fn) else (512, 512, 3)
)
logging.getLogger(__name__).info(
'---------- PSNR: %.8f ----' % psnr(original, extracted)
)
axarr[i][j + 1].imshow(extracted, cmap='gray', vmin=0, vmax=255)
plt.show()
if __name__ == '__main__':
main()