-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (49 loc) · 1.75 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
72
73
74
75
76
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 12 16:07:35 2015
@author: Navegantes
"""
#from matplotlib import pyplot as plt
#import numpy as np
#import HuffCoder as hf
import cv2
import JPEGcodec as jpg
from Tkinter import Tk
from tkFileDialog import askopenfilename
import ssim
root = Tk()
root.withdraw()
if __name__ == '__main__':
filepath = askopenfilename(parent=root, title="Choose a Image File!").__str__()
# filepath = 'flyingfish.jpg'
img = cv2.imread(filepath,1)
qually = 75
mode = '420'
print '\n****************************'
print '* JPEG Encoder Initialized *'
print '****************************'
enc = jpg.Encoder(filepath, qually, mode)
print '- Outcomes'
enc.Outcomes()
print '\n****************************'
print '* JPEG Decoder Initialized *'
print '****************************'
huffile = enc.dirOut + enc.filepath.split('/')[-1:][0].split('.')[0] + '.huff'
dec = jpg.Decoder(huffile)
imrec = dec._run_()
luma1 = cv2.cvtColor(img, cv2.COLOR_YCR_CB2BGR)
luma2 = cv2.cvtColor(imrec, cv2.COLOR_YCR_CB2BGR)
imdif = (luma1[:,:,0]-luma2[:,:,0]) + 128
print '\n- Computing SSIM...'
SSIMout = ssim.compute_ssim(luma1[:,:,0], luma2[:,:,0])
print ' :: SSIM = ', SSIMout[0]
cv2.imshow('Original Image', img)
cv2.imshow('Recued Image', imrec)
cv2.imshow('Luma Diference', imdif)
cv2.imshow('SSIM_Map', SSIMout[1])
# cv2.imshow('Diferenca', img-imrec)
print '\n- Press <ESC> to close...'
k = cv2.waitKey(0)
if k == 27: # wait for ESC key to exit
cv2.destroyAllWindows()
#plt.imshow(np.uint8(luma1[:,:,0]-luma2[:,:,0]), 'gray')