MCPcopy Create free account
hub / github.com/codec2021/video_codec_learn / BD_RATE

Function BD_RATE

Test/encoder/bjontegaard_metric.py:42–74  ·  view source on GitHub ↗
(R1, PSNR1, R2, PSNR2, piecewise=1)

Source from the content-addressed store, hash-verified

40
41
42def BD_RATE(R1, PSNR1, R2, PSNR2, piecewise=1):
43 lR1 = np.log(R1)
44 lR2 = np.log(R2)
45
46 # rate method
47 p1 = np.polyfit(PSNR1, lR1, 3)
48 p2 = np.polyfit(PSNR2, lR2, 3)
49
50 # integration interval
51 min_int = max(min(PSNR1), min(PSNR2))
52 max_int = min(max(PSNR1), max(PSNR2))
53
54 # find integral
55 if piecewise == 0:
56 p_int1 = np.polyint(p1)
57 p_int2 = np.polyint(p2)
58
59 int1 = np.polyval(p_int1, max_int) - np.polyval(p_int1, min_int)
60 int2 = np.polyval(p_int2, max_int) - np.polyval(p_int2, min_int)
61 else:
62 lin = np.linspace(min_int, max_int, num=100, retstep=True)
63 interval = lin[1]
64 samples = lin[0]
65 v1 = scipy.interpolate.pchip_interpolate(np.sort(PSNR1), lR1[np.argsort(PSNR1)], samples)
66 v2 = scipy.interpolate.pchip_interpolate(np.sort(PSNR2), lR2[np.argsort(PSNR2)], samples)
67 # Calculate the integral using the trapezoid method on the samples.
68 int1 = np.trapz(v1, dx=interval)
69 int2 = np.trapz(v2, dx=interval)
70
71 # find avg diff
72 avg_exp_diff = (int2-int1)/(max_int-min_int)
73 avg_diff = (np.exp(avg_exp_diff)-1)*100
74 return avg_diff
75

Callers 1

demo.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected