def plot_psnr(arg): """ PSNR """ t, st = vars(arg)['filename'], vars(arg)['filename_diff'] for f in st: vars(arg)['filename_diff'] = f yuv = YCbCr(**vars(arg)) psnr = [p[3] for p in yuv.psnr()] N = len(psnr[:-2]) ind = np.arange(N) # the x locations for the groups # To get a uniq identifier plt.plot(ind, psnr[:-2], 'o-', label=f[-10:-8]) del yuv plt.legend() plt.title(create_title_string(t, st)) plt.ylabel('weighted dB') plt.xlabel('frame') plt.grid(True) plt.show()
def plot_ssim(arg): """ SSIM """ t, st = vars(arg)['filename'], vars(arg)['filename_diff'] for f in st: vars(arg)['filename_diff'] = f yuv = YCbCr(**vars(arg)) ssim = [s for s in yuv.ssim()][:-2] N = len(ssim) ind = np.arange(N) plt.plot(ind, ssim, 'o-', label=f[-8:-4]) del yuv plt.legend() plt.title(create_title_string(t, st)) plt.ylabel('Index') plt.xlabel('frame') plt.grid(True) plt.show()
def plot_wpsnr(arg): """ Weighted PSNR BD-PSNR """ t, st = vars(arg)['filename'], vars(arg)['filename_diff'] for f in st: vars(arg)['filename_diff']=f yuv = YCbCr(**vars(arg)) psnr = [p[0] for p in yuv.psnr()] N = len(psnr[:-2]) ind = np.arange(N) # the x locations for the groups # To get a uniq identifier plt.plot(ind, psnr[:-2], 'o-',label=f[-8:-4]) del yuv plt.legend() plt.title(create_title_string(t, st)) plt.ylabel('weighted dB') plt.xlabel('frame') plt.grid(True) plt.show()
def plot_ssim(arg): """ SSIM """ t, st = vars(arg)['filename'], vars(arg)['filename_diff'] for f in st: vars(arg)['filename_diff']=f yuv = YCbCr(**vars(arg)) ssim = [s for s in yuv.ssim()][:-2] N = len(ssim) ind = np.arange(N) plt.plot(ind, ssim, 'o-',label=f[-8:-4]) del yuv plt.legend() plt.title(create_title_string(t, st)) plt.ylabel('Index') plt.xlabel('frame') plt.grid(True) plt.show()
def test_11(self): """ 10bpp -> 8bpp """ a = YCbCr(filename='test_10.yuv', filename_out=OUT) a.ten2eight() ret = get_sha1(OUT, SIZE_420) self.assertEqual(ret, 'c9120ccf583b410b75379c48325dd50ec8d16ce8')
def test_10(self): """ 8bpp -> 10bpp """ a = YCbCr(filename='foreman_cif_frame_0.yuv', filename_out='test_10.yuv') a.eight2ten() ret = get_sha1('test_10.yuv', SIZE_420 * 2) self.assertEqual(ret, '9cbade807771aa135f7f90b07e4bb510273b4e4f')
def test_9(self): """ ssim """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', filename_diff='foreman_cif_frame_1.yuv') ret = a.ssim().next() self.assertEqual(ret, 0.8714863949031405)
def test_8(self): """ psnr """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', filename_diff='foreman_cif_frame_1.yuv') ret = a.psnr().next() self.assertEqual(ret, [27.68336995961328, 43.025594686475237, 43.343456122199385, 29.383484998976837])
def test_7(self): """ split """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12') a.split() ret = get_sha1('frame0.yuv', SIZE_420) self.assertEqual(ret, 'c9120ccf583b410b75379c48325dd50ec8d16ce8')
def test_21(self): """ convert YV12 into NV12 """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', yuv_format_out='NV12', filename_out=OUT) a.convert() ret = get_sha1(OUT, SIZE_420) self.assertEqual(ret, 'e24ac66dc32cff5dff16297dfaab761ab962143c')
def test_1(self): """ convert YV12 into itself """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', yuv_format_out='YV12', filename_out=OUT) a.convert() ret = get_sha1(OUT, SIZE_420) self.assertEqual(ret, 'c9120ccf583b410b75379c48325dd50ec8d16ce8')
def test_2(self): """ YV12 -> UYVY """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', yuv_format_out='UYVY', filename_out=OUT) a.convert() ret = get_sha1(OUT, SIZE_422) self.assertEqual(ret, 'f50fc0500b217256a87c7cd1e867da0c49c51ace')
def test_3(self): """ YV12 -> YVYU """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', yuv_format_out='YVYU', filename_out=OUT) a.convert() ret = get_sha1(OUT, SIZE_422) self.assertEqual(ret, '68ac533290a89625b910731c93fbecba89b61870')
def test_5(self): """ YV12 -> 422 """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', yuv_format_out='422', filename_out=OUT) a.convert() ret = get_sha1(OUT, SIZE_422) self.assertEqual(ret, 'c700a31a209df30b72c1097898740d4c42d63a42')
def test_13(self): """ YV12 -> YUY2 """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', yuv_format_out='YUY2', filename_out=OUT) a.convert() ret = get_sha1(OUT, SIZE_420) self.assertEqual(ret, '410b438c1aedc7e2ee6d68405f411bbfa8131b7a')
def test_12(self): """ YV12 -> IYUV """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', yuv_format_out='IYUV', filename_out=OUT) a.convert() ret = get_sha1(OUT, SIZE_420) self.assertEqual(ret, '385c87ed96b9298be9a410ff041fe4232b27a9aa')
def test_18(self): """ Drawing primitive """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', filename_out=OUT) a.draw_frame_number() ret = get_sha1(OUT, SIZE_420) self.assertEqual(ret, '71490f0356d3ba8d2c3d6110b77a9f665b561324')
def test_6(self): """ diff """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', filename_diff='foreman_cif_frame_1.yuv') a.diff() ret = get_sha1('foreman_cif_frame_0_foreman_cif_frame_1_diff.yuv', SIZE_420) self.assertEqual(ret, '6b508de1971eaae965d3a3cf0c8715c6fe907aff')
def test_16(self): """ YV12 -> flip left-right """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', filename_out=OUT) a.fliplr() ret = get_sha1(OUT, SIZE_420) self.assertEqual(ret, 'f93ef579e5f672fd2a5962072509d98382a7d1d3')
def test_15(self): """ YV12 -> flip upside-down """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', filename_out=OUT) a.flipud() ret = get_sha1(OUT, SIZE_420) self.assertEqual(ret, '9052c6e03d7e4b8b2ec5d80aa17e9585b9b2a672')
def test_19(self): """ YV12 -> crop """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', crop_rect=(0,0,15,15), filename_out=OUT) a.crop() ret = get_sha1(OUT, 384) self.assertEqual(ret, 'e74e61a5c6ade64c9f6371920512b5010d23cad4')
def test_14(self): """ psnr - nan """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', filename_diff='foreman_cif_frame_0.yuv') ret = a.psnr().next() self.assertTrue(math.isnan(ret[0])) self.assertTrue(math.isnan(ret[1])) self.assertTrue(math.isnan(ret[2])) self.assertTrue(math.isnan(ret[3]))
def test_19(self): """ YV12 -> crop """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', crop_rect=(0, 0, 15, 15), filename_out=OUT) a.crop() ret = get_sha1(OUT, 384) self.assertEqual(ret, 'e74e61a5c6ade64c9f6371920512b5010d23cad4')
def test_8(self): """ psnr """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', filename_diff='foreman_cif_frame_1.yuv') ret = a.psnr().next() self.assertEqual(ret, [ 27.68336995961328, 43.025594686475237, 43.343456122199385, 29.383484998976837 ])
def plot_psnr(arg): """ PSNR """ yuv = YCbCr(**vars(arg)) psnr = [p[0] for p in yuv.psnr()] N = len(psnr) ind = np.arange(N) # the x locations for the groups plt.figure() plt.title(create_title_string(arg)) plt.plot(ind, psnr, 'ro-') plt.ylabel('dB') plt.xlabel('frame') plt.grid(True) plt.show()
def plot_ssim(arg): """ SSIM """ yuv = YCbCr(**vars(arg)) ssim = [s for s in yuv.ssim()] N = len(ssim) ind = np.arange(N) # the x locations for the groups plt.figure() plt.title(create_title_string(arg)) plt.plot(ind, ssim, 'ro-') plt.ylabel('Index') plt.xlabel('frame') plt.grid(True) plt.show()
def get_psnr(self, line): yuv = YCbCr(filename=line.input_url, filename_diff=line.output, width=int(line.width), height=int(line.height), yuv_format_in=line.type, bitdepth=int(line.bit_depth)) time_b = time.time() for infile in range(len(line.input_url)): p_pool = [] for diff_file in range(len(line.output)): if not os.path.exists(line.output[diff_file]): print >> sys.stderr, '%s decode failed' % self.codec_name psnr = yuv.psnr_all(diff_file, infile) if 0 in psnr: print ' psnr calculate wrong!\n' line.psnr.append(psnr[0]) line.psnr_luam.append(psnr[1]) line.psnr_charm_cb.append(psnr[2]) line.psnr_charm_cr.append(psnr[3]) if len(psnr) == 0: print 'calculate psnr failed!\n' # com_psnr = Array('d', len(line.output) * 4) # for diff_file in range(len(line.output)): # p = Process(target=yuv.psnr_all, args=(diff_file, infile, com_psnr)) # p.start() # p_pool.append(p) # for p in p_pool: # p.join() # for num in range(len(line.output)): # line.psnr.append(com_psnr[num * 4]) # line.psnr_luam.append(com_psnr[num * 4 + 1]) # line.psnr_charm_cb.append(com_psnr[num * 4 + 2]) # line.psnr_charm_cr.append(com_psnr[num * 4 + 3]) elapsed = (time.time() - time_b) m, s = divmod(elapsed, 60) h, m = divmod(m, 60) print("calculate psnr time used : %d:%02d:%02d" % (h, m, s)) line.set_average_fps() # line.set_bd_psnr(BD.BD_PSNR_Average(line.bit_rate, line.psnr)) line.sort()
def plot_psnr_all(arg): """ PSNR, all planes """ yuv = YCbCr(**vars(arg)) psnr = [p for p in yuv.psnr()] N = len(psnr) ind = np.arange(N) # the x locations for the groups plt.figure() plt.title(create_title_string(arg)) plt.plot(ind, [i[0] for i in psnr], 'ko-', label='Y') plt.plot(ind, [i[1] for i in psnr], 'bo-', label='Cb') plt.plot(ind, [i[2] for i in psnr], 'ro-', label='Cr') plt.plot(ind, [i[3] for i in psnr], 'mo-', label='Frame') plt.legend() plt.ylabel('dB') plt.xlabel('frame') plt.grid(True) plt.show()
def test_17(self): """ YV12 -> YVYU -> flip left-right """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', yuv_format_out='YVYU', filename_out=OUT) a.convert() a = YCbCr(width=352, height=288, filename=OUT, yuv_format_in='YVYU', filename_out=OUT1) a.fliplr() ret = get_sha1(OUT1, SIZE_422) self.assertEqual(ret, 'a5bdbfdeb0259f6d0bd85ddd97d58f6fc7965ca9')
def test_4(self): """ YV12 -> UVYU -> YV12 """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', yuv_format_out='UYVY', filename_out=OUT) a.convert() b = YCbCr(width=352, height=288, filename=OUT, yuv_format_in='UYVY', yuv_format_out='YV12', filename_out=OUT1) b.convert() ret = get_sha1(OUT1, SIZE_422) self.assertEqual(ret, 'b8934d77e0d71e77e90b4ba777a0cb978679d8ec')
def test_20(self): """ YV12 -> YVYU -> crop """ a = YCbCr(width=352, height=288, filename='foreman_cif_frame_0.yuv', yuv_format_in='YV12', yuv_format_out='YVYU', filename_out=OUT) a.convert() a = YCbCr(width=352, height=288, filename=OUT, yuv_format_in='YVYU', crop_rect=(0, 0, 15, 15), filename_out=OUT1) a.crop() ret = get_sha1(OUT1, 512) self.assertEqual(ret, '4bf3179e43e7ca6d490bf1d996dff84ef64be664')
def on_b_calc(self, event): """ Calculate """ f1 = self.t_load_f1.GetValue() f2 = self.t_load_f2.GetValue() a = self.algo.GetValue() f = self.yuv_format.GetValue() s = self.t_size.GetValue() w, h = s.split('x') # are all parameters ok? if not os.path.isfile(f1) or not os.path.isfile(f2): print 'faulty inputfiles' raise IOError if not a in self.algo_list: print 'faulty algorithm' raise KeyError if not f in self.yuv_format_list: print 'faulty format' raise KeyError if not w.isdigit() or not h.isdigit(): print 'faulty size' raise TypeError y = YCbCr(width=int(w), height=int(h), filename=f1, yuv_format_in=f, filename_diff=f2, num=20) if 'psnr' in a: psnr = [p for p in y.psnr()][:-2] if a != 'psnr-all': ind = np.arange(len(psnr)) # the x locations for the groups self.axes.clear() self.axes.plot(ind, [i[self.algo_map[a]] for i in psnr], 'o-', picker=5) self.axes.set_title(os.path.basename(f1) + ' ' + a) self.axes.set_ylabel('dB') self.axes.set_xlabel('frame') self.canvas.draw() elif a == 'psnr-all': ind = np.arange(len(psnr)) # the x locations for the groups self.axes.clear() self.axes.plot(ind, [i[0] for i in psnr], 'ko-', label='Y', picker=5) self.axes.plot(ind, [i[1] for i in psnr], 'bo-', label='Cb', picker=5) self.axes.plot(ind, [i[2] for i in psnr], 'ro-', label='Cr', picker=5) self.axes.plot(ind, [i[3] for i in psnr], 'mo-', label='BD', picker=5) self.axes.set_title(os.path.basename(f1) + ' ' + a) self.axes.legend() self.axes.set_ylabel('dB') self.axes.set_xlabel('frame') self.canvas.draw() elif 'ssim' in a: ssim = [s for s in y.ssim()][:-2] ind = np.arange(len(ssim)) # the x locations for the groups self.axes.clear() self.axes.plot(ind, ssim, 'o-', picker=5) self.axes.set_title(os.path.basename(f1) + ' ' + a) self.axes.set_ylabel('index') self.axes.set_xlabel('frame') self.canvas.draw() else: print '~tilt'
FMT = ['IYUV', 'UYVY', 'YV12', 'YVYU'] if len(sys.argv) != 6: usage(sys.argv[0]) fname1 = sys.argv[1] fname2 = sys.argv[2] w = int(sys.argv[3]) h = int(sys.argv[4]) if sys.argv[5] in FMT: fmt = sys.argv[5] else: usage(sys.argv[0]) Y = YCbCr(width=w, height=h, filename=fname1, yuv_format_in=fmt, filename_diff=fname2) data1 = load_data(Y, fname1) data2 = load_data(Y, fname2) psnr = Y.psnr().next()[0] ssim = Y.ssim().next() # First subplot figure() frame1 = subplot(121) plt.imshow(data1, cmap=cm.gray, hold=True) frame1.axes.get_xaxis().set_visible(False) frame1.axes.get_yaxis().set_visible(False) title("PSNR = %f" % psnr)
if len(sys.argv) != 6: usage(sys.argv[0]) fname1 = sys.argv[1] fname2 = sys.argv[2] w = int(sys.argv[3]) h = int(sys.argv[4]) if sys.argv[5] in FMT: fmt = sys.argv[5] else: usage(sys.argv[0]) Y = YCbCr(width=w, height=h, filename=fname1, yuv_format_in=fmt, filename_diff=fname2) data1 = load_data(Y, fname1) data2 = load_data(Y, fname2) psnr = Y.psnr().next()[0] ssim = Y.ssim().next() # First subplot figure() frame1 = subplot(121) plt.imshow(data1, cmap=cm.gray, hold=True) frame1.axes.get_xaxis().set_visible(False) frame1.axes.get_yaxis().set_visible(False)
def plot_psnr_frames(contain): """ PSNR, all planes """ # ind = arg.Bit_rate # the x locations for the groups fig = plt.figure(figsize=[16, 6], constrained_layout=True) gs = GridSpec(1, 2, figure=fig) plt.suptitle('yuv Quality plot') # frames_psnr = fig.add_subplot(gs[:, 0]) bits_psnr = fig.add_subplot(gs[0, 0]) DBDR = fig.add_subplot(gs[0, 1]) DBDR.set_axis_off() # frames_psnr.set_title('Psnr-Y vs Frames') # frames_psnr.set_xlabel('frames') # frames_psnr.set_ylabel('Psnr-y') bits_psnr.set_title('Psnr vs Bitrate') bits_psnr.set_xlabel('bitrate') bits_psnr.set_ylabel('psnr-y') BD_contain = [] for i in range(len(contain)): yuv = YCbCr(filename=contain[i][0], filename_diff=contain[i][1], width=int(contain[i][5]), height=int(contain[i][6]), yuv_format_in=contain[i][7], bitdepth=contain[i][4]) for infile in range(len(contain[i][0])): point = [] xax = [] for diff_file in range(len(contain[i][1])): temp = [p for p in yuv.psnr_all(diff_file, infile)] ind = np.arange(len(temp)) frame = [frame_order[0] for frame_order in temp] point.append(temp[-1][0]) xax.append(contain[i][2][diff_file]) # frames_psnr.plot(ind[0:-1], frame[0:-1], 'o-', label=contain[i][3]+'_'+str(contain[i][2][diff_file])) temp_sort = sort_point(xax, point) bits_psnr.plot(temp_sort[0], temp_sort[1], 'o-', label=contain[i][3]) BD_contain.append( [temp_sort[0], temp_sort[1], contain[i][3], contain[i][0]]) celltext = [] rowname = [] tag = 0 while tag < len(BD_contain): x265_rate = BD.BD_RATE(BD_contain[tag][0], BD_contain[tag][1], BD_contain[tag + 1][0], BD_contain[tag + 1][1]) svt_rate = BD.BD_RATE(BD_contain[tag][0], BD_contain[tag][1], BD_contain[tag + 2][0], BD_contain[tag + 2][1]) x265_psnr = BD.BD_PSNR(BD_contain[tag][0], BD_contain[tag][1], BD_contain[tag + 1][0], BD_contain[tag + 1][1]) svt_psnr = BD.BD_PSNR(BD_contain[tag][0], BD_contain[tag][1], BD_contain[tag + 2][0], BD_contain[tag + 2][1]) rowname.append(BD_contain[tag][3][0].split('/')[-1] + '_' + BD_contain[tag][2]) rowname.append(BD_contain[tag + 1][3][0].split('/')[-1] + '_' + BD_contain[tag + 1][2]) rowname.append(BD_contain[tag + 2][3][0].split('/')[-1] + '_' + BD_contain[tag + 2][2]) celltext.append(['HM base line', 'HM base line']) celltext.append([x265_rate, x265_psnr]) celltext.append([svt_rate, svt_psnr]) tag += 3 DBDR.table(cellText=celltext, colLabels=['BDBR', 'BD-PSNR'], rowLabels=rowname, loc='center', colWidths=[0.2, 0.2]) # frames_psnr.legend() bits_psnr.legend() # fig.align_labels() plt.show()