Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(480032)

Delta Between Two Patch Sets: tools/dump_ciede2000.py

Issue 1543: 4:2:2 support in dump_ciede2000.py
Left Patch Set: 4:2:2 support in dump_ciede2000.py Created 1 year, 6 months ago
Right Patch Set: 4:2:2 support in dump_ciede2000.py Created 1 year, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 from collections import deque 3 from collections import deque
4 import sys 4 import sys
5 import numpy as np 5 import numpy as np
6 from skimage import color 6 from skimage import color
7 import y4m 7 import y4m
8 8
9 # Assuming BT.709 9 # Assuming BT.709
10 yuv2rgb = np.array([ 10 yuv2rgb = np.array([
11 [1., 0., 1.28033], [1., -0.21482, -0.38059], [1., 2.12798, 0.] 11 [1., 0., 1.28033], [1., -0.21482, -0.38059], [1., 2.12798, 0.]
12 ]) 12 ])
13 13
14 # Simple box filter 14 # Simple box filter
15 box2 = np.ones((2, 2)) 15 box2 = np.ones((2, 2))
16 16
17 box1 = np.ones((1, 2)) 17 box1 = np.ones((1, 2))
18 18
19 def usage(): 19 def usage():
20 print("Usage: %s <video1> <video2>\n" 20 print("Usage: %s <video1> <video2>\n"
21 " <video1> and <video2> must be YUV4MPEG files.\n\n" % __file__) ; 21 " <video1> and <video2> must be YUV4MPEG files.\n\n" % __file__) ;
22 22
23 def decode_y4m_buffer(frame): 23 def decode_y4m_buffer(frame):
24 W, H = frame.headers['W'], frame.headers['H'] 24 W, H = frame.headers['W'], frame.headers['H']
25 Wdiv2, Hdiv2 = W // 2, H // 2 25 Wdiv2, Hdiv2 = W // 2, H // 2
26 C, buf = frame.headers['C'], frame.buffer 26 C, buf = frame.headers['C'], frame.buffer
27 A = W * H 27 A = W * H
28 dtype, scale = 'uint8', 1. 28 dtype, scale = 'uint8', 1.
29 if C.endswith('p10'): 29 if C.endswith('p10'):
30 # TODO 420p10 and 422p10
30 dtype, scale, A = 'uint16', 4., A * 2 31 dtype, scale, A = 'uint16', 4., A * 2
31 Y = (np.ndarray((H, W), dtype, buf) - 16. * scale) / (219. * scale) 32 Y = (np.ndarray((H, W), dtype, buf) - 16. * scale) / (219. * scale)
32 if C.startswith('420'): 33 if C.startswith('420'):
33 div_420 = (Hdiv2, Wdiv2)
34 A_420 = Hdiv2 * Wdiv2 34 A_420 = Hdiv2 * Wdiv2
35 Cb = (np.ndarray(div_420, dtype, buf, A) - 128. * scale) / (224. * scale ) 35 Cb = (np.ndarray((Hdiv2, Wdiv2), dtype, buf, A) - 128. * scale) / (224. * scale)
36 Cr = (np.ndarray(div_420, dtype, buf, A + A_420) - 128. * scale) / (224. * scale) 36 Cr = (np.ndarray((Hdiv2, Wdiv2), dtype, buf, A + A_420) - 128. * scale) / (224. * scale)
37 YCbCr444 = np.dstack((Y, np.kron(Cb, box2), np.kron(Cr, box2))) 37 YCbCr444 = np.dstack((Y, np.kron(Cb, box2), np.kron(Cr, box2)))
38 elif C.startswith('422'): 38 elif C.startswith('422'):
39 div_422 = (H, Wdiv2)
40 A_422 = H * Wdiv2 39 A_422 = H * Wdiv2
41 Cb = (np.ndarray(div_422, dtype, buf, A) - 128. * scale) / (224. * scale ) 40 Cb = (np.ndarray((H, Wdiv2), dtype, buf, A) - 128. * scale) / (224. * sc ale)
42 Cr = (np.ndarray(div_422, dtype, buf, A + A_422) - 128. * scale) / (224. * scale) 41 Cr = (np.ndarray((H, Wdiv2), dtype, buf, A + A_422) - 128. * scale) / (2 24. * scale)
43 YCbCr444 = np.dstack((Y, np.kron(Cb, box1), np.kron(Cr, box1))) 42 YCbCr444 = np.dstack((Y, np.kron(Cb, box1), np.kron(Cr, box1)))
44 else: 43 else:
45 Cb = (np.ndarray((H, W), dtype, buf, A) - 128. * scale) / (224. * scale) 44 Cb = (np.ndarray((H, W), dtype, buf, A) - 128. * scale) / (224. * scale)
46 Cr = (np.ndarray((H, W), dtype, buf, A * 2) - 128. * scale) / (224. * sc ale) 45 Cr = (np.ndarray((H, W), dtype, buf, A * 2) - 128. * scale) / (224. * sc ale)
47 YCbCr444 = np.dstack((Y, Cb, Cr)) 46 YCbCr444 = np.dstack((Y, Cb, Cr))
48 return np.dot(YCbCr444, yuv2rgb.T) 47 return np.dot(YCbCr444, yuv2rgb.T)
49 48
50 49
51 scores = [] 50 scores = []
52 51
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 ref_parser.decode(data) 116 ref_parser.decode(data)
118 if not recons_frames: 117 if not recons_frames:
119 data = recons_buf.read(BLOCK_SIZE) 118 data = recons_buf.read(BLOCK_SIZE)
120 if not data: break 119 if not data: break
121 recons_parser.decode(data) 120 recons_parser.decode(data)
122 print('Total: %2.4f' % np.array(scores).mean()) 121 print('Total: %2.4f' % np.array(scores).mean())
123 122
124 123
125 if __name__ == '__main__': 124 if __name__ == '__main__':
126 main(sys.argv) 125 main(sys.argv)
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

RSS Feeds Recent Issues | This issue
This is Rietveld