-
Notifications
You must be signed in to change notification settings - Fork 3
/
l3iv.py
executable file
·49 lines (37 loc) · 1.25 KB
/
l3iv.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
#!/usr/bin/python3
import os
import sys
import imageio
import argparse
import numpy as np
import matplotlib.pyplot as plt
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
from models.dcn import DCN
from helpers import codec
file_ext = '.l3i'
bitmap_formats = {'.png', '.jpg', '.bmp', '.jpeg', '.jp2'}
def quickshow(ax, image, title):
ax.imshow(image.squeeze())
ax.set_title(title)
ax.set_xticks([])
ax.set_yticks([])
parser = argparse.ArgumentParser(description='Viewer for Lightweight Learned Lossy Image Codec (l3ic)')
parser.add_argument('input', help='Coded image *.{})'.format(file_ext))
parser.add_argument('-m', '--model', dest='model', action='store', default=None,
help='DCN model - corresponds to quality: 16c, 32c, 64c')
args = parser.parse_args()
if args.input is None:
parser.print_usage()
sys.exit(1)
if os.path.splitext(args.input)[-1].lower() == file_ext:
dcn = DCN(args.model) if args.model is not None else None
with open(args.input, 'rb') as f:
coded_stream = f.read()
image = codec.decompress(coded_stream, dcn)
fig = plt.figure()
quickshow(fig.gca(), image, args.input)
fig.tight_layout()
plt.show()
else:
print('The file extension is not supported!')
sys.exit(1)