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

Side by Side Diff: tools/dump_ciede2000.py

Issue 1543: 4:2:2 support in dump_ciede2000.py
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:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 18
18 def usage(): 19 def usage():
19 print("Usage: %s <video1> <video2>\n" 20 print("Usage: %s <video1> <video2>\n"
20 " <video1> and <video2> must be YUV4MPEG files.\n\n" % __file__) ; 21 " <video1> and <video2> must be YUV4MPEG files.\n\n" % __file__) ;
21 22
22 def decode_y4m_buffer(frame): 23 def decode_y4m_buffer(frame):
23 W, H = frame.headers['W'], frame.headers['H'] 24 W, H = frame.headers['W'], frame.headers['H']
24 Wdiv2, Hdiv2 = W // 2, H // 2 25 Wdiv2, Hdiv2 = W // 2, H // 2
25 C, buf = frame.headers['C'], frame.buffer 26 C, buf = frame.headers['C'], frame.buffer
26 A, Adiv2, div2 = W * H, Hdiv2 * Wdiv2, (Hdiv2, Wdiv2) 27 A = W * H
27 dtype, scale = 'uint8', 1. 28 dtype, scale = 'uint8', 1.
28 if C.endswith('p10'): 29 if C.endswith('p10'):
30 # TODO 420p10 and 422p10
29 dtype, scale, A = 'uint16', 4., A * 2 31 dtype, scale, A = 'uint16', 4., A * 2
30 Y = (np.ndarray((H, W), dtype, buf) - 16. * scale) / (219. * scale) 32 Y = (np.ndarray((H, W), dtype, buf) - 16. * scale) / (219. * scale)
31 if C.startswith('420'): 33 if C.startswith('420'):
32 Cb = (np.ndarray(div2, dtype, buf, A) - 128. * scale) / (224. * scale) 34 A_420 = Hdiv2 * Wdiv2
33 Cr = (np.ndarray(div2, dtype, buf, A + Adiv2) - 128. * scale) / (224. * scale) 35 Cb = (np.ndarray((Hdiv2, Wdiv2), dtype, buf, A) - 128. * scale) / (224. * scale)
36 Cr = (np.ndarray((Hdiv2, Wdiv2), dtype, buf, A + A_420) - 128. * scale) / (224. * scale)
34 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'):
39 A_422 = H * Wdiv2
40 Cb = (np.ndarray((H, Wdiv2), dtype, buf, A) - 128. * scale) / (224. * sc ale)
41 Cr = (np.ndarray((H, Wdiv2), dtype, buf, A + A_422) - 128. * scale) / (2 24. * scale)
42 YCbCr444 = np.dstack((Y, np.kron(Cb, box1), np.kron(Cr, box1)))
35 else: 43 else:
36 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)
37 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)
38 YCbCr444 = np.dstack((Y, Cb, Cr)) 46 YCbCr444 = np.dstack((Y, Cb, Cr))
39 return np.dot(YCbCr444, yuv2rgb.T) 47 return np.dot(YCbCr444, yuv2rgb.T)
40 48
41 49
42 scores = [] 50 scores = []
43 51
44 52
(...skipping 22 matching lines...) Expand all
67 recons_frames.append(frame) 75 recons_frames.append(frame)
68 if ref_frames: 76 if ref_frames:
69 process_pair(ref_frames.popleft(), recons_frames.popleft()) 77 process_pair(ref_frames.popleft(), recons_frames.popleft())
70 78
71 class Reader(y4m.Reader): 79 class Reader(y4m.Reader):
72 def _frame_size(self): 80 def _frame_size(self):
73 area = self._stream_headers['W'] * self._stream_headers['H'] 81 area = self._stream_headers['W'] * self._stream_headers['H']
74 C = self._stream_headers['C'] 82 C = self._stream_headers['C']
75 if C.startswith('420'): 83 if C.startswith('420'):
76 pixels = area * 3 // 2 84 pixels = area * 3 // 2
85 elif C.startswith('422'):
86 pixels = area * 2
77 elif C.startswith('444'): 87 elif C.startswith('444'):
78 pixels = area * 3 88 pixels = area * 3
79 else: 89 else:
80 raise Exception('Unknown pixel format: %s' % C) 90 raise Exception('Unknown pixel format: %s' % C)
81 if self._stream_headers['C'].endswith('p10'): 91 if self._stream_headers['C'].endswith('p10'):
82 return 2 * pixels 92 return 2 * pixels
83 return pixels 93 return pixels
84 94
85 def main(args): 95 def main(args):
86 if len(args) != 3: 96 if len(args) != 3:
(...skipping 19 matching lines...) Expand all
106 ref_parser.decode(data) 116 ref_parser.decode(data)
107 if not recons_frames: 117 if not recons_frames:
108 data = recons_buf.read(BLOCK_SIZE) 118 data = recons_buf.read(BLOCK_SIZE)
109 if not data: break 119 if not data: break
110 recons_parser.decode(data) 120 recons_parser.decode(data)
111 print('Total: %2.4f' % np.array(scores).mean()) 121 print('Total: %2.4f' % np.array(scores).mean())
112 122
113 123
114 if __name__ == '__main__': 124 if __name__ == '__main__':
115 main(sys.argv) 125 main(sys.argv)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld